Add change password feature

This commit is contained in:
Tom Wiesing 2022-12-28 17:58:29 +01:00
parent 515142c055
commit b9795be745
No known key found for this signature in database
10 changed files with 228 additions and 96 deletions

View file

@ -104,7 +104,10 @@ type AuthUser struct {
models.User
}
func (au AuthUser) String() string {
func (au *AuthUser) String() string {
if au == nil {
return "User{nil}"
}
hasPassword := len(au.PasswordHash) > 0
return fmt.Sprintf("User{Name:%q,Enabled:%t,HasPassword:%t,Admin:%t}", au.User.User, au.User.Enabled, hasPassword, au.User.Admin)
}
@ -126,12 +129,16 @@ func (au *AuthUser) UnsetPassword(ctx context.Context) error {
return au.Save(ctx)
}
var ErrNoUser = errors.New("user is nil")
var ErrUserDisabled = errors.New("user is disabled")
var ErrUserBlank = errors.New("user has no password set")
// CheckPassword checks if this user can login with the provided password.
// Returns nil on success, an error otherwise.
func (au *AuthUser) CheckPassword(ctx context.Context, password []byte) error {
if au == nil {
return ErrNoUser
}
if !au.User.Enabled {
return ErrUserDisabled
}