public JsonResult JsonExternalLogin(LoginModel model, string ReturnUrl) { if (ModelState.IsValid) { //Step 1: Get data from Sp and check it AccountBL Ab = new AccountBL(); ContactDetails cd = new ContactDetails(); cd = Ab.CheckLogin(model.UserName, model.Password); if (cd.CustomerID > 0) { //cd.CustomerID = 0; FormsAuthentication.SetAuthCookie(model.UserName, false); SiteSession siteSession = new SiteSession(cd); SessionHelper.UserSession = siteSession; UrlHelper u = new UrlHelper(HttpContext.Request.RequestContext); string url = string.Empty; if (SessionHelper.UserSession.RoleID == UserRole.SuperAdmin || SessionHelper.UserSession.RoleID == UserRole.Admin|| SessionHelper.UserSession.RoleID == UserRole.Staff) url = u.Action("Index", "Search", null); else url = u.Action("Index", "SetupCustomer", null); return Json(new { success = true, redirect = string.IsNullOrEmpty(ReturnUrl) ? url : ReturnUrl }); } else { ModelState.AddModelError("", "Please provide valid User Name/Password."); } } return Json(new { errors = KeyValue.GetErrorsFromModelState(ViewData) }); }
/// <summary> /// Initializes a new instance of the SiteSession class. /// </summary> /// <param name="db">The data context.</param> /// <param name="user">The current user.</param> public SiteSession(ContactDetails user) { this.CustomerID = user.CustomerID; //this.Username = user.EmailID; // this.UserRole = user.RoleID; this.Name = user.Name; //this.IsAdmin = user.IsAdmin; this.RoleID = user.RoleID; //this.Mobile = user.MobileNo; //this.UserRole = (UserRoles)user.RoleID; // // TO DO: Cache other user settings! // }
public ContactDetails CheckLogin(string emailaddress, string password) { int errorNum = 0; string errorDesc = ""; DataAccess.resetParams(); DataAccess.addSqlParam("@EmailAddress", ParameterDirection.Input, 50, MySqlDbType.VarChar, emailaddress); DataAccess.addSqlParam("@Password", ParameterDirection.Input, 50, MySqlDbType.VarChar, password); DataAccess.addSqlParam("@CustomerID", ParameterDirection.InputOutput, 16, MySqlDbType.Int32); DataSet ds = DataAccess.ExecuteDataSet(GET_CHECK_LOGIN, ref errorNum, ref errorDesc); ContactDetails cd = new ContactDetails(); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { cd.CustomerID = Common.ConvertToInt(ds.Tables[0].Rows[0], "CustomerID"); cd.Name = Common.ConvertToString(ds.Tables[0].Rows[0], "CustomerName"); cd.IsAdmin = Common.ConvertToInt(ds.Tables[0].Rows[0], "IsAdmin") == 1 ? true: false; cd.RoleID = Common.ConvertToInt(ds.Tables[0].Rows[0], "RoleID"); } return cd; }