Example #1
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserMgr.FindByEmailAsync(model.Email);

                if (user != null && await UserMgr.IsEmailConfirmedAsync(user))
                {
                    var token = await UserMgr.GeneratePasswordResetTokenAsync(user);

                    var passwordResetLink = Url.Action("ResetPassword", "Account",
                                                       new { email = model.Email, token = token }, Request.Scheme);

                    logger.Log(LogLevel.Warning, passwordResetLink);

                    return(View("ForgotPasswordConfirmation"));
                }

                Console.WriteLine("Eu não entrei no if");


                return(View("ForgotPasswordConfirmation"));
            }

            return(View(model));
        }
Example #2
0
        public async Task <IActionResult> Forgot(string email)
        {
            Console.WriteLine(email);
            var user = await UserMgr.FindByEmailAsync(email);

            var todoEmail = Environment.GetEnvironmentVariable("TODOLIST_EMAIL");
            var password  = Environment.GetEnvironmentVariable("TODOLIST_EMAIL_PASSWORD");
            var route     = Request.Host.Value;

            if (user != null)
            {
                var token = await UserMgr.GeneratePasswordResetTokenAsync(user);

                var message = new MimeMessage();
                message.From.Add(new MailboxAddress("Password Recovery - Mike's Todolist", todoEmail));
                message.To.Add(MailboxAddress.Parse(email));
                message.Subject = "Password Recovery - Mike's Todolist";
                message.Body    = new TextPart("plain")
                {
                    Text = "https://" + route + "/Recover/" + email + "/" + HttpUtility.UrlEncode(token)
                };

                using (var client = new SmtpClient())
                {
                    client.Connect("smtp.gmail.com", 587, false);
                    client.Authenticate(todoEmail, password);
                    client.Send(message);
                    client.Disconnect(true);
                }
                return(Ok(true));
            }
            return(BadRequest("Wrong email"));
        }
Example #3
0
        public async Task <IActionResult> ForgotPassword(ForgotPassword model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserMgr.FindByEmailAsync(model.Email);

                if (user != null)
                {
                    token = await UserMgr.GeneratePasswordResetTokenAsync(user);

                    passwordResetLink = Url.Action("ResetPassword", "UserWithAuthentication",
                                                   new { token, email = model.Email }, Request.Scheme);

                    SendResetPasswordLink(passwordResetLink, model.Email);

                    return(View("ForgotPasswordConfirmation"));
                }
                return(View("ForgotPasswordConfirmation"));
            }

            return(View(model));
        }