예제 #1
0
        public IActionResult ResetPassword(string token)
        {
            Dtos.PasswordReset model = new Dtos.PasswordReset()
            {
                token = token
            };

            return(View(model));
        }
예제 #2
0
        public async Task <IActionResult> ResetPassword(Dtos.PasswordReset model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            StringContent content = new StringContent(System.Text.Json.JsonSerializer.Serialize(model, typeof(Dtos.PasswordReset)), Encoding.UTF8, "application/json");

            HttpResponseMessage httpResponse = await apiClient.PostAsync("/account/resetpassword", content);

            var result = await httpResponse.Content.ReadAsStringAsync();

            if (httpResponse.IsSuccessStatusCode)
            {
                return(RedirectToAction("login", "account"));
            }

            List <ProblemDetails> problems = (List <ProblemDetails>)JsonSerializer.Deserialize(result, typeof(List <ProblemDetails>));

            problems.ForEach(problem =>
            {
                switch (problem.Type)
                {
                case "PasswordRequireDigit":
                    ModelState.AddModelError("newPassword", "Senha requer números");
                    break;

                case "PasswordRequireLower":
                    ModelState.AddModelError("newPassword", "Senha requer letras minúsculas");
                    break;

                case "PasswordRequireNonLetterOrDigit":
                    ModelState.AddModelError("newPassword", "Senha requer caracteres especiais");
                    break;

                case "PasswordRequireUpper":
                    ModelState.AddModelError("newPassword", "Senha requer letras maiúsculas");
                    break;

                case "PasswordTooShort":
                    ModelState.AddModelError("newPassword", "Senha é muito curta");
                    break;

                default:
                    ModelState.AddModelError("newPassword", problem.Detail);
                    break;
                }
            });

            return(View(model));
        }