Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Don't generate gravatar hash if no email

Cette révision appartient à :
sfan5 2017-05-09 17:20:19 +02:00
Parent 1ab80d5701
révision 5bb6244564
2 fichiers modifiés avec 17 ajouts et 3 suppressions

Voir le fichier

@ -22,7 +22,7 @@ type User struct {
Likings []User `gorm:"foreignkey:userId;associationforeignkey:follower_id;many2many:user_follows"`
Liked []User `gorm:"foreignkey:follower_id;associationforeignkey:userId;many2many:user_follows"`
Md5 string `json:"md5"`
Md5 string `json:"md5"` // Used for gravatar
Torrents []Torrents `gorm:"ForeignKey:UploaderId"`
}

Voir le fichier

@ -61,17 +61,25 @@ func CreateUserFromForm(registrationForm formStruct.RegistrationForm) (model.Use
var user model.User
log.Debugf("registrationForm %+v\n", registrationForm)
modelHelper.AssignValue(&user, &registrationForm)
user.Md5 = crypto.GenerateMD5Hash(user.Email) // Gravatar
if user.Email == "" {
user.Md5 = ""
} else {
user.Md5 = crypto.GenerateMD5Hash(user.Email)
}
token, err := crypto.GenerateRandomToken32()
if err != nil {
return user, errors.New("Token not generated.")
}
user.Token = token
user.TokenExpiration = timeHelper.FewDaysLater(config.AuthTokenExpirationDay)
log.Debugf("user %+v\n", user)
if db.ORM.Create(&user).Error != nil {
return user, errors.New("User is not created.")
}
user.CreatedAt = time.Now()
return user, nil
}
@ -136,7 +144,12 @@ func RetrieveUsers() []*model.PublicUser {
// UpdateUserCore updates a user. (Applying the modifed data of user).
func UpdateUserCore(user *model.User) (int, error) {
user.Md5 = crypto.GenerateMD5Hash(user.Email)
if user.Email == "" {
user.Md5 = ""
} else {
user.Md5 = crypto.GenerateMD5Hash(user.Email)
}
token, err := crypto.GenerateRandomToken32()
if err != nil {
return http.StatusInternalServerError, errors.New("Token not generated.")
@ -146,6 +159,7 @@ func UpdateUserCore(user *model.User) (int, error) {
if db.ORM.Save(user).Error != nil {
return http.StatusInternalServerError, errors.New("User is not updated.")
}
user.UpdatedAt = time.Now()
return http.StatusOK, nil
}