diff options
author | 杨宇千 <crupest@outlook.com> | 2019-07-29 21:07:46 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-07-29 21:07:46 +0800 |
commit | e1d438454869bce7c086bbe6ba98ca8c5aa74ecd (patch) | |
tree | 1831dc93bcea72b38a914166b4df50226877e9d3 | |
parent | 246e4eafeb10a26e049d1905c9721c1fb1181aed (diff) | |
download | timeline-e1d438454869bce7c086bbe6ba98ca8c5aa74ecd.tar.gz timeline-e1d438454869bce7c086bbe6ba98ca8c5aa74ecd.tar.bz2 timeline-e1d438454869bce7c086bbe6ba98ca8c5aa74ecd.zip |
Rename isAdmin to administrator.
-rw-r--r-- | Timeline.Tests/Helpers/UserInfoComparers.cs | 6 | ||||
-rw-r--r-- | Timeline.Tests/JwtTokenUnitTest.cs | 2 | ||||
-rw-r--r-- | Timeline/Authenticate/AuthHandler.cs | 2 | ||||
-rw-r--r-- | Timeline/Controllers/UserController.cs | 4 | ||||
-rw-r--r-- | Timeline/Entities/Http/User.cs | 4 | ||||
-rw-r--r-- | Timeline/Entities/UserInfo.cs | 8 | ||||
-rw-r--r-- | Timeline/Entities/UserUtility.cs | 2 | ||||
-rw-r--r-- | Timeline/Services/UserService.cs | 24 |
8 files changed, 26 insertions, 26 deletions
diff --git a/Timeline.Tests/Helpers/UserInfoComparers.cs b/Timeline.Tests/Helpers/UserInfoComparers.cs index d88b6622..0d91efe3 100644 --- a/Timeline.Tests/Helpers/UserInfoComparers.cs +++ b/Timeline.Tests/Helpers/UserInfoComparers.cs @@ -20,7 +20,7 @@ namespace Timeline.Tests.Helpers int IEqualityComparer<UserInfo>.GetHashCode(UserInfo obj) { - return obj.Username.GetHashCode() ^ obj.IsAdmin.GetHashCode(); + return obj.Username.GetHashCode() ^ obj.Administrator.GetHashCode(); } } @@ -40,10 +40,10 @@ namespace Timeline.Tests.Helpers if (uc != 0) return uc; - if (left.IsAdmin == right.IsAdmin) + if (left.Administrator == right.Administrator) return 0; - return left.IsAdmin ? -1 : 1; + return left.Administrator ? -1 : 1; } } } diff --git a/Timeline.Tests/JwtTokenUnitTest.cs b/Timeline.Tests/JwtTokenUnitTest.cs index 6ab4e8a6..6c0d4213 100644 --- a/Timeline.Tests/JwtTokenUnitTest.cs +++ b/Timeline.Tests/JwtTokenUnitTest.cs @@ -68,7 +68,7 @@ namespace Timeline.Tests var result = JsonConvert.DeserializeObject<VerifyTokenResponse>(await response.Content.ReadAsStringAsync()); Assert.NotNull(result.User); Assert.Equal(createTokenResult.User.Username, result.User.Username); - Assert.Equal(createTokenResult.User.IsAdmin, result.User.IsAdmin); + Assert.Equal(createTokenResult.User.Administrator, result.User.Administrator); } } } diff --git a/Timeline/Authenticate/AuthHandler.cs b/Timeline/Authenticate/AuthHandler.cs index 80860edf..75d3b49f 100644 --- a/Timeline/Authenticate/AuthHandler.cs +++ b/Timeline/Authenticate/AuthHandler.cs @@ -80,7 +80,7 @@ namespace Timeline.Authenticate var identity = new ClaimsIdentity(AuthConstants.Scheme); identity.AddClaim(new Claim(identity.NameClaimType, userInfo.Username, ClaimValueTypes.String)); - identity.AddClaims(Entities.UserUtility.IsAdminToRoleArray(userInfo.IsAdmin).Select(role => new Claim(identity.RoleClaimType, role, ClaimValueTypes.String))); + identity.AddClaims(Entities.UserUtility.IsAdminToRoleArray(userInfo.Administrator).Select(role => new Claim(identity.RoleClaimType, role, ClaimValueTypes.String))); var principal = new ClaimsPrincipal(); principal.AddIdentity(identity); diff --git a/Timeline/Controllers/UserController.cs b/Timeline/Controllers/UserController.cs index 413999ce..84267520 100644 --- a/Timeline/Controllers/UserController.cs +++ b/Timeline/Controllers/UserController.cs @@ -59,7 +59,7 @@ namespace Timeline.Controllers return BadRequest(); } - var result = await _userService.PutUser(username, request.Password, request.IsAdmin); + var result = await _userService.PutUser(username, request.Password, request.Administrator); switch (result) { case PutResult.Created: @@ -78,7 +78,7 @@ namespace Timeline.Controllers { try { - await _userService.PatchUser(username, request.Password, request.IsAdmin); + await _userService.PatchUser(username, request.Password, request.Administrator); return Ok(); } catch (UserNotExistException e) diff --git a/Timeline/Entities/Http/User.cs b/Timeline/Entities/Http/User.cs index 91423c7b..b5384778 100644 --- a/Timeline/Entities/Http/User.cs +++ b/Timeline/Entities/Http/User.cs @@ -3,13 +3,13 @@ public class UserPutRequest { public string Password { get; set; } - public bool IsAdmin { get; set; } + public bool Administrator { get; set; } } public class UserPatchRequest { public string Password { get; set; } - public bool? IsAdmin { get; set; } + public bool? Administrator { get; set; } } public class ChangePasswordRequest diff --git a/Timeline/Entities/UserInfo.cs b/Timeline/Entities/UserInfo.cs index 9a82c991..414a8dfe 100644 --- a/Timeline/Entities/UserInfo.cs +++ b/Timeline/Entities/UserInfo.cs @@ -6,18 +6,18 @@ namespace Timeline.Entities { } - public UserInfo(string username, bool isAdmin) + public UserInfo(string username, bool administrator) { Username = username; - IsAdmin = isAdmin; + Administrator = administrator; } public string Username { get; set; } - public bool IsAdmin { get; set; } + public bool Administrator { get; set; } public override string ToString() { - return $"Username: {Username} ; IsAdmin: {IsAdmin}"; + return $"Username: {Username} ; Administrator: {Administrator}"; } } } diff --git a/Timeline/Entities/UserUtility.cs b/Timeline/Entities/UserUtility.cs index cbbd391c..14cdb2d6 100644 --- a/Timeline/Entities/UserUtility.cs +++ b/Timeline/Entities/UserUtility.cs @@ -54,7 +54,7 @@ namespace Timeline.Entities { if (user == null) throw new ArgumentNullException(nameof(user)); - return new UserCache { Username = user.Name, IsAdmin = RoleStringToIsAdmin(user.RoleString), Version = user.Version }; + return new UserCache { Username = user.Name, Administrator = RoleStringToIsAdmin(user.RoleString), Version = user.Version }; } } } diff --git a/Timeline/Services/UserService.cs b/Timeline/Services/UserService.cs index 01d05903..c63ded1e 100644 --- a/Timeline/Services/UserService.cs +++ b/Timeline/Services/UserService.cs @@ -96,21 +96,21 @@ namespace Timeline.Services /// </summary> /// <param name="username">Username of user.</param> /// <param name="password">Password of user.</param> - /// <param name="isAdmin">Whether the user is administrator.</param> + /// <param name="administrator">Whether the user is administrator.</param> /// <returns>Return <see cref="PutResult.Created"/> if a new user is created. /// Return <see cref="PutResult.Modified"/> if a existing user is modified.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="username"/> or <paramref name="password"/> is null.</exception> - Task<PutResult> PutUser(string username, string password, bool isAdmin); + Task<PutResult> PutUser(string username, string password, bool administrator); /// <summary> /// Partially modify a user of given username. /// </summary> /// <param name="username">Username of the user to modify. Can't be null.</param> /// <param name="password">New password. Null if not modify.</param> - /// <param name="isAdmin">Whether the user is administrator. Null if not modify.</param> + /// <param name="administrator">Whether the user is administrator. Null if not modify.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="username"/> is null.</exception> /// <exception cref="UserNotExistException">Thrown if the user with given username does not exist.</exception> - Task PatchUser(string username, string password, bool? isAdmin); + Task PatchUser(string username, string password, bool? administrator); /// <summary> /// Delete a user of given username. @@ -135,12 +135,12 @@ namespace Timeline.Services internal class UserCache { public string Username { get; set; } - public bool IsAdmin { get; set; } + public bool Administrator { get; set; } public long Version { get; set; } public UserInfo ToUserInfo() { - return new UserInfo(Username, IsAdmin); + return new UserInfo(Username, Administrator); } } @@ -263,7 +263,7 @@ namespace Timeline.Services .ToArrayAsync(); } - public async Task<PutResult> PutUser(string username, string password, bool isAdmin) + public async Task<PutResult> PutUser(string username, string password, bool administrator) { if (username == null) throw new ArgumentNullException(nameof(username)); @@ -278,7 +278,7 @@ namespace Timeline.Services { Name = username, EncryptedPassword = _passwordService.HashPassword(password), - RoleString = IsAdminToRoleString(isAdmin), + RoleString = IsAdminToRoleString(administrator), Version = 0 }); await _databaseContext.SaveChangesAsync(); @@ -286,7 +286,7 @@ namespace Timeline.Services } user.EncryptedPassword = _passwordService.HashPassword(password); - user.RoleString = IsAdminToRoleString(isAdmin); + user.RoleString = IsAdminToRoleString(administrator); user.Version += 1; await _databaseContext.SaveChangesAsync(); @@ -296,7 +296,7 @@ namespace Timeline.Services return PutResult.Modified; } - public async Task PatchUser(string username, string password, bool? isAdmin) + public async Task PatchUser(string username, string password, bool? administrator) { if (username == null) throw new ArgumentNullException(nameof(username)); @@ -313,10 +313,10 @@ namespace Timeline.Services user.EncryptedPassword = _passwordService.HashPassword(password); } - if (isAdmin != null) + if (administrator != null) { modified = true; - user.RoleString = IsAdminToRoleString(isAdmin.Value); + user.RoleString = IsAdminToRoleString(administrator.Value); } if (modified) |