From 38575931b02919555aa2a65f5db01ad41ac4a099 Mon Sep 17 00:00:00 2001 From: NGPixel Date: Fri, 23 Feb 2018 18:38:01 -0500 Subject: [PATCH] fix: azure ad email getter --- server/models/user.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/server/models/user.js b/server/models/user.js index 18b2e429..83acd6e8 100644 --- a/server/models/user.js +++ b/server/models/user.js @@ -48,6 +48,7 @@ var userSchema = Mongoose.Schema({ userSchema.statics.processProfile = (profile) => { let primaryEmail = '' + let name = '' if (_.isArray(profile.emails)) { let e = _.find(profile.emails, ['primary', true]) primaryEmail = (e) ? e.value : _.first(profile.emails).value @@ -57,6 +58,8 @@ userSchema.statics.processProfile = (profile) => { primaryEmail = profile.mail } else if (profile.user && profile.user.email && profile.user.email.length > 5) { primaryEmail = profile.user.email + } else if (_.isString(profile.unique_name) && profile.unique_name.length > 5) { + primaryEmail = profile.unique_name } else { return Promise.reject(new Error(lang.t('auth:errors.invaliduseremail'))) } @@ -64,6 +67,16 @@ userSchema.statics.processProfile = (profile) => { profile.provider = _.lowerCase(profile.provider) primaryEmail = _.toLower(primaryEmail) + if (_.has(profile, 'displayName')) { + name = profile.displayName + } else if (_.has(profile, 'name')) { + name = profile.name + } else if (_.has(profile, 'cn')) { + name = profile.cn + } else { + name = _.split(primaryEmail, '@')[0] + } + return db.User.findOneAndUpdate({ email: primaryEmail, provider: profile.provider @@ -71,7 +84,7 @@ userSchema.statics.processProfile = (profile) => { email: primaryEmail, provider: profile.provider, providerId: profile.id, - name: profile.displayName || profile.cn || _.split(primaryEmail, '@')[0] + name }, { new: true }).then((user) => { @@ -82,7 +95,7 @@ userSchema.statics.processProfile = (profile) => { provider: profile.provider, providerId: profile.id, password: '', - name: profile.displayName || profile.name || profile.cn, + name, rights: [{ role: 'read', path: '/',