MSP-3427 added audit for password change
This commit is contained in:
1 parent
6f48eea3c9
commit
e7935499b6
3 files changed
+11
-8
No files matched your search
+2
-2
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+2
-1
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user