コード例 #1
0
        public async Task <IActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userHelper.GetUserByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "The email doesn't correspont to a registered user.");
                    return(View(model));
                }

                ModelState.AddModelError(string.Empty, "Click on the link send to your email to recover your password");


                var myToken = await _userHelper.GeneratePasswordResetTokenAsync(user);

                var link = Url.Action(
                    "ResetPassword",
                    "Account",
                    new { token = myToken }, protocol: HttpContext.Request.Scheme);

                _mailHelper.SendMail(model.Email, "HighFly Password Reset", $"<h1>HighFly Password Reset</h1>" +
                                     $"To reset the password click in this link:</br></br>" +
                                     $"<a href = \"{link}\">Reset Password</a>");

                return(View());
            }

            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                UserEntity user = await _userHelper.GetUserAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "El correo no corresponde al registrado.");
                    return(View(model));
                }

                string myToken = await _userHelper.GeneratePasswordResetTokenAsync(user);

                string link = Url.Action(
                    "ResetPassword",
                    "Account",
                    new { token = myToken }, protocol: HttpContext.Request.Scheme);
                _mailHelper.SendMail(model.Email, "Clave cambiada", $"<h1>Cambiar clave</h1>" +
                                     $"Para cambiar la contraseña presiona click en este enlace:</br></br>" +
                                     $"<a href = \"{link}\">Cambiar clave</a>");
                ViewBag.Message = "Las instrucciones para recuperar tu clave ha sido enviado al correo.";
                return(View());
            }

            return(View(model));
        }
コード例 #3
0
        public async Task <IActionResult> RecoverPasswordMVC(RecoverPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _userHelper.GetUserByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "The email doesn't correspont to a registered user.");
                    return(View(model));
                }

                string myToken = await _userHelper.GeneratePasswordResetTokenAsync(user);

                string link = Url.Action(
                    "ResetPassword",
                    "Account",
                    new { token = myToken }, protocol: HttpContext.Request.Scheme);
                _mailHelper.SendMail(model.Email, "Restablecer contraseña", $"<h1>Restablecer contraseña</h1>" +
                                     $"Sigue este este enlace para restablecer la contraseña:</br></br>" +
                                     $"<a href = \"{link}\">Restablecer consenesa</a>");
                ViewBag.Message = "Las instrucciones para cambiar la contraseña ha sido enviado a su correo.";
                return(View());
            }

            return(View(model));
        }
コード例 #4
0
        public async Task <IActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _userHelper.GetUserByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "El Email no corresponde con ningún usuario registrado.");
                    return(View(model));
                }

                string myToken = await _userHelper.GeneratePasswordResetTokenAsync(user);

                string link = Url.Action(
                    "ResetPassword",
                    "Account",
                    new { token = myToken }, protocol: HttpContext.Request.Scheme);
                _mailHelper.SendMail(model.Email, "Prensa Estudiantil - Password Reset", $"<h1>Prensa Estudiantill Password Reset</h1>" +
                                     $"To reset the password click in this link:</br></br>" +
                                     $"<a href = \"{link}\">Reset Password</a>");

                TempData["Success"] = "Las instrucciones para recuperar la contraseña fueron enviadas al correo.";
                return(View());
            }

            return(View(model));
        }
コード例 #5
0
        public ActionResult RecoverPassword(RecoverPasswordViewModel model)
        {
            UserStore <Person>   store       = new UserStore <Person>(_uw.db);
            UserManager <Person> userManager = new UserManager <Person>(store);
            var user = userManager.FindByEmail(model.Email);

            if (user != null)
            {
                var newPass = CreatePassword();
                store.SetPasswordHashAsync(user, userManager.PasswordHasher.HashPassword(newPass));
                _uw.Complete();

                var body = $"Merhaba <b>{user.UserName}</br> Hesabınızın Parolası sıfırlanmıştır.  Yeni Parolanız:{newPass}<p>Yukarıdaki parolayı kullanarak sisteme giriş yapabilirsiniz";

                WebMail.SmtpServer = "smtp.gmail.com";
                WebMail.EnableSsl  = true;
                WebMail.UserName   = "******";
                WebMail.Password   = "******";
                WebMail.SmtpPort   = 587;
                WebMail.Send(
                    model.Email,
                    "Şifre sıfırlama",
                    body
                    );
                ViewBag.b = "Email adresinizize yeni şifreniz gönderilmiştir.";
                return(View());
            }
            else
            {
                ViewBag.a = "Email adresine kayıtlı üyelik bulunamadı";
                return(View());
            }
            return(View());
        }
コード例 #6
0
        public async Task <IActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = await this.userHelper.GetUserByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "The email doesn't correspont to a registered user.");
                    return(this.View(model));
                }

                var myToken = await this.userHelper.GeneratePasswordResetTokenAsync(user);

                var link = this.Url.Action(
                    "ResetPassword",
                    "Account",
                    new { token = myToken }, protocol: HttpContext.Request.Scheme);
                this.mailHelper.SendMail(model.Email, "Postres juanita recuperación de contraseña", $"<h1>Recuperar contraseña</h1>" +
                                         $"para cambiar tu contraseña haz click aquí:</br></br>" +
                                         $"<a href = \"{link}\">Resetear contraseña</a>");
                this.ViewBag.Message = "Las instrucciones para recuperar la contraseña han sido enviadas a tu correo.";
                return(this.View());
            }

            return(this.View(model));
        }
コード例 #7
0
ファイル: AccountController.cs プロジェクト: haguer/Desastres
        public async Task <IActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userHelper.GetUserByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "El correo no corresponde al registrado.");
                    return(View(model));
                }

                var myToken = await _userHelper.GeneratePasswordResetTokenAsync(user);

                var link = Url.Action(
                    "ResetPassword",
                    "Account",
                    new { token = myToken }, protocol: HttpContext.Request.Scheme);
                _mailHelper.SendMail(model.Email, "Reiniciar Contraseña", $"<h1>Reiniciar Contraseña</h1>" +
                                     $"Para reiniciar contraseña click en el link:</br></br>" +
                                     $"<a href = \"{link}\">Resetear Contraseña</a>");
                ViewBag.Message = "Las instrucciones para recuperar la contraseña fueron enviadas al email.";
                return(View());
            }

            return(View(model));
        }
コード例 #8
0
        public ActionResult RecoverPassword(RecoverPasswordViewModel model, string email)
        {
            if (ModelState.IsValid)
            {
                //sends a password recovery email if the account exists in the system
                email = model.email;
                Account account = accountDAO.FetchByEmail(email);
                if (account != null)
                {
                    if (account.emailVerified)
                    {
                        emails.PasswordRecoveryEmail(account.email, account.email);
                        TempData["successMessage"] = "An email has been sent to you!";
                        return(RedirectToAction("Recoverpassword", "Account"));
                    }
                    else
                    {
                        emails.SendEmailAddressVerificationEmail(account.email, account.email);
                        TempData["errorMessage"] = @"The email you provided was correct 
                                but your email address has not yet been verified.  
                                We just sent another email verification email to you.  
                                Please follow the instructions in that email.";
                    }
                }
                else
                {
                    TempData["errorMessage"] = @"We could not find that email !
                                                 contact customer service on [email protected] 
                                                 if you need more help";
                }
            }

            return(View(model));
        }
コード例 #9
0
        public async Task <IActionResult> Recover(RecoverPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByEmailAsync(model.Email);

                if (user != null)
                {
                    var result = await UserManager.ResetPasswordAsync(user, model.Key, model.Password);

                    if (result.Succeeded)
                    {
                        this.ShowSuccess("Lo contraseña se ha modificado correctamente");
                        return(this.RedirectToAction("Login"));
                    }
                    else
                    {
                        var erroMessage = "";
                        foreach (var item in result.Errors)
                        {
                            erroMessage += item.Description + "/n";
                        }
                        this.ShowError(erroMessage);
                    }
                }
                else
                {
                    ModelState.AddModelError("Email", "No se encuentra ningun usuario con el email especificado");
                }
            }
            return(View());
        }
コード例 #10
0
        public ActionResult RecoverPassword(RecoverPasswordViewModel passwordViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View()); // Not sending the viewModel because passwords
            }
            var url         = $"{ProjectConstants.APIURL}/api/Account/SendResetPassword";
            var callbackUrl = Url.Action("ResetPassword", "Account", null, Request.Url.Scheme);

            var parameters = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("Email", passwordViewModel.Email),
                new KeyValuePair <string, string>("Url", callbackUrl)
            };

            var encodedParameters = new FormUrlEncodedContent(parameters);
            var response          = HttpClientContext.httpClient.PostAsync(url, encodedParameters).Result;

            if (response.IsSuccessStatusCode)
            {
                TempData.Add("Message", $"If that account exists, an email has been sent!");
                return(RedirectToAction("Index", "Household"));
            }
            else
            {
                ErrorHelpers.HandleResponseErrors(response, TempData, ModelState);
                return(View());
            }
        }
コード例 #11
0
ファイル: AccountController.cs プロジェクト: sevannr/MyVet
        public async Task <IActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userHelper.GetUserByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "The email doesn't correspont to a registered user.");
                    return(View(model));
                }

                var myToken = await _userHelper.GeneratePasswordResetTokenAsync(user);

                //var link = Url.Action(
                //    "ResetPassword",
                //    "Account",
                //    new { token = myToken }, protocol: HttpContext.Request.Scheme);
                //_mailHelper.SendMail(model.Email, "MyVet Password Reset", $"<h1>Shop Password Reset</h1>" +
                //    $"To reset the password click in this link:</br></br>" +
                //    $"<a href = \"{link}\">Reset Password</a>");
                //ViewBag.Success = "The instructions to recover your password has been sent to email.";
                //return View();

                return(RedirectToAction("ResetPassword", null, new { token = myToken }));
            }

            return(View(model));
        }
コード例 #12
0
        public async Task <IActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await userHelper.GetUserByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "The email doesn't correspont to a registered user.");
                    return(View(model));
                }

                var myToken = await userHelper.GeneratePasswordResetTokenAsync(user);

                var link = Url.Action(
                    nameof(ResetPassword),
                    AccountController.RouteController,
                    new { token = myToken }, protocol: HttpContext.Request.Scheme);
                mailHelper.SendMail(model.Email, "Auth-Web-App Password Reset", $"<h1>Shop Password Reset</h1>" +
                                    $"To reset the password click in this link:</br></br>" +
                                    $"<a href = \"{link}\">Reset Password</a>");
                ViewBag.Message = "The instructions to recover your password has been sent to email.";
                return(View());
            }

            return(View(model));
        }
コード例 #13
0
        public async Task Given_ResetPasswordFromTokenFails_When_RecoverPasswordPost_Then_ReturnsError()
        {
            // Arrange
            var model = new RecoverPasswordViewModel
            {
                Id             = TestUserId,
                SecurityAnswer = "encryptedSecurityAnswer"
            };

            _encryption.Expect(e => e.Decrypt(Arg <string> .Is.Anything, Arg <string> .Is.Anything, Arg <int> .Is.Anything,
                                              Arg <string> .Is.Anything, out Arg <string> .Out(EncryptedSecurityAnswer).Dummy)).Return(false);
            _userManager
            .Expect(a =>
                    a.ChangePasswordFromTokenAsync(Arg <int> .Is.Anything, Arg <string> .Is.Anything,
                                                   Arg <string> .Is.Anything))
            .Return(Task.FromResult(new SeIdentityResult(new List <string> {
                "some stuff went wrong"
            })));
            _recaptcha.Expect(a => a.ValidateRecaptcha(Arg <Controller> .Is.Anything)).Return(true);

            // Act
            var result = await _sut.RecoverPasswordAsync(model);

            // Assert
            AssertViewResultReturned(result, "RecoverPassword");
            Context.AssertWasNotCalled(a => a.SaveChanges());
            AssertViewResultWithError(result, "some stuff went wrong");
        }
コード例 #14
0
        public async Task Given_ValidSubmissionData_When_RecoverPasswordPost_Then_SavesEmailsAndSuccessViewReturned()
        {
            // Arrange
            var model = new RecoverPasswordViewModel
            {
                Id             = TestUserId,
                SecurityAnswer = "encryptedSecurityAnswer"
            };

            _encryption.Expect(e => e.Decrypt(Arg <string> .Is.Anything, Arg <string> .Is.Anything, Arg <int> .Is.Anything,
                                              Arg <string> .Is.Anything, out Arg <string> .Out(EncryptedSecurityAnswer).Dummy)).Return(false);
            _userManager
            .Expect(a =>
                    a.ChangePasswordFromTokenAsync(Arg <int> .Is.Anything, Arg <string> .Is.Anything,
                                                   Arg <string> .Is.Anything)).Return(Task.FromResult(new SeIdentityResult()));
            _userManager.Expect(a => a.LogOnAsync(Arg <string> .Is.Anything, Arg <bool> .Is.Anything))
            .Return(Task.FromResult(0));
            _recaptcha.Expect(a => a.ValidateRecaptcha(Arg <Controller> .Is.Anything)).Return(true);

            // Act
            var result = await _sut.RecoverPasswordAsync(model);

            // Assert
            AssertViewResultReturned(result, "RecoverPasswordSuccess");
            Context.AssertWasCalled(a => a.SaveChanges());
            _httpCache.AssertWasCalled(a => a.RemoveFromCache(Arg <string> .Is.Equal("MustChangePassword-5")));
        }
コード例 #15
0
        public ActionResult RecoverPassword()
        {
            var passwordResetToken = Request.QueryString["PasswordResetToken"] ?? "";
            var requester          = UserIdentity.GetRequester(this);

            var user = _context.User.Include("SecurityQuestionLookupItem").SingleOrDefault(u => u.PasswordResetToken == passwordResetToken && u.PasswordResetExpiryDateUtc > DateTime.UtcNow);

            if (user == null)
            {
                HandleErrorInfo error = new HandleErrorInfo(new ArgumentException(@"INFO: The password recovery token is not valid or has expired"), "Account", "RecoverPassword");
                Logger.Information("Failed Account RecoverPassword Get, recovery token {passwordResetToken} is not valid or expired by requester {@requester}", passwordResetToken, requester);
                return(View("Error", error));
            }
            if (user.Enabled == false)
            {
                var             userName = user.UserName;
                HandleErrorInfo error    = new HandleErrorInfo(new InvalidOperationException(@"INFO: Your account is not currently approved or active"), "Account", "Recover");
                Logger.Information("Failed Account RecoverPassword Get, account {userName} not approved or active by requester {@requester}", userName, requester);
                return(View("Error", error));
            }
            RecoverPasswordViewModel recoverPasswordModel = new RecoverPasswordViewModel()
            {
                Id                 = user.Id,
                HasRecaptcha       = _configuration.HasRecaptcha,
                SecurityAnswer     = "",
                SecurityQuestion   = user.SecurityQuestionLookupItem.Description,
                PasswordResetToken = passwordResetToken,
                UserName           = user.UserName
            };

            return(View("RecoverPassword", recoverPasswordModel));
        }
コード例 #16
0
        public async Task <IActionResult> RecoverPassword(RecoverPasswordViewModel recoverPasswordViewModel)
        {
            try
            {
                var    TokenData = _passwordService.ReadToken(recoverPasswordViewModel.Token);
                string email     = TokenData.Claims.FirstOrDefault().Value;
                var    User      = _userService.GetUserByEmail(email);

                if (User == null)
                {
                    return(BadRequest(email + "is not registered. Or it is not confirmed"));
                }
                else
                {
                    User.PasswordHash = _passwordService.Hash(recoverPasswordViewModel.Password);
                    await _userService.UpdateUser(User);

                    return(Ok(User));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #17
0
ファイル: AccountController.cs プロジェクト: farney9/shop
        public async Task <IActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = await this.userHelper.GetUserByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "The email doesn't correspont to a registered user.");
                    return(this.View(model));
                }

                var myToken = await this.userHelper.GeneratePasswordResetTokenAsync(user);

                var link = this.Url.Action(
                    "ResetPassword",
                    "Account",
                    new { token = myToken }, protocol: HttpContext.Request.Scheme);
                this.mailHelper.SendMail(model.Email, "Shop Password Reset", $"<h2>Shop Password Reset</h2>" +
                                         $"Click  <a href = \'{link}\' class='btn btn-link'> here</a> for reset your password");
                this.ViewBag.Message = "The instructions to recover your password has been sent to your registered email.";
                return(this.View());
            }

            return(this.View(model));
        }
コード例 #18
0
        public async Task <IActionResult> RecoverPasswordMVC(RecoverPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                UserEntity user = await _userHelper.GetUserAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "El Email no corresponde a un usuario registrado.");
                    return(View(model));
                }

                string myToken = await _userHelper.GeneratePasswordResetTokenAsync(user);

                string link = Url.Action(
                    "ResetPassword",
                    "Account",
                    new { token = myToken }, protocol: HttpContext.Request.Scheme);
                _mailHelper.SendMail(model.Email, "Soccer Recupero de Password", $"<h1>Soccer Recupero de Password</h1>" +
                                     $"Para recuperar el Password haga clic en este link: </br></br>" +
                                     $"<a href = \"{link}\">Resetear Password</a>");
                ViewBag.Message = "Las instrucciones para recuperar su password han sido enviadas por mail.";
                return(View());
            }

            return(View(model));
        }
コード例 #19
0
        public async Task <ActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            ApplicationUser user = await UserManager.FindByEmailAsync(model.Email);

            if (user == null)
            {
                ModelState.AddModelError(nameof(model.Email), Res.EmailNotRegisteredMessage);
                return(View(model));
            }

            string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

            string url = Url.Action("RedefinePassword", "BOAccountBase", new { userId = user.Id, token = code }, this.Request.Url.Scheme);

            string mailFrom = ConfigurationManager.AppSettings["EmailFromRecoverPassword"];

            _boAccountService.SendRecoverPasswordMail(mailFrom, user.Email, url);

            model.SuccessMessage = Res.RecoverPasswordMailSentMessage;
            return(View(model));
        }
コード例 #20
0
        public ActionResult RecoverPassword(RecoverPasswordViewModel model, string email)
        {
            if (ModelState.IsValid)
            {
                email = model.email;
                Account account = accountDAL.FetchByEmail(email);

                if (account != null)
                {
                    if (account.isVerified == true)
                    {
                        _email.PasswordRecoveryEmail(account.email, account.email);
                        TempData["successMessage"] = @"An email has been sent to you.";
                        return(RedirectToAction("RecoverPassword"));
                    }

                    else
                    {
                        _email.SendEmailAddressVerificationEmail(account.email, account.email);
                        TempData["errorMessage"] = @"The email you provided was correct 
                                but your email address has not yet been verified.  
                                We just sent another email verification email to you.  
                                Please follow the instructions in that email.";
                    }
                }

                else if (account == null)
                {
                    TempData["errorMessage"] = "That email does not exist.";
                }
            }
            return(View(model));
        }
コード例 #21
0
        public async Task <IActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = await this.userHelper.GetUserByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "El Correo no corresponde a un usuario registrado");
                    return(this.View(model));
                }

                var myToken = await this.userHelper.GeneratePasswordResetTokenAsync(user);

                var link = this.Url.Action(
                    "ResetPassword",
                    "Account",
                    new { token = myToken },
                    protocol: HttpContext.Request.Scheme);
                var mailSender = new MailHelper(configuration);
                mailSender.SendMail(model.Email, "Recuperar password Servicios Bomberos", $"<h1>Recupere la contraseña<h1/>" +
                                    $"Para recuperar el password haga click en el siguiente enlace:</br></br>" +
                                    $"<a href=\"{link}\">Reset password</a>");
                this.ViewBag.Message = "Las instrucciones para recuperar la contraseña han sido enviadas a su correo electrónico";
                return(this.View());
            }
            return(this.View(model));
        }
コード例 #22
0
        public async Task <IActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userHelper.GetUserByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "Este correo no corresponde a su usuario");
                    return(View(model));
                }

                var myToken = await _userHelper.GeneratePasswordResetTokenAsync(user);

                var link = Url.Action(
                    "ResetPassword",
                    "Account",
                    new { token = myToken }, protocol: HttpContext.Request.Scheme
                    );

                _mailhelper.SendMail(model.Email, "Veterinaria Zulu - Cambio de Password",
                                     $"<h1>Cambio de Contraseña</h1>" +
                                     $"Para cambiar la contraseña haga click en este link:</br></br>" +
                                     $"<a href = \"{link}\">Cambiar Contraseña</a>");

                ViewBag.Message = "Las instrucciones  para cambiar su contraseña se han enviado a su correo.";
                return(View());
            }
            return(View(model));
        }
コード例 #23
0
        public async Task <IActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = await this.userHelper.GetUserByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "Este email no corresponde al usuario registrado.");
                    return(this.View(model));
                }

                var myToken = await this.userHelper.GeneratePasswordResetTokenAsync(user);

                var link       = this.Url.Action("ResetPassword", "Account", new { token = myToken }, protocol: HttpContext.Request.Scheme);
                var mailSender = new MailHelper(configuration);
                mailSender.SendMail(model.Email, "Reacciones 911 Recuperacion de Contraseña", $"<h1>Reacciones 911 Recuperacion de Contraseña</h1>" +
                                    $"Para resetear su contraseña, haga click en este link:</br></br>" +
                                    $"<a href = \"{link}\">Resetear Contraseña</a>");
                this.ViewBag.Message = "Las instrucciones para recuperar tu contraseña, han sido enviadas a tu Correo";
                return(this.View());
            }

            return(this.View(model));
        }
コード例 #24
0
        public async Task <IActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userHelper.GetUserByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "البريد الإلكتروني لا يتوافق مع بريد المستخدم المسجل.");
                    return(View(model));
                }

                var myToken = await _userHelper.GeneratePasswordResetTokenAsync(user);

                var link = Url.Action(
                    "ResetPassword",
                    "Account",
                    new { token = myToken }, protocol: HttpContext.Request.Scheme);

                _mailHelper.SendMail(model.Email, "استعادة كلمة المرور",
                                     $"<h1>استعادة كلمة المرور</h1>" +
                                     $"لاستعادة كلمة المرور اضغط على الرابط التالي:</br></br>" +
                                     $"<a href = \"{link}\">الرابط</a>");
                ViewBag.Message = "تم إرسال التعليمات لاسترداد كلمة المرور الخاصة بك إلى البريد الإلكتروني.";
                return(View());
            }

            return(View(model));
        }
コード例 #25
0
ファイル: AccountController.cs プロジェクト: Zulu55/Core4
        public async Task <IActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = await this.userManager.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "The email doesn't correspont to a registered user.");
                    return(this.View(model));
                }

                var myToken = await this.userManager.GeneratePasswordResetTokenAsync(user);

                var link       = this.Url.Action("ResetPassword", "Account", new { token = myToken }, protocol: HttpContext.Request.Scheme);
                var mailSender = new MailHelper(configuration);
                mailSender.SendMail(model.Email, "Password Reset", $"<h1>Recover Password</h1>" +
                                    $"To reset the password click in this link:</br></br>" +
                                    $"<a href = \"{link}\">Reset Password</a>");
                this.ViewBag.Message = "The instructions to recover your password has been sent to email.";
                return(this.View());
            }

            return(this.View(model));
        }
コード例 #26
0
        public async Task <IActionResult> RecoverPasswordMVC(RecoverPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _userHelper.GetUserAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "The email doesn't correspont to a registered user.");
                    return(View(model));
                }

                string myToken = await _userHelper.GeneratePasswordResetTokenAsync(user);

                string link = Url.Action(
                    "ResetPassword",
                    "Account",
                    new { token = myToken }, protocol: HttpContext.Request.Scheme);
                _mailHelper.SendMail(model.Email, "Password Reset", $"<h1>Password Reset</h1>" +
                                     $"To reset the password click in this link:</br></br>" +
                                     $"<a href = \"{link}\">Reset Password</a>");
                ViewBag.Message = "The instructions to recover your password has been sent to email.";
                return(View());
            }

            return(View(model));
        }
コード例 #27
0
        public async Task <IActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = await _userHelper.GetUserByEmailAsync(model.Email); //verifica se user existe

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "The email doesn't correspont to a registered user.");
                    return(this.View(model));
                }

                var myToken = await _userHelper.GeneratePasswordResetTokenAsync(user); //gera token

                var link = this.Url.Action(
                    "ResetPassword",
                    "Account",
                    new { token = myToken }, protocol: HttpContext.Request.Scheme);


                _mailHelper.SendMail(model.Email, " AutoWorkshop Password Reset", $"<h1>Penguin AutoWorkshop Password Reset</h1>" +
                                     $"To reset your account password click on this link:</br></br>" +
                                     $"<a href = \"{link}\">Reset Password</a>");
                this.ViewBag.Message = "A password email reset was sent to your email address, follow the directions" +
                                       "in the email to reset your password.";
                return(this.View());
            }

            return(this.View(model));
        }
コード例 #28
0
        public async Task <ActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            try
            {
                ApplicationUser user = await _membershipTools.UserManager.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, $"{model.Email} mail adresine kayıtlı bir üyeliğe erişilemedi");
                    return(View(model));
                }

                string newPassword = StringHelpers.GetCode().Substring(0, 6);

                await _membershipTools.UserManager.RemovePasswordAsync(user);

                await _membershipTools.UserManager.AddPasswordAsync(user,
                                                                    _membershipTools.UserManager.PasswordHasher.HashPassword(user, newPassword));

                //var token=await _membershipTools.UserManager.GeneratePasswordResetTokenAsync(user);
                //await _membershipTools.UserManager.ResetPasswordAsync(user, token, newPassword);

                _dbContext.SaveChanges();

                if (_dbContext.SaveChanges() > 0)
                {
                    TempData["Message"] = new ErrorViewModel()
                    {
                        Text           = $"Bir hata oluştu",
                        ActionName     = "RecoverPassword",
                        ControllerName = "Account",
                        ErrorCode      = 500
                    };
                    return(RedirectToAction("Error500", "Home"));
                }

                EmailService emailService = new EmailService();
                string       body         = $"Merhaba <b>{user.Name} {user.Surname}</b><br>Hesabınızın parolası sıfırlanmıştır<br> Yeni parolanız: <b>{newPassword}</b> <p>Yukarıdaki parolayı kullanarak sitemize giriş yapabilirsiniz.</p>";
                emailService.Send(new HelpDesk.Models.Models.EmailModel()
                {
                    Body = body, Subject = $"{user.UserName} Şifre Kurtarma"
                }, user.Email);
            }

            catch (Exception ex)
            {
                TempData["Message"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "RecoverPassword",
                    ControllerName = "Account",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error500", "Home"));
            }
            TempData["Message"] = $"{model.Email} mail adresine yeni şifre gönderildi.";
            return(View());
        }
コード例 #29
0
        public ActionResult ChangePassword()
        {
            RecoverPasswordViewModel model = new RecoverPasswordViewModel
            {
                NombreUsuario = HttpContext.GetActualUser().NombreUsuario,
            };

            return(View("RecoverPassword", model));
        }
コード例 #30
0
        public async Task <ActionResult> RecoverPassword(RecoverPasswordViewModel model)
        {
            try
            {
                var userStore   = NewUserStore();
                var userManager = NewUserManager();
                var user        = await userStore.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, $"{model.Email} mail adresine kayıtlı bir üyeliğe erişilemedi");
                    return(View(model));
                }

                var newPassword = StringHelpers.GetCode().Substring(0, 6);
                await userStore.SetPasswordHashAsync(user, userManager.PasswordHasher.HashPassword(newPassword));

                var result = userStore.Context.SaveChanges();
                if (result == 0)
                {
                    TempData["Model"] = new ErrorViewModel()
                    {
                        Text           = $"Bir hata oluştu",
                        ActionName     = "RecoverPassword",
                        ControllerName = "Account",
                        ErrorCode      = 500
                    };
                    return(RedirectToAction("Error", "Home"));
                }

                var emailService = new EmailService();
                var body         = $"Merhaba <b>{user.Ad} {user.Soyad}</b><br>Hesabınızın parolası sıfırlanmıştır<br> Yeni parolanız: <b>{newPassword}</b> <p>Yukarıdaki parolayı kullanarak sistemize giriş yapabilirsiniz.</p>";
                emailService.Send(new IdentityMessage()
                {
                    Body = body, Subject = $"{user.UserName} Şifre Kurtarma"
                }, user.Email);

                //TempData["Message"] = "Yeni E-Mail adresinize gönderilmiştir.";
            }


            catch (Exception ex)
            {
                TempData["Model"] = new ErrorViewModel()
                {
                    Text           = $"Bir hata oluştu {ex.Message}",
                    ActionName     = "RecoverPassword",
                    ControllerName = "Account",
                    ErrorCode      = 500
                };
                return(RedirectToAction("Error", "Home"));
            }


            return(View());
        }