/// <summary> /// Two factor verification step /// </summary> /// <param name="provider"></param> /// <param name="code"></param> /// <param name="isPersistent"></param> /// <param name="rememberBrowser"></param> /// <returns></returns> public virtual async Task <InspurSignInStatus> TwoFactorSignInAsync(string provider, string code, bool isPersistent, bool rememberBrowser) { var userId = await GetVerifiedUserIdAsync().WithCurrentCulture(); if (userId == null) { return(InspurSignInStatus.Failure); } var user = await InspurUserManager.FindByIdAsync(userId).WithCurrentCulture(); if (user == null) { return(InspurSignInStatus.Failure); } //if (await InspurUserManager.IsLockedOutAsync(user.Id).WithCurrentCulture()) //{ // return InspurSignInStatus.LockedOut; //} if (await InspurUserManager.VerifyTwoFactorTokenAsync(user.Id, provider, code).WithCurrentCulture()) { // When token is verified correctly, clear the access failed count used for lockout await InspurUserManager.ResetAccessFailedCountAsync(user.Id).WithCurrentCulture(); await SignInAsync(user, isPersistent, rememberBrowser).WithCurrentCulture(); return(InspurSignInStatus.Success); } // If the token is incorrect, record the failure which also may cause the user to be locked out await InspurUserManager.AccessFailedAsync(user.Id).WithCurrentCulture(); return(InspurSignInStatus.Failure); }
/// <summary> /// Sign in the user in using the user name and password /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="isPersistent"></param> /// <param name="shouldLockout"></param> /// <returns></returns> public virtual async Task <InspurSignInStatus> PasswordSignInAsync(string email, string password, bool isPersistent, bool shouldLockout) { if (InspurUserManager == null) { return(InspurSignInStatus.Failure); } //var user = await InspurUserManager.FindByNameAsync(userName).WithCurrentCulture(); //if (user == null) //{ //} var user = await InspurUserManager.FindByEmailAsync(email).WithCurrentCulture(); if (user == null) { return(InspurSignInStatus.Failure); } //if (await InspurUserManager.IsLockedOutAsync(user.Id).WithCurrentCulture()) //{ // return InspurSignInStatus.LockedOut; //} if (await InspurUserManager.CheckPasswordAsync(user, password).WithCurrentCulture()) { //await InspurUserManager.ResetAccessFailedCountAsync(user.Id).WithCurrentCulture(); return(await SignInOrTwoFactor(user, isPersistent).WithCurrentCulture()); } if (shouldLockout) { // If lockout is requested, increment access failed count which might lock out the user await InspurUserManager.AccessFailedAsync(user.Id).WithCurrentCulture(); //if (await InspurUserManager.IsLockedOutAsync(user.Id).WithCurrentCulture()) //{ // return InspurSignInStatus.LockedOut; //} } return(InspurSignInStatus.Failure); }