Пример #1
0
        public async Task <IActionResult> ResetPassword([FromBody] ResetRequest request)
        {
            try
            {
                var user = await _userRepository.WithEmail(request.email);

                var password = PasswordGenerator.CreateRandomPassword(8);
                user.Password = _passwordHasher.HashPassword(user, password);
                var cmd    = new ChangePasswordCmd(user.Password, user.Id);
                var result = await _userRepository.ChangePassword(cmd);

                if (result)
                {
                    bool response = MailsHelpers.MailPassword(user.Email, password);
                    if (response)
                    {
                        return(Ok());
                    }
                    else
                    {
                        return(new JsonResult(new ResponseMail("Error al mandar correo", 0, 400))
                        {
                            StatusCode = 400
                        });
                    }
                }
                else
                {
                    return(new JsonResult(new ResponseMail("Error al actualizar", 0, 404))
                    {
                        StatusCode = 404
                    });
                }
            }
            catch (Exception e)
            {
                return(new JsonResult(e.Message)
                {
                    StatusCode = 500
                });
            }
        }
Пример #2
0
        public async Task <IActionResult> CreateWithPassword([FromBody] CreateUserPasswordReq req)
        {
            var cmd    = new CreateUserCmd(req, HttpContext.UserId().Value);
            var entity = await userRepository.Create(cmd);

            if (entity != null)
            {
                var sent = MailsHelpers.MailPassword("*****@*****.**", cmd.Password);
                if (sent)
                {
                    return(Created($"/api/users/{entity.Id}", new UserResponse(entity)));
                }
                else
                {
                    return(StatusCode(500));
                }
            }
            else
            {
                return(BadRequest());
            }
        }