Merge pull request 'feature-nxdev' (#12) from feature-nxdev into main
Reviewed-on: #12
This commit is contained in:
commit
b5d5cce06d
57
backend/IM_API/Dtos/BaseResponse.cs
Normal file
57
backend/IM_API/Dtos/BaseResponse.cs
Normal file
@ -0,0 +1,57 @@
|
||||
namespace IM_API.Dtos
|
||||
{
|
||||
public class BaseResponse<T>
|
||||
{
|
||||
//响应状态码
|
||||
public int Code { get; set; }
|
||||
//响应消息
|
||||
public string Message { get; set; }
|
||||
//响应数据
|
||||
public T? Data { get; set; }
|
||||
/// <summary>
|
||||
/// 默认成功响应返回
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
/// <param name="data"></param>
|
||||
public BaseResponse(string msg,T data)
|
||||
{
|
||||
this.Code = 0;
|
||||
this.Message = msg;
|
||||
this.Data = data;
|
||||
}
|
||||
/// <summary>
|
||||
/// 默认成功响应返回,不带数据
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
/// <param name="data"></param>
|
||||
public BaseResponse(string msg)
|
||||
{
|
||||
this.Code = 0;
|
||||
this.Message = msg;
|
||||
}
|
||||
/// <summary>
|
||||
/// 非成功响应且带数据
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="data"></param>
|
||||
public BaseResponse(int code, string message, T? data)
|
||||
{
|
||||
Code = code;
|
||||
Message = message;
|
||||
Data = data;
|
||||
}
|
||||
/// <summary>
|
||||
/// 非成功响应且不带数据
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="data"></param>
|
||||
public BaseResponse(int code, string message)
|
||||
{
|
||||
Code = code;
|
||||
Message = message;
|
||||
}
|
||||
public BaseResponse() { }
|
||||
}
|
||||
}
|
||||
9
backend/IM_API/Dtos/FriendRequestDto.cs
Normal file
9
backend/IM_API/Dtos/FriendRequestDto.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace IM_API.Dtos
|
||||
{
|
||||
public class FriendRequestDto
|
||||
{
|
||||
public int FromUserId { get; set; }
|
||||
public int ToUserId { get; set; }
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
}
|
||||
9
backend/IM_API/Dtos/LoginDto.cs
Normal file
9
backend/IM_API/Dtos/LoginDto.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace IM_API.Dtos
|
||||
{
|
||||
public class LoginDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Token { get; set; }
|
||||
public string RefreshToken { get; set; }
|
||||
}
|
||||
}
|
||||
8
backend/IM_API/Dtos/LoginRequestDto.cs
Normal file
8
backend/IM_API/Dtos/LoginRequestDto.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace IM_API.Dtos
|
||||
{
|
||||
public class LoginRequestDto
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
8
backend/IM_API/Dtos/RegisterRequestDto.cs
Normal file
8
backend/IM_API/Dtos/RegisterRequestDto.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace IM_API.Dtos
|
||||
{
|
||||
public class RegisterRequestDto
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
7
backend/IM_API/Dtos/UpdateUserDto.cs
Normal file
7
backend/IM_API/Dtos/UpdateUserDto.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace IM_API.Dtos
|
||||
{
|
||||
public class UpdateUserDto
|
||||
{
|
||||
public string? NickName { get; set; }
|
||||
}
|
||||
}
|
||||
38
backend/IM_API/Dtos/UserInfoDto.cs
Normal file
38
backend/IM_API/Dtos/UserInfoDto.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace IM_API.Dtos
|
||||
{
|
||||
public class UserInfoDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 唯一用户名
|
||||
/// </summary>
|
||||
public string Username { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户昵称
|
||||
/// </summary>
|
||||
public string NickName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户在线状态
|
||||
/// 0(默认):不在线
|
||||
/// 1:在线
|
||||
/// </summary>
|
||||
public sbyte OlineStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime Created { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 账户状态
|
||||
/// (0:未激活,1:正常,2:封禁)
|
||||
/// </summary>
|
||||
public sbyte Status { get; set; }
|
||||
}
|
||||
}
|
||||
@ -21,6 +21,7 @@
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.14.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -1,6 +1,39 @@
|
||||
namespace IM_API.Interface.Services
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Models;
|
||||
|
||||
namespace IM_API.Interface.Services
|
||||
{
|
||||
public interface IAuthService
|
||||
{
|
||||
/// <summary>
|
||||
/// 登录
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
Task<LoginDto> LoginAsync(LoginRequestDto dto);
|
||||
/// <summary>
|
||||
/// 注册
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
Task<UserInfoDto> RegisterAsync(RegisterRequestDto dto);
|
||||
/// <summary>
|
||||
/// 生成登录凭证
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
string GenerateToken(User user);
|
||||
/// <summary>
|
||||
/// 验证登录凭证
|
||||
/// </summary>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
int? ValidateToken(string token);
|
||||
/// <summary>
|
||||
/// 刷新令牌
|
||||
/// </summary>
|
||||
/// <param name="refreshToken"></param>
|
||||
/// <returns></returns>
|
||||
LoginDto RefreshToken(string refreshToken);
|
||||
}
|
||||
}
|
||||
|
||||
32
backend/IM_API/Interface/Services/IFriendSerivce.cs
Normal file
32
backend/IM_API/Interface/Services/IFriendSerivce.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Models;
|
||||
|
||||
namespace IM_API.Interface.Services
|
||||
{
|
||||
public interface IFriendSerivce
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取好友列表
|
||||
/// </summary>
|
||||
/// <param name="userId">指定用户</param>
|
||||
/// <param name="page">当前页</param>
|
||||
/// <param name="limit">分页大小</param>
|
||||
/// <returns></returns>
|
||||
Task<List<UserInfoDto>> GetFriendListAsync(int userId,int page,int limit);
|
||||
/// <summary>
|
||||
/// 新增好友请求
|
||||
/// </summary>
|
||||
/// <param name="friendRequest"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> SendFriendRequestAsync(FriendRequestDto friendRequest);
|
||||
/// <summary>
|
||||
/// 获取好友请求
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="isReceived">是否为接受请求方</param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
Task<Friendrequest> GetFriendRequestListAsync(int userId,bool isReceived,int page,int limit);
|
||||
}
|
||||
}
|
||||
39
backend/IM_API/Interface/Services/IUserService.cs
Normal file
39
backend/IM_API/Interface/Services/IUserService.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Models;
|
||||
|
||||
namespace IM_API.Interface.Services
|
||||
{
|
||||
public interface IUserService
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取用户信息
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<UserInfoDto> GetUserInfoAsync(int userId);
|
||||
/// <summary>
|
||||
/// 用户名查找用户
|
||||
/// </summary>
|
||||
/// <param name="username"></param>
|
||||
/// <returns></returns>
|
||||
Task<UserInfoDto> GetUserInfoByUsernameAsync(string username);
|
||||
/// <summary>
|
||||
/// 更新用户信息
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
Task<UserInfoDto> UpdateUserAsync(UpdateUserDto dto);
|
||||
/// <summary>
|
||||
/// 重置用户密码
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> ResetPasswordAsync(string password);
|
||||
/// <summary>
|
||||
/// 更新用户在线状态
|
||||
/// </summary>
|
||||
/// <param name="onlineStatus"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> UpdateOlineStatusAsync(UserOnlineStatus onlineStatus);
|
||||
}
|
||||
}
|
||||
7
backend/IM_API/Models/FriendStatus.cs
Normal file
7
backend/IM_API/Models/FriendStatus.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace IM_API.Models
|
||||
{
|
||||
public enum FriendStatus:SByte
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -41,7 +41,7 @@ public partial class User
|
||||
/// 1:在线
|
||||
/// </summary>
|
||||
[Column(TypeName = "tinyint(4)")]
|
||||
public sbyte OlineStatus { get; set; }
|
||||
public UserOnlineStatus OlineStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
@ -60,7 +60,7 @@ public partial class User
|
||||
/// (0:未激活,1:正常,2:封禁)
|
||||
/// </summary>
|
||||
[Column(TypeName = "tinyint(4)")]
|
||||
public sbyte Status { get; set; }
|
||||
public UserStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 软删除标识
|
||||
|
||||
18
backend/IM_API/Models/UserOlineStatus.cs
Normal file
18
backend/IM_API/Models/UserOlineStatus.cs
Normal file
@ -0,0 +1,18 @@
|
||||
namespace IM_API.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户在线状态
|
||||
/// </summary>
|
||||
public enum UserOnlineStatus : sbyte
|
||||
{
|
||||
/// <summary>
|
||||
/// 不在线 (0)
|
||||
/// </summary>
|
||||
Offline = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 在线 (1)
|
||||
/// </summary>
|
||||
Online = 1
|
||||
}
|
||||
}
|
||||
9
backend/IM_API/Models/UserStatus.cs
Normal file
9
backend/IM_API/Models/UserStatus.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace IM_API.Models
|
||||
{
|
||||
public enum UserStatus:SByte
|
||||
{
|
||||
Inactive = 0,
|
||||
Normal = 1,
|
||||
Banned = 2
|
||||
}
|
||||
}
|
||||
22
backend/IM_API/Tools/PasswordHasher.cs
Normal file
22
backend/IM_API/Tools/PasswordHasher.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace IM_API.Tools
|
||||
{
|
||||
public static class PasswordHasher
|
||||
{
|
||||
public static string HashPassword(string password)
|
||||
{
|
||||
using var sha256 = SHA256.Create();
|
||||
var hashedBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(password));
|
||||
return Convert.ToBase64String(hashedBytes);
|
||||
}
|
||||
|
||||
public static bool VerifyPassword(string password, string hashedPassword)
|
||||
{
|
||||
var hashedInput = HashPassword(password);
|
||||
return hashedInput == hashedPassword;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user