public ActionResult RenderLogin() { SimpilyLoginViewModel login = new SimpilyLoginViewModel(); LogHelper.Info <SimpilyAuthSurfaceController>("Login URL: {0}", () => HttpContext.Request.Url.AbsolutePath); login.ReturnUrl = HttpContext.Request.Url.ToString(); if (HttpContext.Request.Url.AbsolutePath == SimpilyAuth.LoginUrl) { login.ReturnUrl = "/"; } return(PartialView(SimpilyAuth.LoginView, login)); }
public ActionResult HandleLogin(SimpilyLoginViewModel model) { if (!ModelState.IsValid) { return(CurrentUmbracoPage()); } var membershipHelper = new MembershipHelper(UmbracoContext.Current); if (membershipHelper.IsLoggedIn()) { return(RedirectToRoute(model.ReturnUrl)); } // login in the user try { if (membershipHelper.Login(model.EmailAddress, model.Password)) { // logged in var member = membershipHelper.GetByEmail(model.EmailAddress); if (member != null) { if (member.GetPropertyValue <bool>(SimpilyAuth.AccountVerifiedProperty, false, false)) { // a valid and verified user here be! TempData["returnUrl"] = model.ReturnUrl; return(RedirectToCurrentUmbracoPage()); } else { // we need to validate this account before they can logon. ModelState.AddModelError(SimpilyAuth.LoginKey, GetDictionaryOrDefault("SimpleAuth.Login.NotVerified", "Email has not been verified")); membershipHelper.Logout(); return(CurrentUmbracoPage()); // return PartialView(SimpleAuth.LoginView, model); } } else { // can't find the user...? ModelState.AddModelError(SimpilyAuth.LoginKey, GetDictionaryOrDefault("SimpleAuth.Login.NoUser", "Invalid Details")); } } else { // can't login this person... ModelState.AddModelError(SimpilyAuth.LoginKey, GetDictionaryOrDefault("SimpleAuth.Login.LoginFail", "Invalid Details")); } } catch (Exception ex) { // somethig big time went boom... ModelState.AddModelError(SimpilyAuth.LoginKey, "Error logging on" + ex.ToString()); } return(CurrentUmbracoPage()); }