public ClaimsIdentity CreateIdentity(TUSERModel user, string authenticationType) { ClaimsIdentity _identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie); _identity.AddClaim(new Claim(ClaimTypes.Name, user.FULLNAME)); _identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.USERID)); _identity.AddClaim(new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity")); _identity.AddClaim(new Claim("DisplayName", user.DESCRIPTION)); return(_identity); }
public int Add(TUSERModel tuser) { object obj = base.Add("InsertTUSER", tuser); if (obj != null) { return(Convert.ToInt32(obj)); } else { return(0); } }
public int Update(TUSERModel tuser) { return(base.Update("UpdateTUSER", tuser)); }
public Result <TUSERModel> Login(TUSERModel dto) { var res = new Result <TUSERModel>(); try { var user = tuserDao.GetOne(dto.USERID); if (user == null) { res.msg = "无效的用户"; } else { //记录登录日志 /* * loginLogDao.Add(new LoginLog * { * UserId = user.Id, * LoginName = user.LoginName, * IP = WebHelper.GetClientIP(), * Mac = WebHelper.GetClientMACAddress() * });*/ if (user.PASSID != dto.PASSID) { res.msg = "登录密码错误"; } else { res.flag = true; res.msg = "登录成功"; res.data = user; //写入注册信息 DateTime expiration = true ? DateTime.Now.AddDays(7) : DateTime.Now.Add(FormsAuthentication.Timeout); /* * FormsAuthentication.SetAuthCookie(user.LoginName, true, FormsAuthentication.FormsCookiePath); * * FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(2, * user.LoginName, * DateTime.Now, * expiration, * true, * user.Id.ToString(), * FormsAuthentication.FormsCookiePath); * FormsIdentity identity = new FormsIdentity(ticket); * * HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, * FormsAuthentication.Encrypt(ticket)) * { * HttpOnly = true, * Expires = expiration * }; * HttpContext.Current.Response.Cookies.Add(cookie); */ //方法一: from模式记录用户登录 //Visitor.Reg.Core.TicketTool.SetCookie(user.LoginName, user.Id.ToString(), expiration); //方法二: ClaimsIdentity 记录用户登 录 var _identity = CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = true }, _identity); } } } catch (Exception ex) { res.msg = ex.Message; } return(res); }
public int Update(TUSERModel tuser) { return(tuserDao.Update(tuser)); }
public int Add(TUSERModel tuser) { return(tuserDao.Add(tuser)); }