public ClaimsIdentity CreateIdentity(VR_SITESModel user, string authenticationType) { ClaimsIdentity _identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie); _identity.AddClaim(new Claim(ClaimTypes.Name, user.USERID)); _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.LOCATION)); return(_identity); }
public int Add(VR_SITESModel vr_sites) { object obj = base.Add("InsertVR_SITES", vr_sites); if (obj != null) { return(Convert.ToInt32(obj)); } else { return(0); } }
/// <summary> /// Initialize /// </summary> /// <param name="requestContext"></param> protected override void Initialize(RequestContext requestContext) { base.Initialize(requestContext); // TODO //验证登录方法式1 //用户信息处理 /* * if (User.Identity.IsAuthenticated) * { * var user = User.Identity as FormsIdentity; * CurrentUser = new UserModel * { * Id = Convert.ToInt32(user.Ticket.UserData), * LoginName = User.Identity.Name * }; * } * * IsLogined = CurrentUser != null && CurrentUser.Id > 0; * * ViewRecord(requestContext); */ //验证登录方法式2 if (User.Identity.IsAuthenticated) { ClaimsIdentity claimsIdentity = HttpContext.User.Identity as ClaimsIdentity; if (claimsIdentity != null) { CurrentUser = new VR_SITESModel { USERID = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier).Value, //FULLNAME = claimsIdentity.FindFirst(ClaimTypes.Name).Value }; } } }
public int Update(VR_SITESModel vr_sites) { return(base.Update("UpdateVR_SITES", vr_sites)); }
public Result <VR_SITESModel> Login(VR_SITESModel dto) { var res = new Result <VR_SITESModel>(); try { var user = vr_sitesDao.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(VR_SITESModel vr_sites) { return(vr_sitesDao.Update(vr_sites)); }
public int Add(VR_SITESModel vr_sites) { return(vr_sitesDao.Add(vr_sites)); }