summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLauri Ojansivu <x@xet7.org>2018-08-24 19:46:42 +0300
committerLauri Ojansivu <x@xet7.org>2018-08-24 19:46:42 +0300
commit96173ad4314cf783f4f7d9c0278762f144d95758 (patch)
treef7d24836a28ef1c54674e55fc62d06fb6035176b /models
parent3d76b8e1c16fd6ddaddafc1560ab78791604b45e (diff)
parent3e927b4e585d46d2fe66a7cd9a6de69885793302 (diff)
downloadwekan-96173ad4314cf783f4f7d9c0278762f144d95758.tar.gz
wekan-96173ad4314cf783f4f7d9c0278762f144d95758.tar.bz2
wekan-96173ad4314cf783f4f7d9c0278762f144d95758.zip
Merge branch 'devel' of https://github.com/salleman33/wekan into salleman33-devel
Diffstat (limited to 'models')
-rw-r--r--models/users.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/models/users.js b/models/users.js
index 9b070c43..6e83337e 100644
--- a/models/users.js
+++ b/models/users.js
@@ -478,6 +478,33 @@ if (Meteor.isServer) {
return user;
}
+ if (user.services.oidc) {
+ var email = user.services.oidc.email.toLowerCase();
+
+ user.username = user.services.oidc.username;
+ user.emails = [{ address: email,
+ verified: true }];
+ var initials = user.services.oidc.fullname.match(/\b[a-zA-Z]/g).join('').toUpperCase();
+ user.profile = { initials: initials, fullname: user.services.oidc.fullname };
+
+ // see if any existing user has this email address or username, otherwise create new
+ var existingUser = Meteor.users.findOne({$or: [{'emails.address': email}, {'username':user.username}]});
+ console.log("user to create : ");
+ console.log(user);
+ if (!existingUser)
+ return user;
+
+ // copy across new service info
+ var service = _.keys(user.services)[0];
+ existingUser.services[service] = user.services[service];
+ existingUser.emails = user.emails;
+ existingUser.username = user.username;
+ existingUser.profile = user.profile;
+
+ Meteor.users.remove({_id: existingUser._id}); // remove existing record
+ return existingUser;
+ }
+
if (options.from === 'admin') {
user.createdThroughApi = true;
return user;