yusuketk 5 лет назад
Родитель
Сommit
24b783cb2c
2 измененных файлов с 5 добавлено и 5 удалено
  1. 4 5
      src/server/models/user.js
  2. 1 0
      src/server/service/passport.js

+ 4 - 5
src/server/models/user.js

@@ -189,7 +189,7 @@ module.exports = function(crowi) {
 
   userSchema.methods.updateIsGravatarEnabled = async function(isGravatarEnabled) {
     this.isGravatarEnabled = isGravatarEnabled;
-    this.imageUrlCached = await this.generateImageUrlCached();
+    this.imageUrlCached = await this.updateImageUrlCached();
     const userData = await this.save();
     return userData;
   };
@@ -225,7 +225,7 @@ module.exports = function(crowi) {
 
   userSchema.methods.updateImage = async function(attachment) {
     this.imageAttachment = attachment;
-    this.imageUrlCached = await this.generateImageUrlCached();
+    this.imageUrlCached = await this.updateImageUrlCached();
     return this.save();
   };
 
@@ -241,20 +241,19 @@ module.exports = function(crowi) {
     }
 
     this.imageAttachment = undefined;
-    this.imageUrlCached = await this.generateImageUrlCached();
+    this.imageUrlCached = await this.updateImageUrlCached();
     return this.save();
   };
 
   userSchema.methods.updateImageUrlCached = async function() {
     this.imageUrlCached = await this.generateImageUrlCached();
-    return this.save();
   };
 
   userSchema.methods.generateImageUrlCached = async function() {
     if (this.isGravatarEnabled) {
       const email = this.email || '';
       const hash = md5(email.trim().toLowerCase());
-      this.imageUrlCached = `https://gravatar.com/avatar/${hash}`;
+      return `https://gravatar.com/avatar/${hash}`;
     }
     if (this.image) {
       return this.image;

+ 1 - 0
src/server/service/passport.js

@@ -856,6 +856,7 @@ class PassportService {
         }
         if (!user.imageUrlCached) {
           await user.updateImageUrlCached();
+          await user.save();
         }
         done(null, user);
       }