public void SignIn(Core.Domain.Common.Users user, bool createPersistentCookie) { var applicationIdentity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie); applicationIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Name)); applicationIdentity.AddClaim(new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity")); // Cookie var authProerties = new AuthenticationProperties { IsPersistent = createPersistentCookie }; if (authProerties.IsPersistent) { var currentUtc = new SystemClock().UtcNow; authProerties.IssuedUtc = currentUtc; authProerties.ExpiresUtc = currentUtc.Add(TimeSpan.FromDays(30)); } _authenticationManager.SignIn(authProerties, applicationIdentity); _cachedUser = user; }
/// <summary> /// 判断用户是否有登录权限 /// </summary> /// <param name="userCode">用户名</param> /// <param name="password">密码</param> /// <returns></returns> public UserLoginResult Validate(string userCode, string password, bool isEncryptedPassword = false) { Core.Domain.Common.Users user = _userService.GetByCode(userCode); if (user == null) { return(UserLoginResult.UserNotExist); } string encryptedPassword = password; if (!isEncryptedPassword) { encryptedPassword = EncryptionService.EncryptCRSPassword(password); } if (user.Password.Equals(encryptedPassword) == false) { return(UserLoginResult.WrongPassword); } return(UserLoginResult.Successful); }
public Core.Domain.Common.Users GetAuthenticatedUser() { if (_cachedUser != null) { return(_cachedUser); } if (!(_authenticationManager?.User.Identity is ClaimsIdentity)) { return(null); } var formsIdentity = (ClaimsIdentity)_authenticationManager.User.Identity; Core.Domain.Common.Users user = GetAuthenticatedUserFromClaims(formsIdentity); if (user != null) { _cachedUser = user; } return(_cachedUser); }
public void SignOut() { _cachedUser = null; _authenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); }