Ejemplo n.º 1
0
        public IActionResult ProcessForgotUsername(ForgotCredentialsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("ForgotUsername"));
            }

            var user = _db.Users.FirstOrDefault(u => u.Email == model.Email);


            if (user == null)
            {
                ModelState.AddModelError("Email", "That Email doesn't exist");
                return(View("ForgotUsername"));
            }

            const string from     = "*****@*****.**";
            const string fromName = "RecipeList";
            const string subject  = "RecipeList Username Recovery";
            var          body     = "Hello " + user.DisplayName + ",<br/><br/>The username associated with this email is: <b>" +
                                    user.Username + "</b>";

            _emailSender.SendEmail(user.Email, user.Username, from, fromName, subject, body, true);
            return(RedirectToAction("CheckEmail"));
        }
Ejemplo n.º 2
0
        public IActionResult ProcessForgotPassword(ForgotCredentialsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("ForgotPassword"));
            }

            var user = _db.Users.FirstOrDefault(u => u.Email == model.Email);

            if (user == null)
            {
                ModelState.AddModelError("Email", "That Email doesn't exist");
                return(View("ForgotPassword"));
            }

            const string from             = "*****@*****.**";
            const string fromName         = "RecipeList";
            const string subject          = "RecipeList Password Recovery";
            var          linkId           = Guid.NewGuid();
            var          uniqueIdentifier = new UniqueIdentifiers
            {
                UserId     = user.Id,
                UniqueId   = linkId,
                IsVerified = false
            };

            _db.UniqueIdentifiers.Add(uniqueIdentifier);
            _db.SaveChanges();

            var body = "Hello " + user.DisplayName +
                       ",<br/><br/>Click this <a href='https://myrecipelist.azurewebsites.net/account/recovery/" +
                       user.Id + "/" +
                       linkId + "'>link</a> to reset your password.";

            _emailSender.SendEmail(user.Email, user.Username, from, fromName, subject, body, true);
            return(RedirectToAction("CheckEmail"));
        }