Skip to content

Commit 1c57a9b

Browse files
committed
Prevent adding another user with the same email
1 parent a9d1ccd commit 1c57a9b

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

backend/internal/entity/user/model.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,6 @@ func (m *Model) LoadByEmail(email string) error {
6161
return result.Error
6262
}
6363

64-
/*
65-
// Touch will update model's timestamp(s)
66-
func (m *Model) Touch(created bool) {
67-
var d types.DBDate
68-
d.Time = time.Now()
69-
if created {
70-
m.CreatedOn = d
71-
}
72-
m.ModifiedOn = d
73-
m.generateGravatar()
74-
}
75-
*/
76-
7764
// Save will save this model to the DB
7865
func (m *Model) Save() error {
7966
// Ensure email is nice
@@ -82,8 +69,12 @@ func (m *Model) Save() error {
8269
return errors.ErrSystemUserReadonly
8370
}
8471

72+
// Check if an existing user with this email exists
73+
if m2, err := GetByEmail(m.Email); err == nil && m.ID != m2.ID {
74+
return errors.ErrDuplicateEmailUser
75+
}
76+
8577
db := database.GetDB()
86-
// todo: touch? not sure that save does this or not?
8778
result := db.Save(m)
8879
return result.Error
8980
}

0 commit comments

Comments
 (0)