added email fixes

This commit is contained in:
Wyatt Johnson
2018-01-11 10:58:43 -07:00
parent 92b506c85a
commit 1dcf297a45
5 changed files with 42 additions and 28 deletions
+21
View File
@@ -279,6 +279,27 @@ UserSchema.method('can', function(...actions) {
return can(this, ...actions);
});
/**
* firstEmail will return the first email on the user.
*/
UserSchema.virtual('firstEmail').get(function() {
const emails = this.emails;
if (emails.length === 0) {
return null;
}
return emails[0];
});
/**
* emails will return all the emails on a user.
*/
UserSchema.virtual('emails').get(function() {
return (this.profiles || [])
.filter(({provider}) => provider === 'local')
.map(({id}) => id);
});
/**
* hasVerifiedEmail will return true if at least one of the local email accounts
* have their email verified.