|
@@ -95,7 +95,7 @@ module.exports = function(crowi, app) {
|
|
|
* @param {*} res
|
|
* @param {*} res
|
|
|
*/
|
|
*/
|
|
|
const loginFailure = (req, res) => {
|
|
const loginFailure = (req, res) => {
|
|
|
- req.errors = ErrorV3('sign_in_failure');
|
|
|
|
|
|
|
+ req.form.errors.push(ErrorV3('sign_in_failure', 'signin-failure'));
|
|
|
return loginFailureHandler(req, res, req.t('message.sign_in_failure'));
|
|
return loginFailureHandler(req, res, req.t('message.sign_in_failure'));
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -122,15 +122,17 @@ module.exports = function(crowi, app) {
|
|
|
* @param {*} next
|
|
* @param {*} next
|
|
|
*/
|
|
*/
|
|
|
const loginWithLdap = async(req, res, next) => {
|
|
const loginWithLdap = async(req, res, next) => {
|
|
|
|
|
+ const { errors } = req.form;
|
|
|
if (!passportService.isLdapStrategySetup) {
|
|
if (!passportService.isLdapStrategySetup) {
|
|
|
debug('LdapStrategy has not been set up');
|
|
debug('LdapStrategy has not been set up');
|
|
|
|
|
+ errors.push(ErrorV3('message.strategy_has_not_been_set_up.LdapStrategy', 'ldap-strategy-has-not-been-set-up'));
|
|
|
return next();
|
|
return next();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!req.form.isValid) {
|
|
if (!req.form.isValid) {
|
|
|
debug('invalid form');
|
|
debug('invalid form');
|
|
|
- return res.render('login', {
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // no need to push error to req.form because loginValidation middleware already took care of it.
|
|
|
|
|
+ return next();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const providerId = 'ldap';
|
|
const providerId = 'ldap';
|
|
@@ -142,11 +144,13 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
debug(err.message);
|
|
debug(err.message);
|
|
|
|
|
+ errors.push(err);
|
|
|
return next();
|
|
return next();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// check groups for LDAP
|
|
// check groups for LDAP
|
|
|
if (!isValidLdapUserByGroupFilter(ldapAccountInfo)) {
|
|
if (!isValidLdapUserByGroupFilter(ldapAccountInfo)) {
|
|
|
|
|
+ errors.push(ErrorV3('message.ldap_user_not_valid'));
|
|
|
return next();
|
|
return next();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -172,6 +176,7 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
|
|
const externalAccount = await getOrCreateUser(req, res, userInfo, providerId);
|
|
const externalAccount = await getOrCreateUser(req, res, userInfo, providerId);
|
|
|
if (!externalAccount) {
|
|
if (!externalAccount) {
|
|
|
|
|
+ errors.push(ErrorV3('message.external_account_not_exist'));
|
|
|
return next();
|
|
return next();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -248,15 +253,16 @@ module.exports = function(crowi, app) {
|
|
|
* @param {*} next
|
|
* @param {*} next
|
|
|
*/
|
|
*/
|
|
|
const loginWithLocal = (req, res, next) => {
|
|
const loginWithLocal = (req, res, next) => {
|
|
|
|
|
+ const { errors } = req.form;
|
|
|
if (!passportService.isLocalStrategySetup) {
|
|
if (!passportService.isLocalStrategySetup) {
|
|
|
debug('LocalStrategy has not been set up');
|
|
debug('LocalStrategy has not been set up');
|
|
|
- req.errors.push(ErrorV3('message.strategy_has_not_been_set_up.LocalStrategy', 'local-strategy-has-not-been-set-up'));
|
|
|
|
|
|
|
+ errors.push(ErrorV3('message.strategy_has_not_been_set_up.LocalStrategy', 'local-strategy-has-not-been-set-up'));
|
|
|
return next();
|
|
return next();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!req.form.isValid) {
|
|
if (!req.form.isValid) {
|
|
|
- return res.render('login', {
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // no need to push error to req.form because loginValidation middleware already took care of it.
|
|
|
|
|
+ return next();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
passport.authenticate('local', (err, user, info) => {
|
|
passport.authenticate('local', (err, user, info) => {
|
|
@@ -266,8 +272,8 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
|
|
if (err) { // DB Error
|
|
if (err) { // DB Error
|
|
|
logger.error('Database Server Error: ', err);
|
|
logger.error('Database Server Error: ', err);
|
|
|
- req.errors.push(ErrorV3('message.database_error', 'database-error'));
|
|
|
|
|
- return next(); // pass and the flash message is displayed when all of authentications are failed.
|
|
|
|
|
|
|
+ errors.push(ErrorV3('message.database_error', 'database-error'));
|
|
|
|
|
+ return next();
|
|
|
}
|
|
}
|
|
|
if (!user) { return next() }
|
|
if (!user) { return next() }
|
|
|
req.logIn(user, (err) => {
|
|
req.logIn(user, (err) => {
|