68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|
|
|