X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=db%2Fuser.go;h=24ce491e80ab9e4e3b7ee9135912aa4da1d9c853;hb=cf5bb85cede5b05b58ed2b40460d0b913e8b2cf6;hp=aed0ac173c92652338c213629abbe5d276fff663;hpb=7a9e5112eaaea58d55f181d3e5296e4ff839921c;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FFront.git diff --git a/db/user.go b/db/user.go index aed0ac1..24ce491 100644 --- a/db/user.go +++ b/db/user.go @@ -11,10 +11,16 @@ const ( AwaitingConfirmation ) +type UserRole string + +const RoleUser UserRole = "user" +const RoleAdmin UserRole = "admin" + type User struct { Id int64 - Email string `sql:",unique,notnull"` - PasswordHash string `sql:",notnull"` + Role UserRole + Email string + PasswordHash string OtpSecret string IsOtpSetup bool Status UserStatus @@ -70,3 +76,19 @@ func SetOtpSecret(user *User, secret string, temporary bool) error { return DB.Update(user) } + +func SetPassword(user *User, password string) error { + var err error + user.PasswordHash, err = HashPassword(password) + if err != nil { + return err + } + + return DB.Update(user) +} + +func SetUserStatus(user *User, status UserStatus) error { + user.Status = status + + return DB.Update(user) +}