public CustomLoginViewModel GetUserLoginDetails(CustomLoginViewModel user) { CustomLoginViewModel userRecord = null; try { userRecord = (from userDetail in db.EventUsers join role in db.Roles on userDetail.RoleId equals role.RoleId where (userDetail.EmailAddress == user.EmailAddress && userDetail.PasswordHash == user.Password) select new CustomLoginViewModel { UserId = userDetail.UserId, EmailAddress = userDetail.EmailAddress, Password = userDetail.PasswordHash, Roles = role.RoleName, RoleId = role.RoleId, UserLastname = userDetail.UserLastName, UserFirstname = userDetail.UserFirstName, IsActivated = userDetail.IsActivated, }).FirstOrDefault(); } catch (Exception ex) { //log.Error(ex.Message); throw ex; } return(userRecord); }
public ActionResult Login(CustomLoginViewModel LoginModel) { return(View("LoginResult", LoginModel)); }
public ActionResult Login(LoginViewModel model, string returnUrl) { try { string decodedUrl = ""; if (!string.IsNullOrEmpty(returnUrl)) { decodedUrl = Server.UrlDecode(returnUrl); } if (!ModelState.IsValid) { return(View(model)); } var getPwdState = repository.Verify(model.Email, model.Password);//customRepository.CheckPassword(model.Password, model.Email); if (getPwdState) { var getHashedPwd = repository.SelectPasswordOnSuccessfulPasswordValidation(model.Email); var user = new CustomLoginViewModel() { EmailAddress = model.Email, Password = getHashedPwd }; user = repository.GetUserLoginDetails(user); if (user != null) { FormsAuthentication.SetAuthCookie(model.Email, false); var authTicket = new FormsAuthenticationTicket(1, user.EmailAddress, DateTime.Now, DateTime.Now.AddMinutes(20), false, user.Roles); string encryptedTicket = FormsAuthentication.Encrypt(authTicket); var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); HttpContext.Response.Cookies.Add(authCookie); if (Url.IsLocalUrl(decodedUrl)) { return(Redirect(decodedUrl)); } else { // Successful login by admin/event user return(RedirectToAction("dashboard", "admin")); } } else { ViewBag.DisplayMessage = "Info"; ModelState.AddModelError("", "Invalid username or password."); return(View(model)); } } else { ViewBag.DisplayMessage = "Info"; ModelState.AddModelError("", "Invalid username or password."); return(View(model)); } } catch (Exception ex) { ViewBag.DisplayMessage = "Info"; ModelState.AddModelError("", "Invalid username or password."); return(View(model)); } }