summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/auth.js34
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/auth.js b/lib/auth.js
index 1e21eb9f..b2c787b9 100644
--- a/lib/auth.js
+++ b/lib/auth.js
@@ -135,10 +135,36 @@ if (config.ldap) {
provider: 'ldap',
}
var stringifiedProfile = JSON.stringify(profile);
- // TODO: Generate secure tokens for LDAP users
- var accessToken = 'debug-access-token|LDAP-' + user.uidNumber + '|' + config.ldap.tokenSecret + '|' + new Date().getTime();
- var refreshToken = 'debug-refresh-token|LDAP-' + user.uidNumber + '|' + config.ldap.tokenSecret + '|' + new Date().getTime();
- callback(accessToken, refreshToken, profile, done);
+ models.User.findOrCreate({
+ where: {
+ profileid: profile.id.toString()
+ },
+ defaults: {
+ profile: stringifiedProfile,
+ }
+ }).spread(function (user, created) {
+ if (user) {
+ var needSave = false;
+ if (user.profile != stringifiedProfile) {
+ user.profile = stringifiedProfile;
+ needSave = true;
+ }
+ if (needSave) {
+ user.save().then(function () {
+ if (config.debug)
+ logger.info('user login: ' + user.id);
+ return done(null, user);
+ });
+ } else {
+ if (config.debug)
+ logger.info('user login: ' + user.id);
+ return done(null, user);
+ }
+ }
+ }).catch(function (err) {
+ logger.error('ldap auth failed: ' + err);
+ return done(err, null);
+ });
}));
}
// email