Пример #1
0
        public async Task <IActionResult> Index([FromBody] SetUserPasswordRequestModel model)
        {
            var validator = new SetPasswordModelValidator();
            var result    = await validator.ValidateAsync(model);

            if (result.IsValid)
            {
                var language     = CultureInfo.CurrentUICulture.Name;
                var serviceModel = new SetUserPasswordServiceModel
                {
                    ExpirationId = model.Id.Value,
                    Password     = model.Password,
                    Language     = language
                };

                var user = await this.usersService.SetPasswordAsync(serviceModel);

                if (user is not null)
                {
                    if (await this.userService.SignInAsync(user.Email, model.Password, null, null))
                    {
                        return(this.StatusCode((int)HttpStatusCode.Redirect));
                    }
                }
            }

            return(this.StatusCode((int)HttpStatusCode.BadRequest));
        }
Пример #2
0
        public async Task <IActionResult> SetPassword(SetUserPasswordRequestModel request)
        {
            var serviceModel = new SetUserPasswordServiceModel
            {
                ExpirationId = request.ExpirationId.Value,
                Password     = request.Password,
            };

            var validator        = new SetUserPasswordModelValidator();
            var validationResult = await validator.ValidateAsync(serviceModel);

            if (validationResult != null)
            {
                var response = await this.userService.SetPasswordAsync(serviceModel);

                return(this.StatusCode((int)HttpStatusCode.OK, new { response.Id }));
            }

            throw new CustomException(string.Join(ErrorConstants.ErrorMessagesSeparator, validationResult.Errors.Select(x => x.ErrorMessage)), (int)HttpStatusCode.UnprocessableEntity);
        }