添加登录

This commit is contained in:
橙子
2023-01-30 20:07:09 +08:00
parent aec0150a26
commit b7260ed982
277 changed files with 21789 additions and 31 deletions

View File

@@ -3,6 +3,10 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Core.Exceptions;
using Yi.Framework.Ddd.Repositories;
using Yi.RBAC.Domain.Identity.Entities;
using Yi.RBAC.Domain.Shared.Identity.ConstClasses;
namespace Yi.RBAC.Domain.Identity
{
@@ -13,5 +17,56 @@ namespace Yi.RBAC.Domain.Identity
[AppService]
public class UserManager
{
private readonly IRepository<UserEntity> _repository;
public UserManager(IRepository<UserEntity> repository)
{
_repository = repository;
}
/// <summary>
/// 登录效验
/// </summary>
/// <param name="userName"></param>
/// <param name="password"></param>
/// <param name="userAction"></param>
/// <returns></returns>
public async Task LoginValidationAsync(string userName, string password, Action<UserEntity>? userAction = null)
{
var user = new UserEntity();
if (await ExistAsync(userName, o => user = o))
{
if (userAction is not null)
{
userAction.Invoke(user);
}
if (user.Password != MD5Helper.SHA2Encode(password, user.Salt))
{
return;
}
throw new UserFriendlyException(UserConst._错误);
}
throw new UserFriendlyException(UserConst._不存在);
}
/// <summary>
/// 判断账户合法存在
/// </summary>
/// <param name="userName"></param>
/// <param name="userAction"></param>
/// <returns></returns>
public async Task<bool> ExistAsync(string userName, Action<UserEntity>? userAction = null)
{
var user = await _repository.GetFirstAsync(u => u.UserName == userName && u.IsDeleted == false);
if (userAction is not null)
{
userAction.Invoke(user);
}
if (user == null)
{
return false;
}
return true;
}
}
}