public async Task <AdminListResponse> GetAdminAsync([FromBody] AdminListRequest model)
        {
            var(pageSize, pageNumber, admins) = await _adminsService.GetAsync(model.PageSize, model.CurrentPage, model.SearchValue, model.Active);

            return(new AdminListResponse
            {
                Items = _mapper.Map <List <AdminModel> >(admins),
                PagedResponse = new PagedResponseModel(pageNumber, pageSize)
            });
        }
示例#2
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}");
            }
        }