|
|
@@ -3,37 +3,43 @@ import loggerFactory from '~/utils/logger';
|
|
|
// disable all of linting
|
|
|
// because this file is a deprecated legacy of Crowi
|
|
|
|
|
|
-/* eslint-disable */
|
|
|
-
|
|
|
module.exports = function(crowi, app) {
|
|
|
const debug = require('debug')('growi:routes:login');
|
|
|
const logger = loggerFactory('growi:routes:login');
|
|
|
const path = require('path');
|
|
|
const User = crowi.model('User');
|
|
|
- const { configManager, appService, aclService, mailService } = crowi;
|
|
|
+ const {
|
|
|
+ configManager, appService, aclService, mailService,
|
|
|
+ } = crowi;
|
|
|
|
|
|
const actions = {};
|
|
|
|
|
|
- const loginSuccess = function(req, res, userData) {
|
|
|
- // transforming attributes
|
|
|
- // see User model
|
|
|
- req.user = req.session.user = userData.toObject();
|
|
|
-
|
|
|
- // update lastLoginAt
|
|
|
- userData.updateLastLoginAt(new Date(), (err, uData) => {
|
|
|
+ const registerSuccessHandler = function(req, res, userData) {
|
|
|
+ req.login(userData, (err) => {
|
|
|
if (err) {
|
|
|
- logger.error(`updateLastLoginAt dumps error: ${err}`);
|
|
|
+ logger.debug(err);
|
|
|
+ // I created a flash message in case the user information that processing was successful is not stored in the session.
|
|
|
+ req.flash('successMessage', req.t('message.successfully_created', { username: userData.username }));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // update lastLoginAt
|
|
|
+ userData.updateLastLoginAt(new Date(), (err, userData) => {
|
|
|
+ if (err) {
|
|
|
+ logger.error(`updateLastLoginAt dumps error: ${err}`);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // RegisterFormValidator.registerRule had code to guarantee that there was a password,
|
|
|
+ // but login.register did not. so I wrote this code.
|
|
|
+ if (!userData.password) {
|
|
|
+ return res.redirect('/me#password');
|
|
|
}
|
|
|
- });
|
|
|
-
|
|
|
- if (!userData.password) {
|
|
|
- return res.redirect('/me/password');
|
|
|
- }
|
|
|
|
|
|
- const { redirectTo } = req.session;
|
|
|
- // remove session.redirectTo
|
|
|
- delete req.session.redirectTo;
|
|
|
- return res.safeRedirect(redirectTo);
|
|
|
+ const { redirectTo } = req.session;
|
|
|
+ // remove session.redirectTo
|
|
|
+ delete req.session.redirectTo;
|
|
|
+ return res.safeRedirect(redirectTo);
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
actions.error = function(req, res) {
|
|
|
@@ -70,7 +76,7 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
|
|
|
next();
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
actions.login = function(req, res) {
|
|
|
if (req.form) {
|
|
|
@@ -86,11 +92,11 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
|
|
|
// config で closed ならさよなら
|
|
|
- if (configManager.getConfig('crowi', 'security:registrationMode') == aclService.labels.SECURITY_REGISTRATION_MODE_CLOSED) {
|
|
|
+ if (configManager.getConfig('crowi', 'security:registrationMode') === aclService.labels.SECURITY_REGISTRATION_MODE_CLOSED) {
|
|
|
return res.redirect('/');
|
|
|
}
|
|
|
|
|
|
- if (req.method == 'POST' && req.form.isValid) {
|
|
|
+ if (req.method === 'POST' && req.form.isValid) {
|
|
|
const registerForm = req.form.registerForm || {};
|
|
|
|
|
|
const name = registerForm.name;
|
|
|
@@ -136,12 +142,8 @@ module.exports = function(crowi, app) {
|
|
|
sendEmailToAllAdmins(userData);
|
|
|
}
|
|
|
|
|
|
- // add a flash message to inform the user that processing was successful -- 2017.09.23 Yuki Takei
|
|
|
- // cz. loginSuccess method doesn't work on it's own when using passport
|
|
|
- // because `req.login()` prepared by passport is not called.
|
|
|
- req.flash('successMessage', req.t('message.successfully_created',{ username: userData.username }));
|
|
|
|
|
|
- return loginSuccess(req, res, userData);
|
|
|
+ return registerSuccessHandler(req, res, userData);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
@@ -170,7 +172,7 @@ module.exports = function(crowi, app) {
|
|
|
appTitle,
|
|
|
},
|
|
|
});
|
|
|
- })
|
|
|
+ });
|
|
|
|
|
|
const results = await Promise.allSettled(promises);
|
|
|
results
|
|
|
@@ -183,7 +185,7 @@ module.exports = function(crowi, app) {
|
|
|
return res.redirect('/login');
|
|
|
}
|
|
|
|
|
|
- if (req.method == 'POST' && req.form.isValid) {
|
|
|
+ if (req.method === 'POST' && req.form.isValid) {
|
|
|
const user = req.user;
|
|
|
const invitedForm = req.form.invitedForm || {};
|
|
|
const username = invitedForm.username;
|