itizawa 5 سال پیش
والد
کامیت
2b15c60c9c
2فایلهای تغییر یافته به همراه12 افزوده شده و 10 حذف شده
  1. 0 8
      src/server/models/user.js
  2. 12 2
      src/server/routes/apiv3/personal-setting.js

+ 0 - 8
src/server/models/user.js

@@ -436,14 +436,6 @@ module.exports = function(crowi) {
     });
   };
 
-  userSchema.statics.isPasswordSetById = async function(userId) {
-    if (userId == null) {
-      return Promise.resolve(null);
-    }
-    const user = await this.findOne({ _id: userId });
-    return (user.password != null);
-  };
-
   userSchema.statics.findUserByUsername = function(username) {
     if (username == null) {
       return Promise.resolve(null);

+ 12 - 2
src/server/routes/apiv3/personal-setting.js

@@ -147,8 +147,18 @@ module.exports = (crowi) => {
    *                      type: boolean
    */
   router.get('/is-password-set', accessTokenParser, loginRequiredStrictly, async(req, res) => {
-    const isPasswordSet = await User.isPasswordSetById(req.user._id);
-    return res.apiv3({ isPasswordSet });
+    const { _id } = req.user;
+
+    try {
+      const user = await User.findOne({ _id });
+      const isPasswordSet = user.isPasswordSet();
+      return res.apiv3({ isPasswordSet });
+    }
+    catch (err) {
+      logger.error(err);
+      return res.apiv3Err('update-personal-settings-failed');
+    }
+
   });
 
   /**