feat: 添加值对象
This commit is contained in:
@@ -152,7 +152,7 @@ namespace Yi.Framework.Rbac.Application.Services.System
|
|||||||
//更新密码,特殊处理
|
//更新密码,特殊处理
|
||||||
if (input.Password is not null)
|
if (input.Password is not null)
|
||||||
{
|
{
|
||||||
entity.Password = input.Password;
|
entity.EncryPassword.Password = input.Password;
|
||||||
entity.BuildPassword();
|
entity.BuildPassword();
|
||||||
}
|
}
|
||||||
await MapToEntityAsync(input, entity);
|
await MapToEntityAsync(input, entity);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Volo.Abp.Auditing;
|
|||||||
using Volo.Abp.Domain.Entities;
|
using Volo.Abp.Domain.Entities;
|
||||||
using Yi.Framework.Core.Data;
|
using Yi.Framework.Core.Data;
|
||||||
using Yi.Framework.Core.Helper;
|
using Yi.Framework.Core.Helper;
|
||||||
|
using Yi.Framework.Rbac.Domain.Entities.ValueObjects;
|
||||||
using Yi.Framework.Rbac.Domain.Shared.Enums;
|
using Yi.Framework.Rbac.Domain.Shared.Enums;
|
||||||
|
|
||||||
namespace Yi.Framework.Rbac.Domain.Entities
|
namespace Yi.Framework.Rbac.Domain.Entities
|
||||||
@@ -22,7 +23,7 @@ namespace Yi.Framework.Rbac.Domain.Entities
|
|||||||
public UserEntity(string userName, string password, long phone, string nick = "萌新")
|
public UserEntity(string userName, string password, long phone, string nick = "萌新")
|
||||||
{
|
{
|
||||||
UserName = userName;
|
UserName = userName;
|
||||||
Password = password;
|
EncryPassword.Password = password;
|
||||||
Phone = phone;
|
Phone = phone;
|
||||||
Nick = nick;
|
Nick = nick;
|
||||||
BuildPassword();
|
BuildPassword();
|
||||||
@@ -55,14 +56,20 @@ namespace Yi.Framework.Rbac.Domain.Entities
|
|||||||
public string UserName { get; set; } = string.Empty;
|
public string UserName { get; set; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 密码
|
/// 加密密码
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Password { get; set; } = string.Empty;
|
[SugarColumn(IsOwnsOne = true)]
|
||||||
|
public EncryPasswordValueObject EncryPassword { get; set; }=new EncryPasswordValueObject();
|
||||||
|
|
||||||
/// <summary>
|
///// <summary>
|
||||||
/// 加密盐值
|
///// 密码
|
||||||
/// </summary>
|
///// </summary>
|
||||||
public string Salt { get; set; } = string.Empty;
|
//public string Password { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
///// <summary>
|
||||||
|
///// 加密盐值
|
||||||
|
///// </summary>
|
||||||
|
//public string Salt { get; set; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 头像
|
/// 头像
|
||||||
@@ -175,14 +182,14 @@ namespace Yi.Framework.Rbac.Domain.Entities
|
|||||||
//如果不传值,那就把自己的password当作传进来的password
|
//如果不传值,那就把自己的password当作传进来的password
|
||||||
if (password == null)
|
if (password == null)
|
||||||
{
|
{
|
||||||
if (Password == null)
|
if (EncryPassword.Password == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(Password));
|
throw new ArgumentNullException(nameof(EncryPassword.Password));
|
||||||
}
|
}
|
||||||
password = Password;
|
password = EncryPassword.Password;
|
||||||
}
|
}
|
||||||
Salt = MD5Helper.GenerateSalt();
|
EncryPassword.Salt = MD5Helper.GenerateSalt();
|
||||||
Password = MD5Helper.SHA2Encode(password, Salt);
|
EncryPassword.Password = MD5Helper.SHA2Encode(password, EncryPassword.Salt);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,12 +200,12 @@ namespace Yi.Framework.Rbac.Domain.Entities
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool JudgePassword(string password)
|
public bool JudgePassword(string password)
|
||||||
{
|
{
|
||||||
if (Salt is null)
|
if (EncryPassword.Salt is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(Salt);
|
throw new ArgumentNullException(EncryPassword.Salt);
|
||||||
}
|
}
|
||||||
var p = MD5Helper.SHA2Encode(password, Salt);
|
var p = MD5Helper.SHA2Encode(password, EncryPassword.Salt);
|
||||||
if (Password == MD5Helper.SHA2Encode(password, Salt))
|
if (EncryPassword.Password == MD5Helper.SHA2Encode(password, EncryPassword.Salt))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Volo.Abp.Domain.Values;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Rbac.Domain.Entities.ValueObjects
|
||||||
|
{
|
||||||
|
public class EncryPasswordValueObject : ValueObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 密码
|
||||||
|
/// </summary>
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加密盐值
|
||||||
|
/// </summary>
|
||||||
|
public string Salt { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
protected override IEnumerable<object> GetAtomicValues()
|
||||||
|
{
|
||||||
|
yield return Password;
|
||||||
|
yield return Salt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -154,7 +154,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
|||||||
{
|
{
|
||||||
userAction.Invoke(user);
|
userAction.Invoke(user);
|
||||||
}
|
}
|
||||||
if (user.Password == MD5Helper.SHA2Encode(password, user.Salt))
|
if (user.EncryPassword.Password == MD5Helper.SHA2Encode(password, user.EncryPassword.Salt))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -247,7 +247,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
|||||||
{
|
{
|
||||||
throw new UserFriendlyException("无效更新!原密码错误!");
|
throw new UserFriendlyException("无效更新!原密码错误!");
|
||||||
}
|
}
|
||||||
user.Password = newPassword;
|
user.EncryPassword.Password = newPassword;
|
||||||
user.BuildPassword();
|
user.BuildPassword();
|
||||||
await _repository.UpdateAsync(user);
|
await _repository.UpdateAsync(user);
|
||||||
}
|
}
|
||||||
@@ -262,7 +262,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
|||||||
{
|
{
|
||||||
var user = await _repository.GetByIdAsync(userId);
|
var user = await _repository.GetByIdAsync(userId);
|
||||||
// EntityHelper.TrySetId(user, () => GuidGenerator.Create(), true);
|
// EntityHelper.TrySetId(user, () => GuidGenerator.Create(), true);
|
||||||
user.Password = password;
|
user.EncryPassword.Password = password;
|
||||||
user.BuildPassword();
|
user.BuildPassword();
|
||||||
return await _repository.UpdateAsync(user);
|
return await _repository.UpdateAsync(user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,8 +152,8 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
|||||||
//{
|
//{
|
||||||
// throw new UserFriendlyException($"数据错误,用户id:{nameof(userId)} 不存在,请重新登录");
|
// throw new UserFriendlyException($"数据错误,用户id:{nameof(userId)} 不存在,请重新登录");
|
||||||
//}
|
//}
|
||||||
user.Password = string.Empty;
|
user.EncryPassword.Password = string.Empty;
|
||||||
user.Salt = string.Empty;
|
user.EncryPassword.Salt = string.Empty;
|
||||||
|
|
||||||
//超级管理员特殊处理
|
//超级管理员特殊处理
|
||||||
if (UserConst.Admin.Equals(user.UserName))
|
if (UserConst.Admin.Equals(user.UserName))
|
||||||
|
|||||||
Reference in New Issue
Block a user