90 lines
2.5 KiB
C#
90 lines
2.5 KiB
C#
using Apimanager_backend.Config;
|
|
using Apimanager_backend.Data;
|
|
using Apimanager_backend.Dtos;
|
|
using Apimanager_backend.Exceptions;
|
|
using Apimanager_backend.Models;
|
|
using AutoMapper;
|
|
using Microsoft.AspNetCore.Connections.Features;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.ComponentModel;
|
|
|
|
namespace Apimanager_backend.Services
|
|
{
|
|
public class UserService : IUserService
|
|
{
|
|
private readonly ApiContext apiContext;
|
|
private readonly IMapper mapper;
|
|
public UserService(ApiContext apiContext,IMapper automapper)
|
|
{
|
|
this.apiContext = apiContext;
|
|
this.mapper = automapper;
|
|
}
|
|
public Task BanUserAsync(string username)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<UserInfoDto> CreateUserAsync(CreateUserDto user)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task DeleteUserAsync(string username)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<UserInfoDto> GetUserAsync(string username)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<List<UserInfoDto>> GetUsersAsync(int page, int pageSize, bool desc)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<UserInfoDto> LoginAsync(string username, string password)
|
|
{
|
|
//查找用户
|
|
User? user = await apiContext.Users.SingleOrDefaultAsync(x =>
|
|
x.Username == username && x.PassHash == password
|
|
);
|
|
|
|
//用户不存在或密码错误都为登录失败
|
|
if(user == null)
|
|
{
|
|
throw new BaseException(2001, "Invalid username or password");
|
|
}
|
|
|
|
//用户被禁用
|
|
if (user.IsBan)
|
|
{
|
|
throw new BaseException(2002, "User account is disabled");
|
|
}
|
|
|
|
return mapper.Map<UserInfoDto>(user);
|
|
}
|
|
|
|
public Task ResetPasswordAsync(string email, string token, string newPassword)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task SendResetPasswordEmailAsync(string email)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task UnbanUserAsync(string username)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<UserInfoDto> UpdateUserAsync(UpdateUserDto user)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|