|
@@ -12,6 +12,8 @@ module.exports = function(crowi, app) {
|
|
|
* @param {*} res
|
|
* @param {*} res
|
|
|
*/
|
|
*/
|
|
|
const loginSuccess = (req, res, user) => {
|
|
const loginSuccess = (req, res, user) => {
|
|
|
|
|
+ debug('loginSuccess called');
|
|
|
|
|
+
|
|
|
var jumpTo = req.session.jumpTo;
|
|
var jumpTo = req.session.jumpTo;
|
|
|
if (jumpTo) {
|
|
if (jumpTo) {
|
|
|
req.session.jumpTo = null;
|
|
req.session.jumpTo = null;
|
|
@@ -26,36 +28,50 @@ module.exports = function(crowi, app) {
|
|
|
* @param {*} req
|
|
* @param {*} req
|
|
|
* @param {*} res
|
|
* @param {*} res
|
|
|
*/
|
|
*/
|
|
|
- const loginFailure = (req, res) => {
|
|
|
|
|
|
|
+ const loginFailure = (req, res, next) => {
|
|
|
req.flash('warningMessage', 'Sign in failure.');
|
|
req.flash('warningMessage', 'Sign in failure.');
|
|
|
return res.redirect('/login');
|
|
return res.redirect('/login');
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * failure handler
|
|
|
|
|
+ * @param {*} req
|
|
|
|
|
+ * @param {*} res
|
|
|
|
|
+ */
|
|
|
|
|
+ const loginFailureByDBError = (req, res) => {
|
|
|
|
|
+ req.flash('warningMessage', 'DB Error');
|
|
|
|
|
+ return res.redirect('/login');
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
const loginWithLdap = (req, res, next) => {
|
|
const loginWithLdap = (req, res, next) => {
|
|
|
const loginForm = req.body.loginForm;
|
|
const loginForm = req.body.loginForm;
|
|
|
|
|
|
|
|
if (!req.form.isValid) {
|
|
if (!req.form.isValid) {
|
|
|
|
|
+ debug("invalid form");
|
|
|
return res.render('login', {
|
|
return res.render('login', {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
passport.authenticate('ldapauth', (err, user, info) => {
|
|
passport.authenticate('ldapauth', (err, user, info) => {
|
|
|
- debug('---authentication with LdapStrategy start---');
|
|
|
|
|
|
|
+ if (res.headersSent) { // dirty hack -- 2017.09.25
|
|
|
|
|
+ return; // cz: somehow passport.authenticate called twice when ECONNREFUSED error occurred
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ debug('--- authenticate with LdapStrategy ---');
|
|
|
debug('user', user);
|
|
debug('user', user);
|
|
|
debug('info', info);
|
|
debug('info', info);
|
|
|
|
|
|
|
|
- if (err) { return next(err); }
|
|
|
|
|
|
|
+ if (err) { // DB Error
|
|
|
|
|
+ console.log('An Error occured: ', err);
|
|
|
|
|
+ return loginFailureByDBError(req, res);
|
|
|
|
|
+ }
|
|
|
if (!user) { return next(); }
|
|
if (!user) { return next(); }
|
|
|
req.logIn(user, (err) => {
|
|
req.logIn(user, (err) => {
|
|
|
- if (err != null) {
|
|
|
|
|
- debug(err);
|
|
|
|
|
- return next();
|
|
|
|
|
|
|
+ if (err) { return next(); }
|
|
|
|
|
+ else {
|
|
|
|
|
+ return loginSuccess(req, res, user);
|
|
|
}
|
|
}
|
|
|
- return loginSuccess(req, res, user);
|
|
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
- debug('---authentication with LdapStrategy end---');
|
|
|
|
|
})(req, res, next);
|
|
})(req, res, next);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -74,21 +90,21 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
passport.authenticate('local', (err, user, info) => {
|
|
passport.authenticate('local', (err, user, info) => {
|
|
|
- debug('---authentication with LocalStrategy start---');
|
|
|
|
|
|
|
+ debug('--- authenticate with LocalStrategy ---');
|
|
|
debug('user', user);
|
|
debug('user', user);
|
|
|
debug('info', info);
|
|
debug('info', info);
|
|
|
|
|
|
|
|
- if (err) { return next(err); }
|
|
|
|
|
|
|
+ if (err) { // DB Error
|
|
|
|
|
+ console.log('An Error occured: ', err);
|
|
|
|
|
+ return loginFailureByDBError(req, res);
|
|
|
|
|
+ }
|
|
|
if (!user) { return next(); }
|
|
if (!user) { return next(); }
|
|
|
req.logIn(user, (err) => {
|
|
req.logIn(user, (err) => {
|
|
|
- if (err != null) {
|
|
|
|
|
- debug(err);
|
|
|
|
|
- return next();
|
|
|
|
|
|
|
+ if (err) { return next(); }
|
|
|
|
|
+ else {
|
|
|
|
|
+ return loginSuccess(req, res, user);
|
|
|
}
|
|
}
|
|
|
- return loginSuccess(req, res, user);
|
|
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
- debug('---authentication with LocalStrategy end---');
|
|
|
|
|
})(req, res, next);
|
|
})(req, res, next);
|
|
|
}
|
|
}
|
|
|
|
|
|