Exemplo n.º 1
0
 public ActionResult Login(AccountVm model, string returnUrl)
 {
     if (ModelState.IsValid)
     {
         if(_service.LoginUser(model))
         {
             if (Url.IsLocalUrl(returnUrl))
             {
                 return Redirect(returnUrl);
             }
             return RedirectToAction("Index", "Home");
         }
         ModelState.AddModelError("", "The user name or password provided is incorrect.");
     }
     return View(model);
 }
Exemplo n.º 2
0
        public bool LoginUser(AccountVm model)
        {
            if (!_membershipProvider.ValidateUser(model.Email, model.Password)) return false;
            var user = _unit.User.Get(u => u.Email == model.Email);

            user.ApproveState = user.Live == LiveStatuses.Deleted ? ApproveStates.NotApproved : user.ApproveState;

            _unit.User.Save(user);
            FormsAuthentication.SetAuthCookie(model.Email, true);
            return true;
        }
Exemplo n.º 3
0
        public void ResetPassword(AccountVm model)
        {
            var user = _unit.User.Load(u => u.Email == model.Email).FirstOrDefault();

            if (user == null)
            {
                throw new WarningException("Something went wrong, try again");
            }

            user.PasswordSalt = Ioc.Resolve<ISaltProvider>().GetSalt(SALT_LENGTH);
            user.PasswordHash = Ioc.Resolve<ICryptoProvider>().GetHashWithSalt(model.Password, user.PasswordSalt);
            user.PasswordRecovery.PasswordHash = "";
            user.PasswordRecovery.PasswordSalt = "";

            _unit.User.Save(user);
        }
Exemplo n.º 4
0
        public ActionResult PasswordRecovery(AccountVm model)
        {
            try
            {
                _service.PasswordRecovery(model.Email, Request.Url.AbsoluteUri);
            }
            catch (WarningException exception)
            {
                ModelState.Remove("Password");
                ModelState.AddModelError("", exception.Message);
                return View();
            }

            return View(model);
        }
Exemplo n.º 5
0
        public ActionResult PasswordReset(AccountVm model)
        {
            try
            {
                _service.ResetPassword(model);
                _service.LoginUser(model);
            }
            catch (WarningException exception)
            {
                ModelState.Remove("Password");
                ModelState.AddModelError("", exception.Message);
                return View("PasswordRecovery");
            }

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