public ActionResult Login() { if (HttpContext.User.Identity.IsAuthenticated) { return RedirectToAction("Home", "Account"); } ViewBag.Active = "Login"; LoginAndAccountVM LoginAndAccountModel = new LoginAndAccountVM(); return View(LoginAndAccountModel); }
public ActionResult Login(LoginAndAccountVM Account) { ViewBag.Active = "Login"; if (ModelState.IsValidField("LoginModel.Email") && ModelState.IsValidField("LoginModel.Password")) { try { var loginAccount = _DAOFactory.AccountDAO.getByEmail(Account.LoginModel.Email); if (loginAccount != null && loginAccount.password == Account.LoginModel.Password) { FormsAuthentication.SetAuthCookie(loginAccount.email, Account.RememberMe); return RedirectToAction("Home", "Account"); } ModelState.AddModelError("LogError", "The user name or password provided is incorrect."); } catch (Exception ex) { ModelState.AddModelError("LogError", ex.Message); } } return View(Account); }
public ActionResult Register(LoginAndAccountVM Account, string returnUrl) { ViewBag.Active = "Register"; if (ModelState.IsValidField("RegisterModel.Email") && ModelState.IsValidField("RegisterModel.Password")) { account register = Account.RegisterModel; register.role = "User"; try { var loginAccount = _DAOFactory.AccountDAO.getByEmail(Account.RegisterModel.email); if (loginAccount == null) { _DAOFactory.AccountDAO.create(Account.RegisterModel); ViewBag.Active = "Login"; Account.LoginModel = new Login(); Account.LoginModel.Email = Account.RegisterModel.email; ViewBag.Reg = "registered"; } else { ModelState.AddModelError("RegError", "Email has already been taken"); } } catch (Exception ex) { ModelState.AddModelError("RegError", ex.Message); } } return View("Login", Account); }