예제 #1
0
        public async Task SendRestorePasswordEmailAsync(RestorePasswordMessage model)
        {
            var template = new RestorePassword();

            template.ConfirmationCode = model.Token;

            var text = template.TransformText();

            var message = new SendGridMessage();

            message.To      = new[] { new MailAddress(model.Email, model.FullName) };
            message.Subject = $"Восстановление пароля на AZUREday {Configuration.Year}";
            message.Html    = text;
            message.From    = new MailAddress(Configuration.SendGridFromEmail, Configuration.SendGridFromName);
            message.ReplyTo = new[] { new MailAddress(Configuration.SendGridFromEmail, Configuration.SendGridFromName) };

            await SendEmail(message);
        }
예제 #2
0
        public async Task <IActionResult> RestorePassword([FromBody] RestorePassword command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var user = await _userService.GetActiveByEmailAsync(command.Email);

            if (user == null)
            {
                return(Ok(new { message = "The message of password restoring has been sent to given email address" }));
            }
            try {
                await _userService.RestorePasswordAsync(user);

                return(Ok(new { message = "The message of password restoring has been sent to given email address" }));
            } catch (Exception e) {
                return(BadRequest(new { errorMessage = e.Message }));
            }
        }
예제 #3
0
        public ActionResult ForgotPassword(RestorePassword model)
        {
            try
            {
                //have only email
                if (string.IsNullOrEmpty(model.Token))
                {
                    string token = UserService.CreateRestoreToken(model.Email);

                    MessageService.SendEmail <string>(model.Email, "Change password", "PasswordRestoreRequest",
                                                      new EmailDTO <string>
                    {
                        Model = token, User = UserService.GetUser(model.Email)
                    });
                    this.SetTempMessage("Please check your email for next instructions", "success");

                    return(RedirectToAction("Index", "Home"));
                }

                model.IsValidToken = UserService.IsPasswordRestoreTokenValid(model.Email, model.Token);
                if (!model.IsValidToken)
                {
                    this.SetTempMessage("Invalid token", "error");
                    return(RedirectToAction("Index", "Home"));
                }

                //update password here
                UserService.UpdateUserPassword(model.Email, model.NewPassword);
                this.SetTempMessage("You have changed your password", "success");
                return(RedirectToAction("Index", "Home"));
            }

            catch (ServiceException ex)
            {
                this.SetTempMessage(ex.Message, ex.Level);
            }
            return(View(model));
        }
예제 #4
0
        public ActionResult ForgotPassword(string email = "", string token = "")
        {
            var vm = new RestorePassword {
                Email = email
            };

            if (email == "")
            {
                return(View(vm));
            }

            //try
            //{
            vm.IsValidToken = UserService.IsPasswordRestoreTokenValid(email, token);
            //}
            //catch (ServiceException ex)
            //{
            //    this.SetTempMessage(ex.Message, "Error");
            //}

            //show form for update password here or to get token
            return(View(vm));
        }