forked from yangzhongke/NETBookMaterials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a1e6e7
commit 1ba7c6f
Showing
15 changed files
with
442 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
最后大项目代码/YouZack-VNext/FileService.WebAPI/Uploader/UploadRequestValidator.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
最后大项目代码/YouZack-VNext/IdentityService.Domain/IdDomainService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using IdentityService.Domain; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.Extensions.Options; | ||
using System.Security.Claims; | ||
using Zack.JWT; | ||
|
||
namespace IdentityService.Infrastructure | ||
{ | ||
public class IdDomainService | ||
{ | ||
private readonly IIdRepository repository; | ||
private readonly ITokenService tokenService; | ||
private readonly IOptions<JWTOptions> optJWT; | ||
|
||
public IdDomainService(IIdRepository repository, | ||
ITokenService tokenService,IOptions<JWTOptions> optJWT) | ||
{ | ||
this.repository = repository; | ||
this.tokenService = tokenService; | ||
this.optJWT = optJWT; | ||
} | ||
|
||
public async Task<SignInResult> CheckUserNameAndPwdAsync(string userName, string password) | ||
{ | ||
var user = await repository.FindByNameAsync(userName); | ||
if (user == null) | ||
{ | ||
return SignInResult.Failed; | ||
} | ||
//CheckPasswordSignInAsync会对于多次重复失败进行账号禁用 | ||
var result = await repository.CheckForSignInAsync(user, password, true); | ||
return result; | ||
} | ||
public async Task<SignInResult> CheckPhoneNumAndPwdAsync(string phoneNum, string password) | ||
{ | ||
var user = await repository.FindByPhoneNumberAsync(phoneNum); | ||
if (user == null) | ||
{ | ||
return SignInResult.Failed; | ||
} | ||
var result = await repository.CheckForSignInAsync(user, password, true); | ||
return result; | ||
} | ||
|
||
public async Task<(SignInResult Result, string? Token)> LoginByPhoneAndPwdAsync(string phoneNum, string password) | ||
{ | ||
var checkResult = await CheckPhoneNumAndPwdAsync(phoneNum, password); | ||
if (checkResult.Succeeded) | ||
{ | ||
var user = await repository.FindByPhoneNumberAsync(phoneNum); | ||
string token = await BuildTokenAsync(user); | ||
return (SignInResult.Success,token); | ||
} | ||
else | ||
{ | ||
return (checkResult, null); | ||
} | ||
} | ||
|
||
public async Task<(SignInResult Result, string? Token)> LoginByUserNameAndPwdAsync(string userName, string password) | ||
{ | ||
var checkResult = await CheckUserNameAndPwdAsync(userName, password); | ||
if (checkResult.Succeeded) | ||
{ | ||
var user = await repository.FindByNameAsync(userName); | ||
string token = await BuildTokenAsync(user); | ||
return (SignInResult.Success, token); | ||
} | ||
else | ||
{ | ||
return (checkResult, null); | ||
} | ||
} | ||
|
||
private async Task<string> BuildTokenAsync(User user) | ||
{ | ||
var roles = await repository.GetRolesAsync(user); | ||
List<Claim> claims = new List<Claim>(); | ||
claims.Add(new Claim(ClaimTypes.NameIdentifier, user.Id.ToString())); | ||
foreach (string role in roles) | ||
{ | ||
claims.Add(new Claim(ClaimTypes.Role, role)); | ||
} | ||
return tokenService.BuildToken(claims, optJWT.Value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.