예제 #1
0
        public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordModel model)
        {
            var(adminServiceResponseError, admin) = await _adminsService.GetAsync(_requestContext.UserId);

            var email = admin.Email;

            var error = await _adminsService.ChangePasswordAsync(email, model.CurrentPassword, model.NewPassword);

            if (error == AdminChangePasswordErrorCodes.None)
            {
                await _auditLogPublisher.PublishAuditLogAsync(_requestContext.UserId, null, ActionType.ChangeAdminPassword);

                return(Ok());
            }

            switch (error)
            {
            case AdminChangePasswordErrorCodes.AdminNotActive:
                throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.AdminNotActive);

            case AdminChangePasswordErrorCodes.LoginNotFound:
            case AdminChangePasswordErrorCodes.PasswordMismatch:
                throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.InvalidCredentials);

            case AdminChangePasswordErrorCodes.InvalidEmailOrPasswordFormat:
                throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.InvalidEmailOrPasswordFormat);

            case AdminChangePasswordErrorCodes.NewPasswordInvalid:
                throw LykkeApiErrorException.BadRequest(ApiErrorCodes.Service.NewPasswordInvalid);

            default:
                throw new InvalidOperationException($"Unexpected error during change password for {email.SanitizeEmail()} - {error}");
            }
        }