UpdatePassword updates the user's password. Use SetPassword outside of a transaction first!
(tx *storage.Connection, sessionID *uuid.UUID)
| 353 | |
| 354 | // UpdatePassword updates the user's password. Use SetPassword outside of a transaction first! |
| 355 | func (u *User) UpdatePassword(tx *storage.Connection, sessionID *uuid.UUID) error { |
| 356 | // These need to be reset because password change may mean the user no longer trusts the actions performed by the previous password. |
| 357 | u.ConfirmationToken = "" |
| 358 | u.ConfirmationSentAt = nil |
| 359 | u.RecoveryToken = "" |
| 360 | u.RecoverySentAt = nil |
| 361 | u.EmailChangeTokenCurrent = "" |
| 362 | u.EmailChangeTokenNew = "" |
| 363 | u.EmailChangeSentAt = nil |
| 364 | u.PhoneChangeToken = "" |
| 365 | u.PhoneChangeSentAt = nil |
| 366 | u.ReauthenticationToken = "" |
| 367 | u.ReauthenticationSentAt = nil |
| 368 | |
| 369 | if err := tx.UpdateOnly(u, "encrypted_password", "confirmation_token", "confirmation_sent_at", "recovery_token", "recovery_sent_at", "email_change_token_current", "email_change_token_new", "email_change_sent_at", "phone_change_token", "phone_change_sent_at", "reauthentication_token", "reauthentication_sent_at"); err != nil { |
| 370 | return err |
| 371 | } |
| 372 | |
| 373 | if err := ClearAllOneTimeTokensForUser(tx, u.ID); err != nil { |
| 374 | return err |
| 375 | } |
| 376 | |
| 377 | if sessionID == nil { |
| 378 | // log out user from all sessions to ensure reauthentication after password change |
| 379 | return Logout(tx, u.ID) |
| 380 | } else { |
| 381 | // log out user from all other sessions to ensure reauthentication after password change |
| 382 | return LogoutAllExceptMe(tx, *sessionID, u.ID) |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | // Authenticate a user from a password |
| 387 | func (u *User) Authenticate(ctx context.Context, tx *storage.Connection, password string, decryptionKeys map[string]string, encrypt bool, encryptionKeyID string) (bool, bool, error) { |
no test coverage detected