예제 #1
0
        /// <summary>
        /// 密码登录
        /// </summary>
        private async Task <SignInResult> PasswordSignIn(TUser user, string password, bool isPersistent = false, bool lockoutOnFailure = true, string applicationCode = "")
        {
            await AddClaimsToUser(user, applicationCode);

            var signInResult = await IdentitySignInManager.PasswordSignInAsync(user, password, isPersistent, lockoutOnFailure);

            if (signInResult.IsNotAllowed)
            {
                throw new Warning(SecurityResource.UserIsDisabled);
            }
            if (signInResult.IsLockedOut)
            {
                throw new Warning(SecurityResource.LoginFailLock);
            }
            if (signInResult.Succeeded)
            {
                return(new SignInResult(SignInState.Succeeded, user.Id.SafeString()));
            }
            if (signInResult.RequiresTwoFactor)
            {
                return(new SignInResult(SignInState.TwoFactor, user.Id.SafeString()));
            }
            return(new SignInResult(SignInState.Failed, string.Empty));
        }
예제 #2
0
 /// <summary>
 /// 退出登录
 /// </summary>
 public async Task SignOutAsync()
 {
     await IdentitySignInManager.SignOutAsync();
 }
예제 #3
0
 /// <summary>
 /// 初始化登录服务
 /// </summary>
 /// <param name="signInManager">Identity登录服务</param>
 /// <param name="userManager">用户服务</param>
 public SignInManager(IdentitySignInManager <TUser, TKey> signInManager, IUserManager <TUser, TKey> userManager)
 {
     IdentitySignInManager = signInManager;
     UserManager           = userManager;
 }