Exemplo n.º 1
0
        public async Task <IActionResult> ForgotPasswordUser(RegisterUserViewModel form)
        {
            if (!ModelState.IsValid)
            {
                return(View(form));
            }
            try
            {
                var success = ValidationHelper.ProoveValidPhoneNumber(form.PhoneNumber, out string telNumber);
                if (!success)
                {
                    ModelState.AddModelError("PhoneNumber", "Die Telefonnummer hat ein ungültiges Format");
                    return(View(form));
                }

                var user = await _context.TblUsers.FirstOrDefaultAsync(a => a.PhoneNumber == telNumber);

                if (user == null)
                {
                    ModelState.AddModelError("PhoneNumber", "Diese Telefonummer existiert nicht!");
                    return(View(form));
                }

                RestAccess ra  = new RestAccess(Constants.ServiceClientEndPointWithApiPrefix);
                var        res = await ra.UserStartResetPassword(user.Id);

                if (res.Ok)
                {
                    TempData.Add("message", "Überprüfe bitte deine SMS Nachrichten!");
                    return(RedirectToAction("LoginUser"));
                }

                ViewData["message"] = "Passwort konnte nicht verschickt werden!";
                return(View(form));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("PhoneNumber", ex.Message);
                return(View(form));
            }
        }