58 lines
1.9 KiB
C#
58 lines
1.9 KiB
C#
using YLErp.Helpers;
|
|
|
|
namespace YLErp.Modules.SystemModule
|
|
{
|
|
/// <summary>
|
|
/// 系统用户密码服务
|
|
/// </summary>
|
|
public class SysUserPasswordService : BaseService<BaseOUDAL.ErpBaseContext>
|
|
{
|
|
public SysUserPasswordService(OptUserInfo userInfo) : base(userInfo)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 变更密码
|
|
/// </summary>
|
|
public void ChangePassword(UserChangePasswordRequest reqModel)
|
|
{
|
|
if (reqModel is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(reqModel));
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(reqModel.Password))
|
|
{
|
|
throw new ServiceException("输入错误,缺少当前密码");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(reqModel.NewPassword))
|
|
{
|
|
throw new ServiceException("输入错误,缺少新密码");
|
|
}
|
|
|
|
if (reqModel.NewPassword == null || reqModel.NewPassword.Length < 6 || !reqModel.NewPassword.Any(n => (n >= 'a' && n <= 'z') || (n >= 'A' && n <= 'Z')) || !reqModel.NewPassword.Any(n => n >= '0' && n <= '9'))
|
|
{
|
|
throw new ServiceException("密码长度至少6位并且包含英文字母和数字");
|
|
}
|
|
|
|
var user = DbContext.SystemUsers.Where(u => u.Id == reqModel.UserId).FirstOrDefault();
|
|
|
|
if (user == null)
|
|
{
|
|
throw new ServiceException("用户信息不存在");
|
|
}
|
|
|
|
if (!DataHelper.EncryptPassword(user.LoginName.ToLowerInvariant(), reqModel.Password).Equals(user.Password, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
throw new ServiceException("当前密码错误");
|
|
}
|
|
|
|
user.Password = DataHelper.EncryptPassword(user.LoginName.ToLowerInvariant(), reqModel.NewPassword);
|
|
|
|
DbContext.SaveChanges();
|
|
}
|
|
}
|
|
}
|