diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/auth.js | 28 | ||||
-rw-r--r-- | lib/config.js | 6 | ||||
-rw-r--r-- | lib/migrations/20160515114000-user-add-tokens.js | 15 | ||||
-rw-r--r-- | lib/models/user.js | 11 | ||||
-rw-r--r-- | lib/response.js | 16 |
5 files changed, 62 insertions, 14 deletions
diff --git a/lib/auth.js b/lib/auth.js index af3e8d1d..ec45eea3 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -4,6 +4,7 @@ var passport = require('passport'); var FacebookStrategy = require('passport-facebook').Strategy; var TwitterStrategy = require('passport-twitter').Strategy; var GithubStrategy = require('passport-github').Strategy; +var GitlabStrategy = require('passport-gitlab2').Strategy; var DropboxStrategy = require('passport-dropbox-oauth2').Strategy; //core @@ -18,13 +19,23 @@ function callback(accessToken, refreshToken, profile, done) { profileid: profile.id.toString() }, defaults: { - profile: JSON.stringify(profile) + profile: JSON.stringify(profile), + accessToken: accessToken, + refreshToken: refreshToken } }).spread(function(user, created) { if (user) { - if (config.debug) - logger.info('user login: ' + user.id); - return done(null, user); + if(user.accessToken == accessToken){ + if (config.debug) + logger.info('user login: ' + user.id); + return done(null, user); + } + user.accessToken = accessToken; + user.save().then(function(){ + if (config.debug) + logger.info('user login: ' + user.id); + return done(null, user); + }) } }).catch(function(err) { logger.error('auth callback failed: ' + err); @@ -56,6 +67,15 @@ if (config.github) { callbackURL: config.serverurl + '/auth/github/callback' }, callback)); } +//gitlab +if (config.gitlab) { + passport.use(new GitlabStrategy({ + baseURL: config.gitlab.baseURL, + clientID: config.gitlab.clientID, + clientSecret: config.gitlab.clientSecret, + callbackURL: config.serverurl + '/auth/gitlab/callback' + }, callback)); +} //dropbox if (config.dropbox) { passport.use(new DropboxStrategy({ diff --git a/lib/config.js b/lib/config.js index 6738d4a8..cdaec31c 100644 --- a/lib/config.js +++ b/lib/config.js @@ -25,7 +25,7 @@ var db = config.db || { }; // ssl path -var sslkeypath = config.sslkeypath || '' +var sslkeypath = config.sslkeypath || ''; var sslcertpath = config.sslcertpath || ''; var sslcapath = config.sslcapath || ''; var dhparampath = config.dhparampath || ''; @@ -59,6 +59,7 @@ var documentmaxlength = config.documentmaxlength || 100000; var facebook = config.facebook || false; var twitter = config.twitter || false; var github = config.github || false; +var gitlab = config.gitlab || false; var dropbox = config.dropbox || false; var imgur = config.imgur || false; @@ -110,6 +111,7 @@ module.exports = { facebook: facebook, twitter: twitter, github: github, + gitlab: gitlab, dropbox: dropbox, imgur: imgur -};
\ No newline at end of file +}; diff --git a/lib/migrations/20160515114000-user-add-tokens.js b/lib/migrations/20160515114000-user-add-tokens.js new file mode 100644 index 00000000..3af490a9 --- /dev/null +++ b/lib/migrations/20160515114000-user-add-tokens.js @@ -0,0 +1,15 @@ +"use strict"; + +module.exports = { + up: function (queryInterface, Sequelize) { + queryInterface.addColumn('Users', 'accessToken', Sequelize.STRING); + queryInterface.addColumn('Users', 'refreshToken', Sequelize.STRING); + return; + }, + + down: function (queryInterface, Sequelize) { + queryInterface.removeColumn('Users', 'accessToken'); + queryInterface.removeColumn('Users', 'refreshToken'); + return; + } +};
\ No newline at end of file diff --git a/lib/models/user.js b/lib/models/user.js index e1a373d6..64173cbd 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -23,6 +23,12 @@ module.exports = function (sequelize, DataTypes) { }, history: { type: DataTypes.TEXT + }, + accessToken: { + type: DataTypes.STRING + }, + refreshToken: { + type: DataTypes.STRING } }, { classMethods: { @@ -63,6 +69,9 @@ module.exports = function (sequelize, DataTypes) { case "github": photo = 'https://avatars.githubusercontent.com/u/' + profile.id + '?s=48'; break; + case "gitlab": + photo = profile.avatarUrl; + break; case "dropbox": //no image api provided, use gravatar photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0].value); @@ -72,6 +81,6 @@ module.exports = function (sequelize, DataTypes) { } } }); - + return User; };
\ No newline at end of file diff --git a/lib/response.js b/lib/response.js index 7a75e234..99cd080a 100644 --- a/lib/response.js +++ b/lib/response.js @@ -48,7 +48,7 @@ var response = { showNote: showNote, showPublishNote: showPublishNote, showPublishSlide: showPublishSlide, - showIndex: showIndex, + showIndex: showIndex, noteActions: noteActions, publishNoteActions: publishNoteActions, githubActions: githubActions @@ -72,7 +72,7 @@ function responseError(res, code, detail, msg) { code: code, detail: detail, msg: msg, - useCDN: config.usecdn + useCDN: config.usecdn }); res.write(content); res.end(); @@ -94,7 +94,8 @@ function showIndex(req, res, next) { facebook: config.facebook, twitter: config.twitter, github: config.github, - dropbox: config.dropbox, + gitlab: config.gitlab, + dropbox: config.dropbox }); res.write(content); res.end(); @@ -124,7 +125,8 @@ function responseHackMD(res, note) { facebook: config.facebook, twitter: config.twitter, github: config.github, - dropbox: config.dropbox, + gitlab: config.gitlab, + dropbox: config.dropbox }); var buf = html; res.writeHead(200, { @@ -355,7 +357,7 @@ function publishNoteActions(req, res, next) { res.redirect(config.serverurl + '/' + (note.alias ? note.alias : LZString.compressToBase64(note.id))); break; default: - res.redirect(config.serverurl + '/s/' + note.shortid); + res.redirect(config.serverurl + '/s/' + note.shortid); break; } }); @@ -370,7 +372,7 @@ function githubActions(req, res, next) { githubActionGist(req, res, note); break; default: - res.redirect(config.serverurl + '/' + noteId); + res.redirect(config.serverurl + '/' + noteId); break; } }); @@ -470,4 +472,4 @@ var render = function (res, title, markdown) { })); }; -module.exports = response;
\ No newline at end of file +module.exports = response; |