Updates user email and writes user doc
(u User, email string)
| 615 | |
| 616 | // Updates user email and writes user doc |
| 617 | func (auth *Authenticator) UpdateUserEmail(u User, email string) error { |
| 618 | |
| 619 | updateUserEmailCallback := func(currentPrincipal Principal) (updatedPrincipal Principal, err error) { |
| 620 | currentUser, ok := currentPrincipal.(User) |
| 621 | if !ok { |
| 622 | return nil, base.ErrUpdateCancel |
| 623 | } |
| 624 | |
| 625 | if currentUser.Email() == email { |
| 626 | return currentUser, base.ErrUpdateCancel |
| 627 | } |
| 628 | |
| 629 | base.DebugfCtx(auth.LogCtx, base.KeyAuth, "Updating user %s email to: %v", base.UD(u.Name()), base.UD(email)) |
| 630 | err = currentUser.SetEmail(email) |
| 631 | if err != nil { |
| 632 | return nil, err |
| 633 | } |
| 634 | currentUser.SetUpdatedAt() |
| 635 | |
| 636 | return currentUser, nil |
| 637 | } |
| 638 | |
| 639 | return auth.casUpdatePrincipal(u, updateUserEmailCallback) |
| 640 | } |
| 641 | |
| 642 | // rehashPassword will check the bcrypt cost of the given hash |
| 643 | // and will reset the user's password if the configured cost has since changed |