초기커밋
This commit is contained in:
67
UGQDataAccess/Service/AdminService.cs
Normal file
67
UGQDataAccess/Service/AdminService.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UGQDataAccess.Repository.Models;
|
||||
using UGQDataAccess.Repository;
|
||||
using UGQDatabase.Models;
|
||||
using ServerCommon;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace UGQDataAccess.Service
|
||||
{
|
||||
public class AdminService
|
||||
{
|
||||
readonly AdminAccountRepository _adminAccountRepository;
|
||||
|
||||
public AdminService(AdminAccountRepository adminAccountRepository)
|
||||
{
|
||||
_adminAccountRepository = adminAccountRepository;
|
||||
}
|
||||
|
||||
public async Task<AdminAccountEntity?> get(string username)
|
||||
{
|
||||
return await _adminAccountRepository.get(username);
|
||||
}
|
||||
|
||||
public async Task<AdminAccountEntity?> signup(string username, string password, UGQAccountRole role)
|
||||
{
|
||||
var passwordHash = BCrypt.Net.BCrypt.HashPassword(password);
|
||||
return await _adminAccountRepository.signup(username, passwordHash, role);
|
||||
}
|
||||
|
||||
public async Task<AdminAccountEntity?> login(string username, string password)
|
||||
{
|
||||
var entity = await _adminAccountRepository.get(username);
|
||||
if (entity == null)
|
||||
return null;
|
||||
|
||||
if (BCrypt.Net.BCrypt.Verify(password, entity.Password) == false)
|
||||
return null;
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public async Task<AdminAccountEntity?> changePassword(string username, string newPassword)
|
||||
{
|
||||
var entity = await _adminAccountRepository.get(username);
|
||||
if (entity == null)
|
||||
return null;
|
||||
|
||||
var passwordHash = BCrypt.Net.BCrypt.HashPassword(newPassword);
|
||||
return await _adminAccountRepository.changePassword(username, passwordHash);
|
||||
}
|
||||
|
||||
public async Task<AdminAccountEntity?> saveRefreshToken(string id, string refreshToken, DateTime? refreshTokenExpryTime)
|
||||
{
|
||||
return await _adminAccountRepository.saveRefreshToken(id, refreshToken, refreshTokenExpryTime);
|
||||
}
|
||||
|
||||
public async Task<AdminAccountEntity?> deleteRefreshToken(string userGuid)
|
||||
{
|
||||
return await _adminAccountRepository.deleteRefreshToken(userGuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user