feat: add UpdateAccountEmail

This commit is contained in:
Derrick Hammer 2024-03-19 07:46:58 -04:00
parent fddc64799e
commit 9bfdef1519
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 26 additions and 0 deletions

View File

@ -278,6 +278,32 @@ func (s AccountServiceDefault) UpdateAccountName(userId uint, firstName string,
return s.updateAccountInfo(userId, models.User{FirstName: firstName, LastName: lastName})
}
func (s AccountServiceDefault) UpdateAccountEmail(userId uint, email string, password string) error {
exists, _, err := s.EmailExists(email)
if err != nil {
return err
}
if exists {
return NewAccountError(ErrKeyEmailAlreadyExists, nil)
}
valid, _, err := s.ValidLoginByUserID(userId, password)
if err != nil {
return err
}
if !valid {
return NewAccountError(ErrKeyInvalidLogin, nil)
}
var update models.User
update.Email = email
return s.updateAccountInfo(userId, update)
}
func (s AccountServiceDefault) AddPubkeyToAccount(user models.User, pubkey string) error {
var model models.PublicKey