Browse Source

Fix #200: Bug: 500 Internal Server Error occures when basic-auth configuration is set

Yuki Takei 8 years ago
parent
commit
03f6c7229a
2 changed files with 12 additions and 10 deletions
  1. 6 8
      lib/util/i18nUserSettingDetector.js
  2. 6 2
      lib/util/middlewares.js

+ 6 - 8
lib/util/i18nUserSettingDetector.js

@@ -2,15 +2,13 @@ module.exports = {
   name: 'userSettingDetector',
   name: 'userSettingDetector',
 
 
   lookup: function(req, res, options) {
   lookup: function(req, res, options) {
-    var lang = null;
-
-    if (req.user) {
-      if ('lang' in req.user) {
-        lang = req.user.lang || null;
-      }
+    // return null if
+    //  1. user doesn't logged in
+    //  2. req.user is username/email string to login which is set by basic-auth-connect
+    if (req.user == null || !(req.user instanceof Object)) {
+      return null;
     }
     }
-
-    return lang;
+    return req.user.lang || null;
   },
   },
 
 
   cacheUserlanguage: function(req, res, lng, options) {
   cacheUserlanguage: function(req, res, lng, options) {

+ 6 - 2
lib/util/middlewares.js

@@ -182,7 +182,9 @@ exports.swigFilters = function(app, swig) {
 
 
 exports.adminRequired = function() {
 exports.adminRequired = function() {
   return function(req, res, next) {
   return function(req, res, next) {
-    if (req.user && '_id' in req.user) {
+    // check the user logged in
+    //  make sure that req.user isn't username/email string to login which is set by basic-auth-connect
+    if (req.user != null && (req.user instanceof Object) && '_id' in req.user) {
       if (req.user.admin) {
       if (req.user.admin) {
         next();
         next();
         return;
         return;
@@ -215,7 +217,9 @@ exports.loginRequired = function(crowi, app, isStrictly = true) {
       }
       }
     }
     }
 
 
-    if (req.user && '_id' in req.user) {
+    // check the user logged in
+    //  make sure that req.user isn't username/email string to login which is set by basic-auth-connect
+    if (req.user != null && (req.user instanceof Object) && '_id' in req.user) {
       if (req.user.status === User.STATUS_ACTIVE) {
       if (req.user.status === User.STATUS_ACTIVE) {
         // Active の人だけ先に進める
         // Active の人だけ先に進める
         return next();
         return next();