private bool IsValid(string email, string password) { var user = _userService.Login(new LoginUserRequest { Email = email, Password = password }); if (user != null && user.IsSuccess) { /* Try Get Current User Role */ //this._createRole(user.RoleName); //this._userAddToRole(user.Username, user.RoleName); var roleName = new List<KeyValuePair<int, string>>(); //roleName = user.RolePrivileges.ToDictionary(x => x.Id); if (user.RolePrivileges != null && user.RolePrivileges.Count() > 0) { foreach (var role in user.RolePrivileges) { //this._userAddToRole(user.Username, role.Name); roleName.Add(new KeyValuePair<int, string>(role.Id, role.Name)); } } var profileData = new UserProfileSessionData { UserId = user.Id, Email = user.Email, Name = user.Username, RoleId = user.RoleId, RoleName = user.RoleName, RedirectUrl = user.ChangeModel, IsSuperAdmin = user.IsSuperAdmin, RolePrivilegeName = roleName }; this.Session["LoginUser"] = profileData; //var authTicket = new FormsAuthenticationTicket( // version:1, // name : user.Username, // issueDate : DateTime.Now, // expiration: DateTime.Now.AddMinutes(30), // isPersistent : false, // userData : string.Join("|",roles) // ); //string encryptedTicket = FormsAuthentication.Encrypt(authTicket); //HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); //System.Web.HttpContext.Current.Response.Cookies.Add(authCookie); FormsAuthentication.SetAuthCookie(user.Username, false); return user.IsSuccess; } return false; }
private bool IsValid(string email, string password) { var user = _userService.Login(new LoginUserRequest { Email = email, Password = password }); if (user != null) { /* Try Get Current User Role */ //this._createRole(user.RoleName); //this._userAddToRole(user.Username, user.RoleName); var profileData = new UserProfileSessionData { UserId = user.Id, Email = user.Email, Name = user.Username, RoleId = user.RoleId, RoleName = user.RoleName, RedirectUrl = user.ChangeModel, IsSuperAdmin = user.IsSuperAdmin }; this.Session["LoginUser"] = profileData; FormsAuthentication.SetAuthCookie(user.Username, false); return user.IsSuccess; } return false; }