Ejemplo n.º 1
0
        /// <summary>
        /// 密码登录
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="password">密码</param>
        ///  <param name="isPersistent">cookie是否持久保留,设置为false,当关闭浏览器则cookie失效</param>
        /// <param name="lockoutOnFailure">达到登录失败次数是否锁定</param>
        /// <param name="applicationCode">应用程序编码</param>
        /// <returns></returns>
        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(SecurityResources.UserIsDisabled);
            }
            if (signInResult.IsLockedOut)
            {
                throw new Warning(SecurityResources.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));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 初始化一个<see cref="SignInManager{TUser,TKey}"/>类型的实例
 /// </summary>
 /// <param name="identitySignInManager">Identity登录服务</param>
 /// <param name="userManager">用户服务</param>
 public SignInManager(IdentitySignInManager <TUser, TKey> identitySignInManager,
                      IUserManager <TUser, TKey> userManager)
 {
     IdentitySignInManager = identitySignInManager;
     UserManager           = userManager;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 退出登录
 /// </summary>
 /// <returns></returns>
 public async Task SignOutAsync()
 {
     await IdentitySignInManager.SignOutAsync();
 }