Beispiel #1
0
        public ActionResult Recover(RecoverViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // CHECK IF THE USERS EMAIL EXISTS IN DB
                    var usar = this.UnitOfWork.UserRepository.Get().Where(u => u.Email == model.Email);
                    if (usar.FirstOrDefault() == null)
                    {
                        var modl = new ReUzze.Models.RecoverViewModel
                        {
                            StatusMessage = "E-mail adres not found in database."
                        };

                        return View(modl);
                    }

                    App.Models.User usr = this.UnitOfWork.UserRepository.Get().Where(u => u.Email == model.Email).FirstOrDefault();
                    var password = BCrypt.Net.BCrypt.HashPassword(usr.Password, usr.PasswordSalt);

                    // SETTINGS NEED TO BE ADJUSTED TO THE SERVER
                    MailMessage mail = new MailMessage();
                    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                    mail.From = new MailAddress("*****@*****.**");
                    mail.To.Add(model.Email);
                    mail.Subject = "Password recovery - ReUzze";
                    mail.Body = "Hi, Your password is: " + password;

                    SmtpServer.Send(mail);

                    return RedirectToAction("Index", "Home");
                }
                catch (ArgumentException ae)
                {
                    ModelState.AddModelError("", ae.Message);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Beispiel #2
0
 public ActionResult Recover()
 {
     var model = new RecoverViewModel();
     return View(model);
 }