feature-nxdev #12
@@ -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() { }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace IM_API.Dtos
|
||||||
|
{
|
||||||
|
public class LoginRequestDto
|
||||||
|
{
|
||||||
|
public string Username { get; set; }
|
||||||
|
public string Password { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace IM_API.Dtos
|
||||||
|
{
|
||||||
|
public class RegisterRequestDto
|
||||||
|
{
|
||||||
|
public string Username { get; set; }
|
||||||
|
public string Password { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace IM_API.Dtos
|
||||||
|
{
|
||||||
|
public class UpdateUserDto
|
||||||
|
{
|
||||||
|
public string? NickName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
|
||||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.3" />
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.3" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||||
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.14.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</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
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace IM_API.Models
|
||||||
|
{
|
||||||
|
public enum FriendStatus:SByte
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,7 +41,7 @@ public partial class User
|
|||||||
/// 1:在线
|
/// 1:在线
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Column(TypeName = "tinyint(4)")]
|
[Column(TypeName = "tinyint(4)")]
|
||||||
public sbyte OlineStatus { get; set; }
|
public UserOnlineStatus OlineStatus { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建时间
|
/// 创建时间
|
||||||
@@ -60,7 +60,7 @@ public partial class User
|
|||||||
/// (0:未激活,1:正常,2:封禁)
|
/// (0:未激活,1:正常,2:封禁)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Column(TypeName = "tinyint(4)")]
|
[Column(TypeName = "tinyint(4)")]
|
||||||
public sbyte Status { get; set; }
|
public UserStatus Status { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 软删除标识
|
/// 软删除标识
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
namespace IM_API.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户在线状态
|
||||||
|
/// </summary>
|
||||||
|
public enum UserOnlineStatus : sbyte
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 不在线 (0)
|
||||||
|
/// </summary>
|
||||||
|
Offline = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 在线 (1)
|
||||||
|
/// </summary>
|
||||||
|
Online = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace IM_API.Models
|
||||||
|
{
|
||||||
|
public enum UserStatus:SByte
|
||||||
|
{
|
||||||
|
Inactive = 0,
|
||||||
|
Normal = 1,
|
||||||
|
Banned = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user