Просмотр исходного кода

remove crowi classic auth backend & fix installer

mizozobu 6 лет назад
Родитель
Сommit
446f0a6f29
3 измененных файлов с 11 добавлено и 41 удалено
  1. 4 12
      src/server/crowi/express-init.js
  2. 7 9
      src/server/models/user.js
  3. 0 20
      src/server/util/middlewares.js

+ 4 - 12
src/server/crowi/express-init.js

@@ -139,11 +139,9 @@ module.exports = function(crowi, app) {
   });
 
   // passport
-  if (getConfig('crowi', 'security:isEnabledPassport')) {
-    debug('initialize Passport');
-    app.use(passport.initialize());
-    app.use(passport.session());
-  }
+  debug('initialize Passport');
+  app.use(passport.initialize());
+  app.use(passport.session());
 
   app.use(flash());
 
@@ -154,13 +152,7 @@ module.exports = function(crowi, app) {
 
   app.use(middlewares.csrfKeyGenerator());
 
-  // switch loginChecker
-  if (getConfig('crowi', 'security:isEnabledPassport')) {
-    app.use(middlewares.loginCheckerForPassport);
-  }
-  else {
-    app.use(middlewares.loginChecker);
-  }
+  app.use(middlewares.loginCheckerForPassport);
 
   app.use(i18nMiddleware.handle(i18next));
 };

+ 7 - 9
src/server/models/user.js

@@ -622,10 +622,8 @@ module.exports = function(crowi) {
 
     const User = this;
     const createdUserList = [];
-    const Config = crowi.model('Config');
-    const config = crowi.getConfig();
-
     const mailer = crowi.getMailer();
+
     if (!Array.isArray(emailList)) {
       debug('emailList is not array');
     }
@@ -665,7 +663,7 @@ module.exports = function(crowi) {
           newUser.createdAt = Date.now();
           newUser.status = STATUS_INVITED;
 
-          const globalLang = Config.globalLang(config);
+          const globalLang = crowi.configManager.getConfig('crowi', 'app:globalLang');
           if (globalLang != null) {
             newUser.lang = globalLang;
           }
@@ -706,15 +704,17 @@ module.exports = function(crowi) {
                 return next();
               }
 
+              const appTitle = crowi.appService.getAppTitle();
+
               mailer.send({
                 to: user.email,
-                subject: `Invitation to ${Config.appTitle(config)}`,
+                subject: `Invitation to ${appTitle}`,
                 template: path.join(crowi.localeDir, 'en-US/admin/userInvitation.txt'),
                 vars: {
                   email: user.email,
                   password: user.password,
                   url: crowi.appService.getSiteUrl(),
-                  appTitle: Config.appTitle(config),
+                  appTitle,
                 },
               },
               (err, s) => {
@@ -759,9 +759,7 @@ module.exports = function(crowi) {
       newUser.setPassword(password);
     }
 
-    const Config = crowi.model('Config');
-    const config = crowi.getConfig();
-    const globalLang = Config.globalLang(config);
+    const globalLang = crowi.configManager.getConfig('crowi', 'app:globalLang');
     if (globalLang != null) {
       newUser.lang = globalLang;
     }

+ 0 - 20
src/server/util/middlewares.js

@@ -21,26 +21,6 @@ module.exports = (crowi, app) => {
     };
   };
 
-  middlewares.loginChecker = async function(req, res, next) {
-    const User = crowi.model('User');
-    let user = null;
-
-    try {
-      // session に user object が入ってる
-      if (req.session.user && '_id' in req.session.user) {
-        user = await User.findById(req.session.user._id).populate(User.IMAGE_POPULATION);
-      }
-
-      req.user = user;
-      req.session.user = user;
-      res.locals.user = req.user;
-      next();
-    }
-    catch (err) {
-      next(err);
-    }
-  };
-
   middlewares.loginCheckerForPassport = function(req, res, next) {
     res.locals.user = req.user;
     next();