public ActionResult LogOn(string txtUserName, string txtPassword, string chkRememberMe, string returnUrl) { if (ModelState.IsValid) { if (chkRememberMe == null) { chkRememberMe = "false"; } else { chkRememberMe = "true"; } if (txtUserName.Trim() == "admin" && txtPassword.Trim() == "admin") { Helper.CurrentUserRole = "Admin"; string adminDetails = "0" + "^" + "Admin" + "^" + "Admin"; Helper.UserData = adminDetails; FormsAuthentication.SetAuthCookie(adminDetails, Convert.ToBoolean(chkRememberMe)); return(RedirectToAction("AdminLogin")); } else { Userdetail userdetail = objUserDetailBO.AuthenticateUser(txtUserName, txtPassword); if (userdetail != null) { //Helper.CurrentUserID = userdetail.PKUserId; string UserData = string.Empty; UserData = userdetail.PKUserId + "^" + userdetail.FirstName + "^" + "User"; Helper.UserData = UserData; FormsAuthentication.SetAuthCookie(UserData, Convert.ToBoolean(chkRememberMe)); return(RedirectToAction("UserLogin")); } else { ViewBag.message = "Invalid User Name or Password"; return(View()); } } } return(View()); }
/// <summary> /// This method is used for authenticating User details and returning user data in string format /// </summary> /// <remarks> /// DateCreated: 4th Nov 2016 /// Edited By: Phani (5-Nov-2016) /// </remarks> /// <exception cref="HttpResponseException">Will be thrown when there is a problem in Retrieving data of user or any exception occurs due to Helper Properties</exception> /// <param name="model">contains current user login details</param> /// <param name="request">contains currrent request message</param> /// <returns>user data</returns> // POST: api/AuthenticateAPI public HttpResponseMessage Post([FromBody]LoginModel model,HttpRequestMessage request) { try { //if login user is admin if (model.UserName.ToLower() == "admin" && model.Password.ToLower() == "admin") { string UserData = string.Empty; UserData = model.UserName.ToLower() + "^" + model.Password.ToLower(); FormsAuthentication.SetAuthCookie(UserData, Convert.ToBoolean(model.RememberMe)); return request.CreateResponse(HttpStatusCode.OK, UserData); } //if login user is not admin else { //retrieving userdetails based on username and password Userdetail userdetail = objUserDetailBO.AuthenticateUser(model.UserName, model.Password); if (userdetail != null) { //setting user details in helper properties string UserData = string.Empty; UserData = userdetail.PKUserId + "^" + userdetail.UserName + "^" + "User"; //creating auth cookie for login user FormsAuthentication.SetAuthCookie(UserData, Convert.ToBoolean(model.RememberMe)); return request.CreateResponse(HttpStatusCode.OK, UserData); } else return request.CreateResponse(HttpStatusCode.NoContent); } } catch (Exception ex) { var resp = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(ex.Message), ReasonPhrase = ex.Message }; throw new HttpResponseException(resp); } }