Files
Yi.Framework/Yi.Framework.Net6/Yi.Framework.Model/UserEntity.cs
2022-12-26 14:19:12 +08:00

54 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugar;
using Yi.Framework.Common.Helper;
namespace Yi.Framework.Model.Models
{
public partial class UserEntity
{
/// <summary>
/// 看好啦ORM精髓导航属性
///</summary>
[Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.UserId), nameof(UserRoleEntity.RoleId))]
public List<RoleEntity>? Roles { get; set; }
[Navigate(typeof(UserPostEntity), nameof(UserPostEntity.UserId), nameof(UserPostEntity.PostId))]
public List<PostEntity>? Posts { get; set; }
[Navigate( NavigateType.OneToOne,nameof(DeptId))]
public DeptEntity? Dept { get; set; }
/// <summary>
/// 构建密码MD5盐值加密
/// </summary>
public UserEntity BuildPassword(string password = null)
{
//如果不传值那就把自己的password当作传进来的password
if (password == null)
{
password = this.Password;
}
this.Salt = Common.Helper.MD5Helper.GenerateSalt();
this.Password = Common.Helper.MD5Helper.SHA2Encode(password, this.Salt);
return this;
}
/// <summary>
/// 判断密码和加密后的密码是否相同
/// </summary>
/// <param name="password"></param>
/// <returns></returns>
public bool JudgePassword(string password)
{
var p = MD5Helper.SHA2Encode(password, this.Salt);
if (this.Password == MD5Helper.SHA2Encode(password, this.Salt))
{
return true;
}
return false;
}
}
}