Esempio n. 1
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="password">密码</param>
        /// <param name="isPersistent">cookie是否持久保留,设置为false,当关闭浏览器则cookie失效</param>
        /// <param name="lockoutOnFailure">达到登录失败次数是否锁定</param>
        public async Task <SignInResult> SignInAsync(User user, string password, bool isPersistent, bool lockoutOnFailure)
        {
            if (user == null)
            {
                return(new SignInResult(SignInState.Failed, null, GreatWallResource.InvalidAccountOrPassword));
            }
            var signInResult = await IdentitySignInManager.PasswordSignInAsync(user, password, isPersistent, lockoutOnFailure);

            return(GetSignInResult(user, signInResult));
        }
Esempio n. 2
0
        /// <summary>
        /// 令牌登录
        /// </summary>
        /// <param name="phone">手机号</param>
        /// <param name="token">令牌</param>
        /// <param name="isPersistent">cookie是否持久保留,设置为false,当关闭浏览器则cookie失效</param>
        /// <param name="lockoutOnFailure">达到登录失败次数是否锁定</param>
        /// <param name="application">应用程序</param>
        public async Task <SignInResult> TokenSignInAsync(string phone, string token, bool isPersistent, bool lockoutOnFailure, string application = "")
        {
            var user = await UserManager.FindByPhoneAsync(phone);

            if (user == null)
            {
                return(new SignInResult(SignInState.Failed, null, GreatWallResource.InvalidAccountOrPassword));
            }
            var success = await UserManager.VerifyTokenAsync(user, TokenPurpose.SignIn, token, application);

            var signInResult = await IdentitySignInManager.TokenSignInAsync(user, success, isPersistent, lockoutOnFailure);

            return(GetSignInResult(user, signInResult));
        }
Esempio n. 3
0
        /// <summary>
        /// 密码登录
        /// </summary>
        private async Task <SignInResult> PasswordSignIn(User user, string password, bool isPersistent, bool lockoutOnFailure)
        {
            var signInResult = await IdentitySignInManager.PasswordSignInAsync(user, password, isPersistent, lockoutOnFailure);

            if (signInResult.IsNotAllowed)
            {
                return(new SignInResult(SignInState.Failed, null, GreatWallResource.UserIsDisabled));
            }
            if (signInResult.IsLockedOut)
            {
                return(new SignInResult(SignInState.Failed, null, GreatWallResource.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, null, GreatWallResource.InvalidAccountOrPassword));
        }
Esempio n. 4
0
 /// <summary>
 /// 退出登录
 /// </summary>
 public async Task SignOutAsync()
 {
     await IdentitySignInManager.SignOutAsync();
 }
Esempio n. 5
0
 /// <summary>
 /// 初始化登录服务
 /// </summary>
 /// <param name="signInManager">Identity登录服务</param>
 /// <param name="userManager">用户服务</param>
 public SignInManager(IdentitySignInManager signInManager, IUserManager userManager)
 {
     IdentitySignInManager = signInManager;
     UserManager           = userManager;
 }