public async Task <ActionResult> Login(ICMS.Lite.Repository.ViewModels.AccountViewModel.LoginViewModel model) { ViewBag.Response = null; if (!ModelState.IsValid) { return(View(model)); } try { var isValid = await _accountService.AUTHENTICATEUSER(model); if (!isValid) { ViewBag.Response = "Invalid username or password"; return(View(model)); } await this.LoginAuthenticationTicketInitializer(model); var returnUrl = string.Empty; if (string.IsNullOrEmpty(returnUrl)) { var authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie == null) { ViewBag.Response = "Unable to determine your role. Contact your administrator"; } //ModelState.AddModelError("", "Unable to determine your role. Contact your administrator"); else { //Extract the forms authentication cookie FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); //If caching roles in userData field then extract var role = authTicket.UserData; var roleName = authTicket.UserData; //Todo::Get menu for the user role //if (string.IsNullOrEmpty(roleName)) //{ // ModelState.AddModelError("", "Invalid login attempt."); // return View(model); //} return(RedirectToAction("Index", new { Controller = "Indents", action = "Index" })); } } } catch (Exception ex) { var error = await ExceptionRefiner.LogError(ex); ViewBag.Response = error; return(View(model)); } return(View(model)); }