diff --git a/controller/user.go b/controller/user.go index 7f1d1d8..d644841 100644 --- a/controller/user.go +++ b/controller/user.go @@ -221,8 +221,8 @@ func (u User) GetById(ctx context.Context, identities domain.IdRequest) (*domain // @Param X-AUTH-ADMIN header string true "Токен администратора" // @Param body body domain.ChangePasswordRequest true "Тело запроса" // @Success 200 -// @Failure 400 {object} domain.GrpcError "Невалидное тело запроса" -// @Failure 500 {object} domain.GrpcError +// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" +// @Failure 500 {object} apierrors.Error "внутренняя ошибка" // @Router /user/change_password [POST] func (u User) ChangePassword(ctx context.Context, authData grpc.AuthData, req domain.ChangePasswordRequest) error { adminId, err := getAdminId(authData) diff --git a/entity/audit_event.go b/entity/audit_event.go index 7ce2956..896bf7a 100644 --- a/entity/audit_event.go +++ b/entity/audit_event.go @@ -1,11 +1,13 @@ package entity const ( - EventSuccessLogin = "success_login" - EventErrorLogin = "error_login" - EventSuccessLogout = "success_logout" - EventRoleChanged = "role_changed" - EventUserChanged = "user_changed" + EventSuccessLogin = "success_login" + EventErrorLogin = "error_login" + EventSuccessLogout = "success_logout" + EventRoleChanged = "role_changed" + EventUserChanged = "user_changed" + EventUserPasswordChanged = "success_change_password" + EventErrorPasswordChange = "error_change_password" ) type AuditEvent struct { diff --git a/service/user.go b/service/user.go index 6d40213..eab2904 100644 --- a/service/user.go +++ b/service/user.go @@ -469,6 +469,7 @@ func (u User) ChangePassword(ctx context.Context, adminId int64, oldPassword str } if err := bcrypt.CompareHashAndPassword([]byte(admin.Password), []byte(oldPassword)); err != nil { + u.auditService.SaveAuditAsync(ctx, adminId, "Указан неверный старый пароль", entity.EventErrorPasswordChange) return domain.ErrInvalidPassword } @@ -487,7 +488,7 @@ func (u User) ChangePassword(ctx context.Context, adminId int64, oldPassword str return errors.WithMessage(err, "revoke all tokens by user id") } - u.auditService.SaveAuditAsync(ctx, adminId, "Выход", entity.EventSuccessLogout) + u.auditService.SaveAuditAsync(ctx, adminId, "Сменил пароль", entity.EventUserPasswordChanged) return nil }