aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Services/UserService.cs
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-08-04 15:46:31 +0800
committer杨宇千 <crupest@outlook.com>2019-08-04 15:46:31 +0800
commit36da221444807742a9e26f2ba636d9c6aef6155f (patch)
treedeace7e60ff91362572bf178004f3928175a340e /Timeline/Services/UserService.cs
parenta17aa8770b0b4861849c6e01812b2ff686497f02 (diff)
downloadtimeline-36da221444807742a9e26f2ba636d9c6aef6155f.tar.gz
timeline-36da221444807742a9e26f2ba636d9c6aef6155f.tar.bz2
timeline-36da221444807742a9e26f2ba636d9c6aef6155f.zip
Continue to add unit tests for token. Fix a bug thanks to unit test.
Diffstat (limited to 'Timeline/Services/UserService.cs')
-rw-r--r--Timeline/Services/UserService.cs23
1 files changed, 9 insertions, 14 deletions
diff --git a/Timeline/Services/UserService.cs b/Timeline/Services/UserService.cs
index 328dbff0..65ac98d3 100644
--- a/Timeline/Services/UserService.cs
+++ b/Timeline/Services/UserService.cs
@@ -19,7 +19,7 @@ namespace Timeline.Services
[Serializable]
public class UserNotExistException : Exception
{
- public UserNotExistException(): base("The user does not exist.") { }
+ public UserNotExistException() : base("The user does not exist.") { }
public UserNotExistException(string message) : base(message) { }
public UserNotExistException(string message, Exception inner) : base(message, inner) { }
protected UserNotExistException(
@@ -30,7 +30,7 @@ namespace Timeline.Services
[Serializable]
public class BadPasswordException : Exception
{
- public BadPasswordException(): base("Password is wrong.") { }
+ public BadPasswordException() : base("Password is wrong.") { }
public BadPasswordException(string message) : base(message) { }
public BadPasswordException(string message, Exception inner) : base(message, inner) { }
protected BadPasswordException(
@@ -42,7 +42,7 @@ namespace Timeline.Services
[Serializable]
public class BadTokenVersionException : Exception
{
- public BadTokenVersionException(): base("Token version is expired.") { }
+ public BadTokenVersionException() : base("Token version is expired.") { }
public BadTokenVersionException(string message) : base(message) { }
public BadTokenVersionException(string message, Exception inner) : base(message, inner) { }
protected BadTokenVersionException(
@@ -105,6 +105,8 @@ namespace Timeline.Services
/// <summary>
/// Partially modify a user of given username.
+ ///
+ /// Note that whether actually modified or not, Version of the user will always increase.
/// </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>
@@ -309,27 +311,20 @@ namespace Timeline.Services
if (user == null)
throw new UserNotExistException();
- bool modified = false;
-
if (password != null)
{
- modified = true;
user.EncryptedPassword = _passwordService.HashPassword(password);
}
if (administrator != null)
{
- modified = true;
user.RoleString = IsAdminToRoleString(administrator.Value);
}
- if (modified)
- {
- user.Version += 1;
- await _databaseContext.SaveChangesAsync();
- //clear cache
- RemoveCache(user.Id);
- }
+ user.Version += 1;
+ await _databaseContext.SaveChangesAsync();
+ //clear cache
+ RemoveCache(user.Id);
}
public async Task DeleteUser(string username)