From ce85af942c64fc3bad4e4502d683f730c882de96 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 26 Nov 2020 23:43:11 +0800 Subject: refactor: ... --- BackEnd/Timeline/Services/UserService.cs | 68 -------------------------------- 1 file changed, 68 deletions(-) (limited to 'BackEnd/Timeline/Services/UserService.cs') diff --git a/BackEnd/Timeline/Services/UserService.cs b/BackEnd/Timeline/Services/UserService.cs index cded3ff1..9395cc52 100644 --- a/BackEnd/Timeline/Services/UserService.cs +++ b/BackEnd/Timeline/Services/UserService.cs @@ -26,19 +26,6 @@ namespace Timeline.Services public interface IUserService : IBasicUserService { - /// - /// Try to verify the given username and password. - /// - /// The username of the user to verify. - /// The password of the user to verify. - /// The user info and auth info. - /// Thrown when or is null. - /// Thrown when is of bad format or is empty. - /// Thrown when the user with given username does not exist. - /// Thrown when password is wrong. - Task VerifyCredential(string username, string password); - - /// /// Try to get a user by id. /// @@ -47,7 +34,6 @@ namespace Timeline.Services /// Thrown when the user with given id does not exist. Task GetUser(long id); - /// /// List all users. /// @@ -77,18 +63,6 @@ namespace Timeline.Services /// Version will increase if password is changed. /// Task ModifyUser(long id, ModifyUserParams? param); - - /// - /// Try to change a user's password with old password. - /// - /// The id of user to change password of. - /// Old password. - /// New password. - /// Thrown if or is null. - /// Thrown if or is empty. - /// Thrown if the user with given username does not exist. - /// Thrown if the old password is wrong. - Task ChangePassword(long id, string oldPassword, string newPassword); } public class UserService : BasicUserService, IUserService @@ -159,26 +133,7 @@ namespace Timeline.Services }; } - public async Task VerifyCredential(string username, string password) - { - if (username == null) - throw new ArgumentNullException(nameof(username)); - if (password == null) - throw new ArgumentNullException(nameof(password)); - - CheckUsernameFormat(username, nameof(username)); - CheckPasswordFormat(password, nameof(password)); - - var entity = await _databaseContext.Users.Where(u => u.Username == username).SingleOrDefaultAsync(); - - if (entity == null) - throw new UserNotExistException(username); - if (!_passwordService.VerifyPassword(entity.Password, password)) - throw new BadPasswordException(password); - - return await CreateUserFromEntity(entity); - } public async Task GetUser(long id) { @@ -288,28 +243,5 @@ namespace Timeline.Services return await CreateUserFromEntity(entity); } - - public async Task ChangePassword(long id, string oldPassword, string newPassword) - { - if (oldPassword == null) - throw new ArgumentNullException(nameof(oldPassword)); - if (newPassword == null) - throw new ArgumentNullException(nameof(newPassword)); - CheckPasswordFormat(oldPassword, nameof(oldPassword)); - CheckPasswordFormat(newPassword, nameof(newPassword)); - - var entity = await _databaseContext.Users.Where(u => u.Id == id).SingleOrDefaultAsync(); - - if (entity == null) - throw new UserNotExistException(id); - - if (!_passwordService.VerifyPassword(entity.Password, oldPassword)) - throw new BadPasswordException(oldPassword); - - entity.Password = _passwordService.HashPassword(newPassword); - entity.Version += 1; - await _databaseContext.SaveChangesAsync(); - _logger.LogInformation(Log.Format(LogDatabaseUpdate, ("Id", id), ("Operation", "Change password"))); - } } } -- cgit v1.2.3