Commit d6053c18 by ruyun.zhang

Merge branch 'feature/宜宾高县安全' into develop

parents 9369fd3c 0b9f4326
......@@ -49,7 +49,7 @@ public class AccountController : Controller
/// {
/// "logintype": 2,
/// "account": "admin",
/// "password": "1111",
/// "password": "e10adc3949ba59abbe56e057f20f883e",
/// "appname": "string",
/// "device": "web"
/// }
......@@ -75,6 +75,37 @@ public ApiResponse<JwtToken> Login([FromBody] LoginRequest request)
new Claim(JwtClaimTypes.AppName, request.AppName ?? ""),
new Claim(JwtClaimTypes.Device, request.Device ?? ""),
new Claim(JwtClaimTypes.Department, user.Department ?? ""),
new Claim(JwtClaimTypes.QuickLogin, EQuickLogin.NO.ToString()),
};
var jwtToken = JwtTokenHelper.GenerateToken(claims, _options.ExpirationMinutes);
return new ApiResponse<JwtToken>(ResponseType.OK, jwtToken);
}
/// <summary>
/// 快速登录
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("quick/login")]
[HttpPost]
[AllowAnonymous]
public ApiResponse<JwtToken> QuickLogin([FromBody] ResetPwdRequest request)
{
var user = _userService.QuickLogin(request.TargetUserId, request.CurrentUserId, request.Password);
if (user == null)
return new ApiResponse<JwtToken>(ResponseType.Fail, "用户不存在");
var claims = new Claim[]
{
new Claim(JwtClaimTypes.Id, user.UserID.ToString()),
new Claim(JwtClaimTypes.Login, user.Login),
new Claim(JwtClaimTypes.RealName, user.RealName),
new Claim(JwtClaimTypes.Mail, user.Mail??""),
new Claim(JwtClaimTypes.AppName, request.AppName ?? ""),
new Claim(JwtClaimTypes.Device, request.Device ?? ""),
new Claim(JwtClaimTypes.Department, user.Department ?? ""),
new Claim(JwtClaimTypes.QuickLogin, EQuickLogin.YES.ToString()),
};
var jwtToken = JwtTokenHelper.GenerateToken(claims, _options.ExpirationMinutes);
......@@ -119,6 +150,16 @@ public ApiResponse SelfInfo()
{
var userid = _claim.GetUserId();
var user = _userService.GetUser(userid);
var userClaim = _claim.GetUserClaim();
// 如果用户是快捷登录的,则不需要重置密码
var quickLogin = userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.QuickLogin)?.Value ?? "";
if (quickLogin.Equals(EQuickLogin.YES.ToString(), StringComparison.OrdinalIgnoreCase))
{
user.IsInitialPassword = (int)InitialPassword.修改;
}
user.Role = _roleService.GetUserRole(user.UserID);
user.Hospital = _hospitalService.GetUserHopital(user.UserID);
......@@ -147,59 +188,12 @@ public ApiResponse<UserResponse> UpdateSelf([CustomizeValidator(RuleSet = "Self"
/// <returns></returns>
[Route("list")]
[HttpPost]
public ApiResponse<List<UserResponse>> List([FromBody] UserRequest request)
public ApiResponse<List<UserResponse>> List([FromBody] UserListRequest request)
{
var userList = _userService.GetUserList(_claim.GetUserId(), request.Role);
return new ApiResponse<List<UserResponse>>(ResponseType.OK, "ok", userList);
}
///// <summary>
///// 新增用户
///// </summary>
///// <param name="request"></param>
///// <returns></returns>
//[Route("insert")]
//[HttpPost]
//public ApiResponse<UserResponse> Insert([CustomizeValidator(RuleSet = "Insert"), FromBody] UserRequest request)
//{
// var userId = _claim.GetUserId();
// var user = _userService.Insert(request, userId);
// user.Role = request.Role;
// return new ApiResponse<UserResponse>(ResponseType.OK, user);
//}
///// <summary>
///// 新增用户
///// </summary>
///// <param name="request"></param>
///// <returns></returns>
//[Route("delete")]
//[HttpPost]
//public ApiResponse Delete([CustomizeValidator(RuleSet = "Delete"), FromBody] UserRequest request)
//{
// return _userService.Delete(request.ID);
//}
///// <summary>
///// 删除用户
///// </summary>
///// <param name="request"></param>
///// <returns></returns>
//[Route("update")]
//[HttpPost]
//public ApiResponse<UserResponse> Update([CustomizeValidator(RuleSet = "Update"), FromBody] UserRequest request)
//{
// var userId = _claim.GetUserId();
// int[] roleArray = new int[] { _options.NurseRole, _options.DirectorRole, _options.SpecialRole, _options.OfficeRole };
// var roles = _roleService.GetUserRole(userId);
// var isAgainAdmin = roles != null ? roleArray.Contains(roles.First().Type ?? 0) : false;
// var user = _userService.Update(request, isAgainAdmin);
// user.Role = request.Role;
// return new ApiResponse<UserResponse>(ResponseType.OK, user);
//}
/// <summary>
/// 修改用户密码
/// </summary>
......@@ -282,16 +276,17 @@ public ApiResponse<JwtToken> DemoUsers(int userId)
}
/// <summary>
/// 修改用户密码
/// 重置密码
/// </summary>
/// <param name="userId">用户id</param>
/// <param name="userId">重置目标用户id</param>
/// <param name="request"></param>
/// <returns></returns>
[Route("reset/{userId}")]
[HttpPost]
public ApiResponse<UserResponse> Password(int userId)
public ApiResponse<UserResponse> Password(int userId, [FromBody] ResetPwdRequest request)
{
var loginUserId = _claim.GetUserId();
var user = _userService.ResetPwd(userId, loginUserId);
var user = _userService.ResetPwd(userId, loginUserId, request.Password);
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
......@@ -316,6 +311,16 @@ public ApiResponse SelfInfos([FromBody] UserRequest request)
user.IsAgainAdmin = user.Role != null ? roleArray.Contains(user.Role.First().Type ?? 0) : false;
else
user.IsAgainAdmin = user.Role != null ? roleArray.Contains(user.Role.First(t => t.RoleID == request.Role).Type ?? 0) : false;
var userClaim = _claim.GetUserClaim();
// 如果用户是快捷登录的,则不需要重置密码
var quickLogin = userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.QuickLogin)?.Value ?? "";
if (quickLogin.Equals(EQuickLogin.YES.ToString(), StringComparison.OrdinalIgnoreCase))
{
user.IsInitialPassword = (int)InitialPassword.修改;
}
return new ApiResponse(ResponseType.OK, user);
}
......@@ -351,7 +356,7 @@ public ApiResponse<UserResponse> UpdateUser([CustomizeValidator(RuleSet = "Updat
}
/// <summary>
/// 新增用户
/// 删除用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
......
......@@ -99,6 +99,7 @@ public static class JwtClaimTypes
public const string AppName = "appname";
public const string Device = "device";
public const string Department = "department";
public const string QuickLogin = "quicklogin";
}
public static class Consts
......
......@@ -7,7 +7,7 @@
},
"AppConnection": {
//"PerformanceConnectionString": "server=112.124.13.17;database=db_performance;uid=suvalue;pwd=suvalue2016;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;",
"PerformanceConnectionString": "server=192.168.18.166;database=db_test_beiliu;uid=root;pwd=1234qwer;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;"
"PerformanceConnectionString": "server=192.168.18.166;database=db_performance_screen;uid=root;pwd=1234qwer;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;"
//"PerformanceConnectionString": "server=116.62.245.55;database=db_performance;uid=root;pwd=1234qwer;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;"
},
"Application": {
......
......@@ -15,7 +15,7 @@
{
"logintype": 2,
"account": "admin",
"password": "1111",
"password": "e10adc3949ba59abbe56e057f20f883e",
"appname": "string",
"device": "web"
}
......@@ -24,6 +24,13 @@
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AccountController.QuickLogin(Performance.DtoModels.ResetPwdRequest)">
<summary>
快速登录
</summary>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AccountController.Refresh">
<summary>
刷新登录JWT TOKEN
......@@ -43,7 +50,7 @@
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AccountController.List(Performance.DtoModels.UserRequest)">
<member name="M:Performance.Api.Controllers.AccountController.List(Performance.DtoModels.UserListRequest)">
<summary>
用户列表
</summary>
......@@ -82,11 +89,12 @@
<param name="userId"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AccountController.Password(System.Int32)">
<member name="M:Performance.Api.Controllers.AccountController.Password(System.Int32,Performance.DtoModels.ResetPwdRequest)">
<summary>
修改用户密码
重置密码
</summary>
<param name="userId">用户id</param>
<param name="userId">重置目标用户id</param>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AccountController.SelfInfos(Performance.DtoModels.UserRequest)">
......
......@@ -14,6 +14,11 @@
返回数据。
</summary>
</member>
<member name="F:Performance.DtoModels.AppConst.InitPwd">
<summary>
初始密码
</summary>
</member>
<member name="T:Performance.DtoModels.AppSettings.AppConnection">
<summary>
数据库连接字符串
......@@ -826,6 +831,31 @@
保底绩效
</summary>
</member>
<member name="P:Performance.DtoModels.PerComputeData.SheetType">
<summary>
sheet模板类型
</summary>
</member>
<member name="P:Performance.DtoModels.PerComputeData.UnitType">
<summary>
核算单元类别 (医生组/护理组)
</summary>
</member>
<member name="P:Performance.DtoModels.PerComputeData.AccountingUnit">
<summary>
核算单元名称
</summary>
</member>
<member name="P:Performance.DtoModels.PerComputeData.TypeName">
<summary>
列头类型名称
</summary>
</member>
<member name="P:Performance.DtoModels.PerComputeData.CellValue">
<summary>
单元格value
</summary>
</member>
<member name="P:Performance.DtoModels.PerData.UnitType">
<summary>
核算单元类别 (医生组/护理组)
......@@ -2449,6 +2479,21 @@
<member name="P:Performance.DtoModels.ReportRequest.AccountingUnit">
<summary> 科室 </summary>
</member>
<member name="P:Performance.DtoModels.ResetPwdRequest.Password">
<summary>
操作人密码
</summary>
</member>
<member name="P:Performance.DtoModels.ResetPwdRequest.CurrentUserId">
<summary>
操作人密码
</summary>
</member>
<member name="P:Performance.DtoModels.ResetPwdRequest.TargetUserId">
<summary>
目标登录人,希望登录的账号ID
</summary>
</member>
<member name="P:Performance.DtoModels.SecondAuditRequest.SecondId">
<summary> 二次绩效Id </summary>
</member>
......@@ -2481,6 +2526,11 @@
提交类型 1 模板提交 2 其他提交
</summary>
</member>
<member name="P:Performance.DtoModels.UserListRequest.Role">
<summary>
角色
</summary>
</member>
<member name="P:Performance.DtoModels.UserRequest.RealName">
<summary>
真实名称
......@@ -4203,6 +4253,11 @@
用户科室
</summary>
</member>
<member name="P:Performance.DtoModels.UserIdentity.IsInitialPassword">
<summary>
初始密码 1 初始 2 改过
</summary>
</member>
<member name="P:Performance.DtoModels.WorkyearResponse.MaxRange">
<summary>
最大工龄范围(小于)
......
......@@ -9188,6 +9188,11 @@
核算序号
</summary>
</member>
<member name="P:Performance.EntityModels.sys_user.IsInitialPassword">
<summary>
初始密码 1 初始 2 改过
</summary>
</member>
<member name="T:Performance.EntityModels.sys_user_hospital">
<summary>
......
namespace Performance.DtoModels
{
public class AppConst
{
/// <summary>
/// 初始密码
/// </summary>
public const string InitPwd = "123456";
}
}
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
......@@ -10,11 +10,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Remove="PerExcel\PerComputeData.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Performance.EntityModels\Performance.EntityModels.csproj" />
<ProjectReference Include="..\Performance.Infrastructure\Performance.Infrastructure.csproj" />
</ItemGroup>
......
namespace Performance.DtoModels
{
public class ResetPwdRequest
{
/// <summary>
/// 操作人密码
/// </summary>
public string Password { get; set; }
/// <summary>
/// 操作人密码
/// </summary>
public int CurrentUserId { get; set; }
/// <summary>
/// 目标登录人,希望登录的账号ID
/// </summary>
public int TargetUserId { get; set; }
public string AppName { get; set; }
public string Device { get; set; }
}
}
namespace Performance.DtoModels
{
public class UserListRequest
{
/// <summary>
/// 角色
/// </summary>
public int Role { get; set; }
}
}
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System;
using FluentValidation;
namespace Performance.DtoModels
{
......@@ -74,7 +71,7 @@ public UserRequestValidator()
{
action();
RuleFor(x => x.RoleArr).NotNull().NotEmpty();
RuleFor(x => x.Password).NotNull().NotEmpty().Length(4, 20);
RuleFor(x => x.Password).NotNull().NotEmpty().Length(4, 64);
RuleFor(x => x.HosIDArray).NotNull().NotEmpty().Must(f => f.Length > 0);
});
......@@ -95,7 +92,7 @@ public UserRequestValidator()
RuleSet("Self", () =>
{
RuleFor(x => x.Password).Length(4, 20);
RuleFor(x => x.Password).Length(4, 64);
//RuleFor(x => x.Mobile).Must((pre) =>
//{
// if (!string.IsNullOrEmpty(pre))
......
......@@ -25,7 +25,10 @@ public class UserIdentity
public string Department { get; set; }
public List<HospitalResponse> Hospital { get; set; }
public List<RoleResponse> Role { get; set; }
/// <summary>
/// 初始密码 1 初始 2 改过
/// </summary>
public int IsInitialPassword { get; set; }
public UserIdentity()
{
Hospital = new List<HospitalResponse>();
......
......@@ -11,7 +11,6 @@ public class UserResponse
public int CreateUser { get; set; }
public string RealName { get; set; }
public string Login { get; set; }
public string Password { get; set; }
public string Mail { get; set; }
public string Mobile { get; set; }
public int States { get; set; }
......
......@@ -83,5 +83,9 @@ public class sys_user
/// 核算序号
/// </summary>
public string UnitCode { get; set; }
/// <summary>
/// 初始密码 1 初始 2 改过
/// </summary>
public int IsInitialPassword { get; set; }
}
}
......@@ -92,3 +92,14 @@ public enum UnitType
[Description("行政工勤")]
行政工勤 = 12,
}
public enum InitialPassword
{
初始 = 1,
修改 = 2,
}
public enum EQuickLogin
{
YES = 1,
NO = 2,
}
using System.Security.Cryptography;
using System.Text;
namespace Performance.Infrastructure
{
public class PwdHelper
{
/// <summary>
/// 一次加密不加盐
/// </summary>
/// <param name="password"></param>
/// <returns></returns>
public static string MD5(string password)
{
return MD5Encrypt(password);
}
/// <summary>
/// 一次加密加盐
/// </summary>
/// <param name="password"></param>
/// <param name="salt"></param>
/// <returns></returns>
public static string MD5AndSalt(string password, string salt = "Suvalue")
{
return MD5Encrypt(password + salt);
}
/// <summary>
/// 两次加密加盐
/// </summary>
/// <param name="password"></param>
/// <param name="salt"></param>
/// <returns></returns>
public static string MD5AndSalt2(string password, string salt = "Suvalue")
{
return MD5Encrypt(MD5Encrypt(password) + salt);
}
/// <summary>
/// 32位MD5加密
/// </summary>
/// <param name="password"></param>
/// <returns></returns>
private static string MD5Encrypt(string password)
{
MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(password));
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));//转化为小写的32进制
}
return sBuilder.ToString();
}
}
}
\ No newline at end of file
......@@ -1353,13 +1353,16 @@ public void SaveQueryRole(int hospitalId, int userId, List<Dictionary<string, st
{
var json = JsonHelper.Serialize(item);
var data = JsonHelper.Deserialize<per_employee>(json);
string pwd = item.ContainsKey("Password") ? item["Password"] : "";
if (hospital.IsOwnerQuery == 1)
{
var isNewRole = !string.IsNullOrEmpty(data.PersonnelNumber?.Trim()) && !string.IsNullOrEmpty(item["Password"]);
var isNewRole = !string.IsNullOrEmpty(data.PersonnelNumber?.Trim()) && !string.IsNullOrEmpty(pwd);
var isRepeat = users.FirstOrDefault(t => t.Login == data.PersonnelNumber?.Trim());
if (isRepeat != null)
{
isRepeat.Password = item["Password"];
isRepeat.Password = PwdHelper.MD5AndSalt2(pwd);
updateUsers.Add(isRepeat);
}
if (isNewRole && isRepeat == null)
......
......@@ -559,7 +559,8 @@ private T GetCellValue<T>(IRow row, List<string> columns, string key)
var data = (from t1 in pdata
join t2 in tdata
on t1.PersonnelNumber equals t2.PersonnelNumber into temp
from t in temp.DefaultIfEmpty() orderby t1.Id descending
from t in temp.DefaultIfEmpty()
orderby t1.Id descending
select new
{
PersonnelNumber = t1.PersonnelNumber,
......@@ -590,7 +591,7 @@ select new
Tag5 = t?.Tag5,
}).Distinct()?.ToList();
if (data == null || !data.Any()) return (result,null);
if (data == null || !data.Any()) return (result, null);
var users = new List<sys_user>();
if (hos?.IsOwnerQuery == 1)
......@@ -613,7 +614,8 @@ select new
select new HandsonCellData(conf.Alias, fst.Value)).ToList();
if (hos?.IsOwnerQuery == 1)
{
var password = users.FirstOrDefault(w => w.Login == item.PersonnelNumber && w.Department == item.AccountingUnit)?.Password ?? "";
//var password = users.FirstOrDefault(w => w.Login == item.PersonnelNumber && w.Department == item.AccountingUnit)?.Password ?? "";
var password = "";
cells.Add(new HandsonCellData("密码", password));
}
......
......@@ -70,6 +70,9 @@ public UserIdentity Login(LoginRequest request)
var user = _userRepository.GetEntity(t => t.Login == request.Account && t.IsDelete == 1);
if (user == null)
throw new PerformanceException($"用户不存在 UserId:{request.Account}");
//MD5小写加密
request.Password = PwdHelper.MD5AndSalt(request.Password);
if (!user.Password.Equals(request.Password, StringComparison.OrdinalIgnoreCase))
throw new PerformanceException($"密码错误");
......@@ -89,6 +92,24 @@ public UserIdentity GetUser(int userId)
return _mapper.Map<UserIdentity>(user);
}
public UserIdentity QuickLogin(int targetUserId, int loginUserId, string password)
{
var loginUser = _userRepository.GetEntity(t => t.ID == loginUserId && t.IsDelete == 1);
if (loginUser == null)
throw new PerformanceException($"您的账号信息有误,请稍后重试!");
if (loginUser.Password != PwdHelper.MD5AndSalt(password))
throw new PerformanceException($"您的密码错误,请重新输入后重试");
var targetUser = _userRepository.GetEntity(t => t.ID == targetUserId && t.IsDelete == 1);
if (targetUser == null)
throw new PerformanceException($"您要登录的用户信息有误,请检查后重试");
var data = _mapper.Map<UserIdentity>(targetUser);
data.Token = Guid.NewGuid().ToString("N");
return data;
}
/// <summary>
/// 获取用户第一个角色
/// </summary>
......@@ -211,57 +232,6 @@ public List<UserResponse> GetUserList(int userID, int roleType = 1)
return result;
}
///// <summary>
///// 删除
///// </summary>
///// <param name="iD"></param>
///// <returns></returns>
//public ApiResponse Delete(int iD)
//{
// var user = _userRepository.GetEntity(t => t.ID == iD && t.IsDelete == 1);
// if (null == user)
// throw new PerformanceException($"用户不存在 UserId:{iD}");
// user.IsDelete = 2;
// var result = _userRepository.Remove(user);
// return result ? new ApiResponse(ResponseType.OK) : new ApiResponse(ResponseType.Fail);
//}
///// <summary>
///// 新增用户
///// </summary>
///// <param name="request"></param>
//public UserResponse Insert(UserRequest request, int userid)
//{
// if (null != _userRepository.GetEntity(t => t.Login == request.Login && t.IsDelete == 1))
// throw new PerformanceException("登录名重复");
// //if (null != _userRepository.GetEntity(t => t.Mobile == request.Mobile && t.IsDelete == 1))
// // throw new PerformanceException("手机号重复");
// //if (request.Role == 3 && string.IsNullOrEmpty(request.Department))
// // throw new PerformanceException("请选择科室");
// if (request.HosIDArray.Length > 1)
// throw new PerformanceException("二次绩效管理员只支持单家医院");
// int[] roleArray = new int[] { application.NurseRole, application.DirectorRole, application.SpecialRole, application.OfficeRole };
// if (roleArray.Contains(request.Role) && string.IsNullOrEmpty(request.Department))
// throw new PerformanceException("二次绩效管理员科室不能为空");
// var user = _mapper.Map<sys_user>(request);
// user.CreateDate = DateTime.Now;
// user.CreateUser = userid;
// user.States = (int)States.Enabled;
// user.Department = request.Department;
// user.IsDelete = 1;
// if (!_userRepository.Add(user))
// throw new PerformanceException("保存失败");
// //添加用户角色关联关系
// _userroleRepository.Add(new sys_user_role { UserID = user.ID, RoleID = request.Role });
// //添加用户医院
// SetHospital(user.ID, request.HosIDArray);
// return _mapper.Map<UserResponse>(user);
//}
/// <summary>
/// 设置用户医院
/// </summary>
......@@ -294,59 +264,6 @@ public bool SetHospital(int userId, int[] hosIDArray)
return rmResult && addResult;
}
///// <summary>
///// 修改用户
///// </summary>
///// <param name="request"></param>
///// <returns></returns>
//public UserResponse Update(UserRequest request, bool isAgainAdmin)
//{
// var user = _userRepository.GetEntity(t => t.ID == request.ID && t.IsDelete == 1);
// if (null == user)
// throw new PerformanceException($"用户不存在 UserId:{request.ID}");
// var vlist = _userRepository.GetEntities(t => t.ID != user.ID && t.Login == request.Login && t.IsDelete == 1);
// if (null != vlist && vlist.Count() > 0)
// throw new PerformanceException("登录名重复");
// var userRole = _userroleRepository.GetEntity(t => t.UserID == request.ID);
// //vlist = _userRepository.GetEntities(t => t.ID != user.ID && t.Mobile == request.Mobile && t.IsDelete == 1);
// //if (null != vlist && vlist.Count() > 0)
// // throw new PerformanceException("手机号重复");
// if (isAgainAdmin && string.IsNullOrEmpty(request.Department))
// throw new PerformanceException("二次绩效管理员科室不能为空");
// if (isAgainAdmin && request.HosIDArray.Length > 1)
// throw new PerformanceException("二次绩效管理员只支持单家医院");
// SaveHistoryDepartment(user.ID, newRoleId: request.Role, newDepartment: request.Department);
// user.Login = request.Login;
// user.Mobile = request.Mobile;
// user.RealName = request.RealName;
// user.Mail = request.Mail;
// user.States = request.States;
// user.Password = string.IsNullOrEmpty(request.Password) ? user.Password : request.Password;
// user.Department = request.Department;
// if (!_userRepository.Update(user))
// throw new PerformanceException("保存失败");
// //删除用户角色关联关系
// if (null != userRole)
// _userroleRepository.Remove(userRole);
// //添加用户角色关联关系
// _userroleRepository.Add(new sys_user_role { UserID = request.ID, RoleID = request.Role });
// //添加用户医院
// SetHospital(user.ID, request.HosIDArray);
// return _mapper.Map<UserResponse>(user);
//}
/// <summary>
/// 修改个人信息
......@@ -370,7 +287,6 @@ public UserResponse UpdateSelf(UserRequest request)
user.Mobile = string.IsNullOrEmpty(request.RealName) ? user.Mobile : request.Mobile;
user.RealName = string.IsNullOrEmpty(request.RealName) ? user.RealName : request.RealName;
user.Mail = string.IsNullOrEmpty(request.Mail) ? user.Mail : request.Mail;
user.Password = string.IsNullOrEmpty(request.Password) ? user.Password : request.Password;
if (!_userRepository.Update(user))
throw new PerformanceException("保存失败");
......@@ -388,11 +304,17 @@ public UserResponse UpdatePwd(PasswordRequest request, int userId)
var user = _userRepository.GetEntity(t => t.ID == userId && t.IsDelete == 1);
if (null == user)
throw new PerformanceException($"用户不存在 UserId:{userId}");
if (string.IsNullOrEmpty(request.NewPwd))
throw new PerformanceException($"新密码错误");
//MD5小写加密
request.OldPwd = PwdHelper.MD5AndSalt(request.OldPwd);
if (request.OldPwd != user.Password)
throw new PerformanceException("原密码错误");
user.Password = string.IsNullOrEmpty(request.NewPwd) ? user.Password : request.NewPwd;
//Md5小写加密
user.Password = PwdHelper.MD5AndSalt(request.NewPwd);
user.IsInitialPassword = (int)InitialPassword.修改;
if (!_userRepository.Update(user))
throw new PerformanceException("保存失败");
......@@ -487,16 +409,22 @@ public UserIdentity GetDemoUserIdentity(int userId)
/// <param name="userId"></param>
/// <param name="loginUserId"></param>
/// <returns></returns>
public UserResponse ResetPwd(int userId, int loginUserId)
public UserResponse ResetPwd(int userId, int loginUserId, string password)
{
var user = _userRepository.GetEntity(t => t.ID == userId && t.IsDelete == 1);
if (user == null)
throw new PerformanceException($"用户不存在 UserId:{userId}");
//if (user.CreateUser != loginUserId)
// throw new PerformanceException($"当前用户无权限重置用户密码");
var loginUser = _userRepository.GetEntity(t => t.ID == loginUserId);
if (loginUser == null)
throw new PerformanceException($"用户不存在!");
if (loginUser.Password != PwdHelper.MD5AndSalt(password))
throw new PerformanceException($"您的密码错误,请重新输入后重试");
user.Password = "123456";
//MD5小写加密
user.Password = PwdHelper.MD5AndSalt2(AppConst.InitPwd);
user.IsInitialPassword = (int)InitialPassword.初始; // 初始密码强制修改
if (!_userRepository.Update(user))
throw new PerformanceException("重置失败");
return _mapper.Map<UserResponse>(user);
......@@ -520,7 +448,9 @@ public UserResponse InsertUser(UserRequest request, int userid)
var user = _mapper.Map<sys_user>(request);
user.CreateDate = DateTime.Now;
user.CreateUser = userid;
user.Password = PwdHelper.MD5AndSalt(request.Password);
user.States = (int)States.Enabled;
user.IsInitialPassword = (int)InitialPassword.初始;
user.Department = UnitTypeUtil.Maps.ContainsKey(request.RoleArr[0]) ? request.Department : "";
if (UnitTypeUtil.Maps.ContainsKey(request.RoleArr[0]))
{
......@@ -591,7 +521,8 @@ public UserResponse UpdateUser(UserRequest request, int userId)
user.RealName = request.RealName;
user.Mail = request.Mail;
user.States = request.States;
user.Password = string.IsNullOrEmpty(request.Password) ? user.Password : request.Password;
//Md5小写加密
user.Password = string.IsNullOrEmpty(request.Password) ? user.Password : PwdHelper.MD5AndSalt(request.Password);
user.Department = UnitTypeUtil.Maps.ContainsKey(request.RoleArr[0]) ? request.Department : "";
if (UnitTypeUtil.Maps.ContainsKey(request.RoleArr[0]))
{
......@@ -642,7 +573,8 @@ public UserResponse UpdateUser(UserRequest request, int userId)
diffUser.RealName = request.RealName;
diffUser.Mail = request.Mail;
diffUser.States = request.States;
diffUser.Password = string.IsNullOrEmpty(request.Password) ? user.Password : request.Password;
//Md5小写加密
diffUser.Password = string.IsNullOrEmpty(request.Password) ? user.Password : PwdHelper.MD5AndSalt(request.Password);
diffUser.Department = UnitTypeUtil.Maps.ContainsKey(request.RoleArr[i]) ? request.Department : "";
if (UnitTypeUtil.Maps.ContainsKey(request.RoleArr[i]))
{
......@@ -757,7 +689,7 @@ public ApiResponse SaveUserHandsFlat(UserCollectData request)
{ "登录名", allDataList[i].RealName ?? "" },
{ "角色", allDataList[i].RoleName ?? "" },
{ "分配医院", allDataList[i].HosName ?? "" },
{ "核算单元", allDataList[i].Department.ToString() ?? "" },
{ "核算单元", allDataList[i].Department ?? "" },
{ "错误原因", "“关键信息缺失”请补全或删除" },
});
continue;
......@@ -771,7 +703,7 @@ public ApiResponse SaveUserHandsFlat(UserCollectData request)
{ "登录名", allDataList[i].RealName ?? "" },
{ "角色", allDataList[i].RoleName ?? "" },
{ "分配医院", allDataList[i].HosName ?? "" },
{ "核算单元", allDataList[i].Department.ToString() ?? "" },
{ "核算单元", allDataList[i].Department ?? "" },
{ "错误原因", "“角色”错误,请修改或删除" },
});
}
......@@ -784,7 +716,7 @@ public ApiResponse SaveUserHandsFlat(UserCollectData request)
{ "登录名", allDataList[i].RealName ?? "" },
{ "角色", allDataList[i].RoleName ?? "" },
{ "分配医院", allDataList[i].HosName ?? "" },
{ "核算单元", allDataList[i].Department.ToString() ?? "" },
{ "核算单元", allDataList[i].Department ?? "" },
{ "错误原因", "“分配医院”错误,请修改或删除" },
});
}
......@@ -844,10 +776,11 @@ public ApiResponse SaveUserHandsFlat(UserCollectData request)
UnitCode = cts?.Code ?? "",
IsDelete = 1,
Login = data.Login,
Password = data?.Password ?? "123456",
Password = PwdHelper.MD5AndSalt2(AppConst.InitPwd),
States = 1,
Mobile = data?.Mobile ?? "",
Mail = data?.Mail ?? ""
Mail = data?.Mail ?? "",
IsInitialPassword = (int)InitialPassword.初始,
};
users.Add(user);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment