匿名修改账户信息
parent
1e42352a59
commit
fe62c051d7
|
@ -1027,7 +1027,7 @@
|
|||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Services.TrialMaintenanceService.TrialSiteUserListExport(System.Guid,System.Boolean,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.CommonDocument},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialSiteSurvey},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TrialSiteUserSurvey})">
|
||||
<summary>
|
||||
|
||||
Site用户列表导出
|
||||
</summary>
|
||||
<param name="trialId"></param>
|
||||
<param name="isAllSiteUser">isAllSiteUser true : site用户列表,false :Site调研汇总表</param>
|
||||
|
@ -2033,24 +2033,37 @@
|
|||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Application.Services.UserService.SendVerificationCode(System.String)">
|
||||
<summary>发送验证码 邮箱或者手机号 New </summary>
|
||||
<summary>发送验证码 修改邮箱(已经登陆修改) New </summary>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Application.Services.UserService.SendVerificationCode(System.String,IRaCIS.Core.Domain.Share.VerifyType,System.Boolean)">
|
||||
<member name="M:IRaCIS.Application.Services.UserService.ResetPassword(System.Guid)">
|
||||
<summary>
|
||||
发送验证码 邮箱或者手机号
|
||||
重置密码为 默认密码
|
||||
</summary>
|
||||
<param name="emailOrPhone"></param>
|
||||
<param name="verificationType"></param>
|
||||
<param name="isReviewer"></param>
|
||||
<param name="userId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Application.Services.UserService.SetNewPassword(IRaCIS.Application.Contracts.ResetPasswordCommand)">
|
||||
<member name="M:IRaCIS.Application.Services.UserService.ModifyPassword(IRaCIS.Application.Contracts.EditPasswordCommand)">
|
||||
<summary>
|
||||
验证设置新密码
|
||||
修改密码,当前支持旧密码修改密码
|
||||
</summary>
|
||||
<param name="resetPwdModel"></param>
|
||||
<param name="editPwModel"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Application.Services.UserService.SendVerificationCode(System.String,System.String)">
|
||||
<summary>
|
||||
重置密码发邮件 (未登陆修改)
|
||||
</summary>
|
||||
<param name="email"></param>
|
||||
<param name="userName"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Application.Services.UserService.SetNewPassword(IRaCIS.Application.Contracts.AllowAnonymousResetPasswordCommand)">
|
||||
<summary>
|
||||
接受验证码 设置新密码 (未登陆修改)
|
||||
</summary>
|
||||
<param name="resetPwdModel"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Application.Services.UserService.GetUserList(IRaCIS.Application.Contracts.UserListQueryDTO)">
|
||||
<summary>
|
||||
获取用户列表
|
||||
|
@ -2094,20 +2107,6 @@
|
|||
<param name="state"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Application.Services.UserService.ResetPassword(System.Guid)">
|
||||
<summary>
|
||||
重置密码为 默认密码
|
||||
</summary>
|
||||
<param name="userId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Application.Services.UserService.ModifyPassword(IRaCIS.Application.Contracts.EditPasswordCommand)">
|
||||
<summary>
|
||||
修改密码,当前支持旧密码修改密码,手机及邮箱验证码后续支持[New]
|
||||
</summary>
|
||||
<param name="editPwModel"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Application.Services.UserService.Login(System.String,System.String)">
|
||||
<summary>
|
||||
用户登陆
|
||||
|
@ -2116,6 +2115,22 @@
|
|||
<param name="password"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Application.Services.UserService.SendVerificationCode(System.String,IRaCIS.Core.Domain.Share.VerifyType,System.Boolean)">
|
||||
<summary>
|
||||
发送验证码 邮箱或者手机号
|
||||
</summary>
|
||||
<param name="emailOrPhone"></param>
|
||||
<param name="verificationType"></param>
|
||||
<param name="isReviewer"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Application.Services.UserService.SetNewPassword(IRaCIS.Application.Contracts.ResetPasswordCommand)">
|
||||
<summary>
|
||||
验证设置新密码
|
||||
</summary>
|
||||
<param name="resetPwdModel"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:IRaCIS.Application.Services.StatisticsService">
|
||||
<summary>
|
||||
Dashboard统计、全局工作量统计、入组两个维度统计(按照项目、按照人)
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace IRaCIS.Application.Services
|
|||
//收件地址
|
||||
messageToSend.To.Add(new MailboxAddress(userName, emailAddress));
|
||||
//主题
|
||||
messageToSend.Subject = "Reset PassWord (Verification Code)";
|
||||
messageToSend.Subject = "Reset email (Verification Code)";
|
||||
|
||||
messageToSend.Body = new TextPart("plain")
|
||||
{
|
||||
|
|
|
@ -208,6 +208,19 @@ namespace IRaCIS.Application.Contracts
|
|||
public Guid UserId { get; set; }
|
||||
public IEnumerable<RoleDTO> RoleList { get; set; }=new List<RoleDTO>();
|
||||
}
|
||||
|
||||
|
||||
public class AllowAnonymousResetPasswordCommand
|
||||
{
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
public string VerificationCode { get; set; } = string.Empty;
|
||||
|
||||
public string NewPwd { get; set; } = string.Empty;
|
||||
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class ResetPasswordCommand
|
||||
{
|
||||
public string EmailOrPhone { get; set; } = string.Empty;
|
||||
|
|
|
@ -10,6 +10,7 @@ using IRaCIS.Core.API.Utility.AOP;
|
|||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Panda.DynamicWebApi.Attributes;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace IRaCIS.Application.Services
|
||||
{
|
||||
|
@ -38,7 +39,7 @@ namespace IRaCIS.Application.Services
|
|||
_userTrialRepository = userTrialRepository;
|
||||
}
|
||||
|
||||
/// <summary>发送验证码 邮箱或者手机号 New </summary>
|
||||
/// <summary>发送验证码 修改邮箱(已经登陆修改) New </summary>
|
||||
|
||||
[HttpGet("{email}")]
|
||||
public async Task<IResponseOutput> SendVerificationCode(string email)
|
||||
|
@ -66,15 +67,14 @@ namespace IRaCIS.Application.Services
|
|||
//验证码 6位
|
||||
int verificationCode = new Random().Next(100000, 1000000);
|
||||
|
||||
await _mailVerificationService.SendMailEditEmail(_userInfo.Id, _userInfo.RealName , email, verificationCode);
|
||||
await _mailVerificationService.SendMailEditEmail(_userInfo.Id, _userInfo.RealName, email, verificationCode);
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
|
||||
}
|
||||
|
||||
|
||||
[HttpPut("{newEmail}/{verificationCode}")]
|
||||
public async Task<IResponseOutput> SetNewEmail( string newEmail,string verificationCode)
|
||||
public async Task<IResponseOutput> SetNewEmail(string newEmail, string verificationCode)
|
||||
{
|
||||
|
||||
|
||||
|
@ -103,18 +103,18 @@ namespace IRaCIS.Application.Services
|
|||
//var count = _doctorRepository.Update<Doctor>().Where(t => t.Id == doctor.Id).Set(d => d.Password == pwd).ExecuteAffrows();
|
||||
|
||||
|
||||
if (await _userRepository.AnyAsync(t => (t.EMail == newEmail && t.UserTypeId == _userInfo.UserTypeId && t.Id != _userInfo.Id)))
|
||||
if (await _userRepository.AnyAsync(t => (t.EMail == newEmail && t.UserTypeId == _userInfo.UserTypeId && t.Id != _userInfo.Id)))
|
||||
{
|
||||
return ResponseOutput.NotOk("The mailbox for this user type already exists");
|
||||
}
|
||||
|
||||
var success = await _userRepository.UpdateFromQueryAsync(t => t.Id == _userInfo.Id, u => new User()
|
||||
{
|
||||
EMail= newEmail
|
||||
EMail = newEmail
|
||||
});
|
||||
|
||||
//删除验证码历史记录
|
||||
await _verificationCodeRepository.DeleteFromQueryAsync(t => t.UserId == _userInfo.Id && t.CodeType ==0);
|
||||
await _verificationCodeRepository.DeleteFromQueryAsync(t => t.UserId == _userInfo.Id && t.CodeType == 0);
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
|
||||
|
@ -124,7 +124,7 @@ namespace IRaCIS.Application.Services
|
|||
|
||||
|
||||
[HttpPut("{newPhone}")]
|
||||
public async Task<IResponseOutput> SetNewPhone( string newPhone)
|
||||
public async Task<IResponseOutput> SetNewPhone(string newPhone)
|
||||
{
|
||||
|
||||
|
||||
|
@ -138,7 +138,7 @@ namespace IRaCIS.Application.Services
|
|||
|
||||
|
||||
[HttpPut("{newUserName}")]
|
||||
public async Task<IResponseOutput> SetNewUserName( string newUserName)
|
||||
public async Task<IResponseOutput> SetNewUserName(string newUserName)
|
||||
{
|
||||
|
||||
if (await _userRepository.AnyAsync(t => t.UserName == newUserName && t.Id != _userInfo.Id))
|
||||
|
@ -154,9 +154,363 @@ namespace IRaCIS.Application.Services
|
|||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重置密码为 默认密码
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{userId:guid}")]
|
||||
|
||||
public async Task<IResponseOutput> ResetPassword(Guid userId)
|
||||
{
|
||||
var success = await _userRepository.UpdateFromQueryAsync(t => t.Id == userId, u => new User()
|
||||
{
|
||||
Password = MD5Helper.Md5(StaticData.DefaultPassword),
|
||||
PasswordChanged = false
|
||||
});
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改密码,当前支持旧密码修改密码
|
||||
/// </summary>
|
||||
/// <param name="editPwModel"><
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IResponseOutput> ModifyPassword(EditPasswordCommand editPwModel)
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(editPwModel.NewUserName))
|
||||
{
|
||||
if (await _userRepository.AnyAsync(t => t.UserName == editPwModel.NewUserName && t.Id != _userInfo.Id))
|
||||
{
|
||||
return ResponseOutput.NotOk("UserId already exists");
|
||||
}
|
||||
|
||||
var success = await _userRepository.UpdateFromQueryAsync(t => t.Id == _userInfo.Id, u => new User()
|
||||
{
|
||||
UserName = editPwModel.NewUserName,
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//验证旧密码OK
|
||||
if (await _userRepository.FirstOrDefaultAsync(t => t.Id == _userInfo.Id && t.Password == editPwModel.OldPassWord) != null)
|
||||
{
|
||||
var success = await _userRepository.UpdateFromQueryAsync(t => t.Id == _userInfo.Id, u => new User()
|
||||
{
|
||||
Password = editPwModel.NewPassWord,
|
||||
IsFirstAdd = false
|
||||
});
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
}
|
||||
|
||||
//医生密码
|
||||
if (await _doctorRepository.AnyAsync(t => t.Id == _userInfo.Id && t.Password == editPwModel.OldPassWord))
|
||||
{
|
||||
var success = await _doctorRepository.UpdateFromQueryAsync(t => t.Id == _userInfo.Id, u => new Doctor()
|
||||
{
|
||||
|
||||
Password = editPwModel.NewPassWord
|
||||
});
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
}
|
||||
|
||||
return ResponseOutput.NotOk("Old password is wrong.");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重置密码发邮件 (未登陆修改)
|
||||
/// </summary>
|
||||
/// <param name="email"></param>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("{email}/{userName}")]
|
||||
public async Task<IResponseOutput> SendVerificationCode(string email,string userName)
|
||||
{
|
||||
|
||||
//检查手机或者邮箱是否有效
|
||||
if (!Regex.IsMatch(email, @"^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$"))
|
||||
{
|
||||
|
||||
return ResponseOutput.NotOk("Please input a legal email");
|
||||
|
||||
}
|
||||
|
||||
////查找改邮箱或者手机的用户
|
||||
var exist = await _userRepository.AnyAsync(t => t.EMail == email&& t.UserName == userName);
|
||||
|
||||
if (!exist)
|
||||
{
|
||||
return ResponseOutput.NotOk("User Id or Email not correct");
|
||||
|
||||
}
|
||||
var user = await _userRepository.FirstOrDefaultAsync(t => t.EMail == email);
|
||||
|
||||
|
||||
//验证码 6位
|
||||
int verificationCode = new Random().Next(100000, 1000000);
|
||||
|
||||
await _mailVerificationService.SendMail(user.Id, _userInfo.RealName, email, verificationCode);
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///接受验证码 设置新密码 (未登陆修改)
|
||||
/// </summary>
|
||||
/// <param name="resetPwdModel"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public async Task<IResponseOutput> SetNewPassword(AllowAnonymousResetPasswordCommand resetPwdModel)
|
||||
{
|
||||
|
||||
var user = await _userRepository.FirstOrDefaultAsync(t => t.EMail == resetPwdModel.Email && t.UserName == resetPwdModel.UserName);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
return ResponseOutput.NotOk("User Id or Email not correct");
|
||||
}
|
||||
|
||||
|
||||
var verificationRecord = await _verificationCodeRepository
|
||||
.FirstOrDefaultAsync(t => t.UserId == user.Id && t.Code == resetPwdModel.VerificationCode && t.CodeType == VerifyType.Email);
|
||||
|
||||
//检查数据库是否存在该验证码
|
||||
if (verificationRecord == null)
|
||||
{
|
||||
|
||||
return ResponseOutput.NotOk("Verification code error");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//检查验证码是否失效
|
||||
if (verificationRecord.ExpirationTime < DateTime.Now)
|
||||
{
|
||||
return ResponseOutput.NotOk("The verification code has expired");
|
||||
|
||||
}
|
||||
else //验证码正确 并且 没有超时
|
||||
{
|
||||
//更新密码
|
||||
//var pwd = MD5Helper.Md5(newPwd);
|
||||
//var count = _doctorRepository.Update<Doctor>().Where(t => t.Id == doctor.Id).Set(d => d.Password == pwd).ExecuteAffrows();
|
||||
|
||||
var success = await _userRepository.UpdateFromQueryAsync(t => t.Id == user.Id, u => new User()
|
||||
{
|
||||
Password = resetPwdModel.NewPwd,
|
||||
PasswordChanged = true
|
||||
});
|
||||
|
||||
//删除验证码历史记录
|
||||
await _verificationCodeRepository.DeleteFromQueryAsync(t => t.UserId == user.Id && t.CodeType == VerifyType.Email);
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户列表
|
||||
/// </summary>
|
||||
/// <param name="param"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<PageOutput<UserListDTO>> GetUserList(UserListQueryDTO param)
|
||||
{
|
||||
var userQueryable = _userRepository.Where(x => x.UserTypeEnum != UserTypeEnum.SuperAdmin)
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(param.UserName), t => t.UserName.Contains(param.UserName) || (t.LastName + ' ' + t.FirstName).Contains(param.UserName))
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(param.Phone), t => t.Phone.Contains(param.Phone))
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(param.OrganizationName), t => t.OrganizationName.Contains(param.OrganizationName))
|
||||
.WhereIf(param.UserType != null, t => t.UserTypeId == param.UserType)
|
||||
.WhereIf(param.UserState != null, t => t.Status == param.UserState)
|
||||
.ProjectTo<UserListDTO>(_mapper.ConfigurationProvider);
|
||||
|
||||
return await userQueryable.ToPagedListAsync(param.PageIndex, param.PageSize, param.SortField == string.Empty ? "UserName" : param.SortField, param.Asc);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户Id获取用户详细信息[New]
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id:guid}")]
|
||||
public async Task<UserDetailDTO> GetUser(Guid id)
|
||||
{
|
||||
var userQuery = _userRepository.Where(t => t.Id == id).ProjectTo<UserDetailDTO>(_mapper.ConfigurationProvider);
|
||||
return await (userQuery.FirstOrDefaultAsync()).IfNullThrowException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加用户
|
||||
/// </summary>
|
||||
/// <param name="userAddModel"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IResponseOutput<UserAddedReturnDTO>> AddUser(UserCommand userAddModel)
|
||||
{
|
||||
if (await _userRepository.AnyAsync(t => t.UserName == userAddModel.UserName || (t.EMail == userAddModel.EMail && t.UserTypeId == userAddModel.UserTypeId)))
|
||||
{
|
||||
return ResponseOutput.NotOk(" UserId or The mailbox for this user type already exists", new UserAddedReturnDTO());
|
||||
}
|
||||
|
||||
var saveItem = _mapper.Map<User>(userAddModel);
|
||||
|
||||
saveItem.Code = await _userRepository.Select(t => t.Code).DefaultIfEmpty().MaxAsync() + 1;
|
||||
|
||||
saveItem.UserCode = AppSettings.UserCodePrefix + saveItem.Code.ToString("D4");
|
||||
|
||||
if (saveItem.IsZhiZhun)
|
||||
{
|
||||
saveItem.OrganizationName = "Zhizhun";
|
||||
}
|
||||
|
||||
//验证码 6位
|
||||
int verificationCode = new Random().Next(100000, 1000000);
|
||||
|
||||
saveItem.Password = MD5Helper.Md5("123456");
|
||||
|
||||
await _userRepository.AddAsync(saveItem);
|
||||
|
||||
var success = await _userRepository.SaveChangesAsync();
|
||||
|
||||
return ResponseOutput.Result(success, new UserAddedReturnDTO { Id = saveItem.Id, UserCode = saveItem.UserCode, VerificationCode = verificationCode });
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IResponseOutput> UpdateUser(UserCommand model)
|
||||
{
|
||||
|
||||
// 判断当前用户名是否已经存在
|
||||
if (await _userRepository.AnyAsync(t => (t.UserName == model.UserName && t.Id != model.Id) || (t.EMail == model.EMail && t.UserTypeId == model.UserTypeId && t.Id != model.Id)))
|
||||
{
|
||||
return ResponseOutput.NotOk("UserId or The mailbox for this user type already exists");
|
||||
}
|
||||
|
||||
var user = await _userRepository.FirstOrDefaultAsync(t => t.Id == model.Id);
|
||||
|
||||
if (user == null) return Null404NotFound(user);
|
||||
|
||||
_mapper.Map(model, user);
|
||||
|
||||
if (user.IsZhiZhun)
|
||||
{
|
||||
user.OrganizationName = "Zhizhun";
|
||||
}
|
||||
var success = await _userRepository.SaveChangesAsync();
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{userId:guid}")]
|
||||
public async Task<IResponseOutput> DeleteUser(Guid userId)
|
||||
{
|
||||
if (await _userTrialRepository.AnyAsync(t => t.Id == userId))
|
||||
{
|
||||
return ResponseOutput.NotOk("This user has participated in the trial and couldn't be deleted");
|
||||
}
|
||||
|
||||
var success = await _userRepository.DeleteFromQueryAsync(t => t.Id == userId);
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 禁用或者启用账户
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="state"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpPost("{userId:guid}/{state:int}")]
|
||||
public async Task<IResponseOutput> UpdateUserState(Guid userId, UserStateEnum state)
|
||||
{
|
||||
var success = await _userRepository.UpdateFromQueryAsync(u => u.Id == userId, t => new User
|
||||
{
|
||||
Status = state
|
||||
});
|
||||
return ResponseOutput.Result(success);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 用户登陆
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
[NonDynamicMethod]
|
||||
public async Task<IResponseOutput<LoginReturnDTO>> Login(string userName, string password)
|
||||
{
|
||||
var userLoginReturnModel = new LoginReturnDTO();
|
||||
|
||||
|
||||
var loginUser = await _userRepository.Where(u => u.UserName == userName && u.Password == password).ProjectTo<UserBasicInfo>(_mapper.ConfigurationProvider).FirstOrDefaultAsync();
|
||||
|
||||
if (loginUser == null)
|
||||
{
|
||||
//此处下面 代码 为了支持医生也能登录 而且前端不加选择到底是管理用户 还是医生用户 奇怪的需求 无法理解
|
||||
|
||||
var loginDoctor = await _doctorRepository.Where(u => u.Phone == userName && u.Password == password).ProjectTo<UserBasicInfo>(_mapper.ConfigurationProvider).FirstOrDefaultAsync();
|
||||
|
||||
if (loginDoctor == null)
|
||||
{
|
||||
return ResponseOutput.NotOk("Please check the user name or password.", new LoginReturnDTO());
|
||||
|
||||
}
|
||||
|
||||
userLoginReturnModel.BasicInfo = loginDoctor;
|
||||
|
||||
|
||||
return ResponseOutput.Ok(userLoginReturnModel);
|
||||
|
||||
}
|
||||
|
||||
if (loginUser.Status == 0)
|
||||
{
|
||||
return ResponseOutput.NotOk("The user has been disabled!", new LoginReturnDTO());
|
||||
}
|
||||
|
||||
userLoginReturnModel.BasicInfo = loginUser;
|
||||
|
||||
|
||||
return ResponseOutput.Ok(userLoginReturnModel);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发送验证码 邮箱或者手机号
|
||||
|
@ -166,6 +520,7 @@ namespace IRaCIS.Application.Services
|
|||
/// <param name="isReviewer"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{emailOrPhone}/{verificationType:int}")]
|
||||
[Obsolete]
|
||||
public async Task<IResponseOutput> SendVerificationCode(string emailOrPhone, VerifyType verificationType, bool isReviewer = false)
|
||||
{
|
||||
if (string.IsNullOrEmpty(emailOrPhone))
|
||||
|
@ -249,13 +604,14 @@ namespace IRaCIS.Application.Services
|
|||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 验证设置新密码
|
||||
/// </summary>
|
||||
/// <param name="resetPwdModel"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
|
||||
[Obsolete]
|
||||
public async Task<IResponseOutput> SetNewPassword(ResetPasswordCommand resetPwdModel)
|
||||
{
|
||||
if (resetPwdModel.IsReviewer)
|
||||
|
@ -347,271 +703,5 @@ namespace IRaCIS.Application.Services
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户列表
|
||||
/// </summary>
|
||||
/// <param name="param"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<PageOutput<UserListDTO>> GetUserList(UserListQueryDTO param)
|
||||
{
|
||||
var userQueryable = _userRepository.Where(x => x.UserTypeEnum != UserTypeEnum.SuperAdmin)
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(param.UserName), t => t.UserName.Contains(param.UserName) || (t.LastName + ' ' + t.FirstName).Contains(param.UserName))
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(param.Phone), t => t.Phone.Contains(param.Phone))
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(param.OrganizationName), t => t.OrganizationName.Contains(param.OrganizationName))
|
||||
.WhereIf(param.UserType != null, t => t.UserTypeId == param.UserType)
|
||||
.WhereIf(param.UserState != null, t => t.Status == param.UserState)
|
||||
.ProjectTo<UserListDTO>(_mapper.ConfigurationProvider);
|
||||
|
||||
return await userQueryable.ToPagedListAsync(param.PageIndex, param.PageSize, param.SortField == string.Empty ? "UserName" : param.SortField, param.Asc);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户Id获取用户详细信息[New]
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id:guid}")]
|
||||
public async Task<UserDetailDTO> GetUser(Guid id)
|
||||
{
|
||||
var userQuery = _userRepository.Where(t => t.Id == id).ProjectTo<UserDetailDTO>(_mapper.ConfigurationProvider);
|
||||
return await (userQuery.FirstOrDefaultAsync()).IfNullThrowException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加用户
|
||||
/// </summary>
|
||||
/// <param name="userAddModel"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IResponseOutput<UserAddedReturnDTO>> AddUser(UserCommand userAddModel)
|
||||
{
|
||||
if (await _userRepository.AnyAsync(t => t.UserName == userAddModel.UserName ||(t.EMail == userAddModel.EMail && t.UserTypeId == userAddModel.UserTypeId)))
|
||||
{
|
||||
return ResponseOutput.NotOk(" UserId or The mailbox for this user type already exists", new UserAddedReturnDTO());
|
||||
}
|
||||
|
||||
var saveItem = _mapper.Map<User>(userAddModel);
|
||||
|
||||
saveItem.Code = await _userRepository.Select(t => t.Code).DefaultIfEmpty().MaxAsync() + 1;
|
||||
|
||||
saveItem.UserCode = AppSettings.UserCodePrefix + saveItem.Code.ToString("D4");
|
||||
|
||||
if (saveItem.IsZhiZhun)
|
||||
{
|
||||
saveItem.OrganizationName = "Zhizhun";
|
||||
}
|
||||
|
||||
//验证码 6位
|
||||
int verificationCode = new Random().Next(100000, 1000000);
|
||||
|
||||
saveItem.Password = MD5Helper.Md5("123456");
|
||||
|
||||
await _userRepository.AddAsync(saveItem);
|
||||
|
||||
var success = await _userRepository.SaveChangesAsync();
|
||||
|
||||
return ResponseOutput.Result(success, new UserAddedReturnDTO { Id = saveItem.Id, UserCode = saveItem.UserCode, VerificationCode = verificationCode });
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IResponseOutput> UpdateUser(UserCommand model)
|
||||
{
|
||||
|
||||
// 判断当前用户名是否已经存在
|
||||
if (await _userRepository.AnyAsync(t => (t.UserName == model.UserName && t.Id != model.Id) || (t.EMail == model.EMail && t.UserTypeId==model.UserTypeId && t.Id != model.Id)))
|
||||
{
|
||||
return ResponseOutput.NotOk("UserId or The mailbox for this user type already exists");
|
||||
}
|
||||
|
||||
var user = await _userRepository.FirstOrDefaultAsync(t => t.Id == model.Id);
|
||||
|
||||
if (user == null) return Null404NotFound(user);
|
||||
|
||||
_mapper.Map(model, user);
|
||||
|
||||
if (user.IsZhiZhun)
|
||||
{
|
||||
user.OrganizationName = "Zhizhun";
|
||||
}
|
||||
var success = await _userRepository.SaveChangesAsync();
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{userId:guid}")]
|
||||
public async Task<IResponseOutput> DeleteUser(Guid userId)
|
||||
{
|
||||
if (await _userTrialRepository.AnyAsync(t => t.Id == userId))
|
||||
{
|
||||
return ResponseOutput.NotOk("This user has participated in the trial and couldn't be deleted");
|
||||
}
|
||||
|
||||
var success = await _userRepository.DeleteFromQueryAsync(t => t.Id == userId);
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 禁用或者启用账户
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="state"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpPost("{userId:guid}/{state:int}")]
|
||||
public async Task<IResponseOutput> UpdateUserState(Guid userId, UserStateEnum state)
|
||||
{
|
||||
var success = await _userRepository.UpdateFromQueryAsync(u => u.Id == userId, t => new User
|
||||
{
|
||||
Status = state
|
||||
});
|
||||
return ResponseOutput.Result(success);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置密码为 默认密码
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{userId:guid}")]
|
||||
|
||||
public async Task<IResponseOutput> ResetPassword(Guid userId)
|
||||
{
|
||||
var success = await _userRepository.UpdateFromQueryAsync(t => t.Id == userId, u => new User()
|
||||
{
|
||||
Password = MD5Helper.Md5(StaticData.DefaultPassword),
|
||||
PasswordChanged = false
|
||||
});
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改密码,当前支持旧密码修改密码,手机及邮箱验证码后续支持[New]
|
||||
/// </summary>
|
||||
/// <param name="editPwModel"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IResponseOutput> ModifyPassword(EditPasswordCommand editPwModel)
|
||||
{
|
||||
|
||||
|
||||
if( !string.IsNullOrEmpty(editPwModel.NewUserName))
|
||||
{
|
||||
if (await _userRepository.AnyAsync(t => t.UserName == editPwModel.NewUserName && t.Id != _userInfo.Id))
|
||||
{
|
||||
return ResponseOutput.NotOk("UserId already exists");
|
||||
}
|
||||
|
||||
var success = await _userRepository.UpdateFromQueryAsync(t => t.Id == _userInfo.Id, u => new User()
|
||||
{
|
||||
UserName = editPwModel.NewUserName,
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//验证旧密码OK
|
||||
if (await _userRepository.FirstOrDefaultAsync(t => t.Id == _userInfo.Id && t.Password == editPwModel.OldPassWord) != null)
|
||||
{
|
||||
var success = await _userRepository.UpdateFromQueryAsync(t => t.Id == _userInfo.Id, u => new User()
|
||||
{
|
||||
Password = editPwModel.NewPassWord,
|
||||
IsFirstAdd = false
|
||||
});
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
}
|
||||
|
||||
//医生密码
|
||||
if (await _doctorRepository.AnyAsync(t => t.Id == _userInfo.Id && t.Password == editPwModel.OldPassWord))
|
||||
{
|
||||
var success = await _doctorRepository.UpdateFromQueryAsync(t => t.Id == _userInfo.Id, u => new Doctor()
|
||||
{
|
||||
|
||||
Password = editPwModel.NewPassWord
|
||||
});
|
||||
|
||||
return ResponseOutput.Result(success);
|
||||
}
|
||||
|
||||
return ResponseOutput.NotOk("Old password is wrong.");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 用户登陆
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
[NonDynamicMethod]
|
||||
public async Task<IResponseOutput<LoginReturnDTO>> Login(string userName, string password)
|
||||
{
|
||||
var userLoginReturnModel = new LoginReturnDTO();
|
||||
|
||||
|
||||
var loginUser = await _userRepository.Where(u => u.UserName == userName && u.Password == password).ProjectTo<UserBasicInfo>(_mapper.ConfigurationProvider).FirstOrDefaultAsync();
|
||||
|
||||
if (loginUser == null)
|
||||
{
|
||||
//此处下面 代码 为了支持医生也能登录 而且前端不加选择到底是管理用户 还是医生用户 奇怪的需求 无法理解
|
||||
|
||||
var loginDoctor = await _doctorRepository.Where(u => u.Phone == userName && u.Password == password).ProjectTo<UserBasicInfo>(_mapper.ConfigurationProvider).FirstOrDefaultAsync();
|
||||
|
||||
if (loginDoctor == null)
|
||||
{
|
||||
return ResponseOutput.NotOk("Please check the user name or password.", new LoginReturnDTO());
|
||||
|
||||
}
|
||||
|
||||
userLoginReturnModel.BasicInfo = loginDoctor;
|
||||
|
||||
|
||||
return ResponseOutput.Ok(userLoginReturnModel);
|
||||
|
||||
}
|
||||
|
||||
if (loginUser.Status == 0)
|
||||
{
|
||||
return ResponseOutput.NotOk("The user has been disabled!", new LoginReturnDTO());
|
||||
}
|
||||
|
||||
userLoginReturnModel.BasicInfo = loginUser;
|
||||
|
||||
|
||||
return ResponseOutput.Ok(userLoginReturnModel);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace IRaCIS.Core.Application.Services
|
|||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Site用户列表导出
|
||||
/// </summary>
|
||||
/// <param name="trialId"></param>
|
||||
/// <param name="isAllSiteUser">isAllSiteUser true : site用户列表,false :Site调研汇总表</param>
|
||||
|
@ -80,7 +80,6 @@ namespace IRaCIS.Core.Application.Services
|
|||
.GroupBy(t => t.SiteId)
|
||||
.Select(g => g.OrderByDescending(u => u.CreateTime).Select(t => t.Id).First());
|
||||
|
||||
|
||||
var query = _trialSiteUserSurveyRepository
|
||||
.Where(t => groupSelectIdQuery.Contains(t.TrialSiteSurveyId))
|
||||
.ProjectTo<TrialSiteUserSummaryDto>(_mapper.ConfigurationProvider);
|
||||
|
@ -122,7 +121,7 @@ namespace IRaCIS.Core.Application.Services
|
|||
.WhereIf(param.IsDeleted != null, t => t.IsDeleted == param.IsDeleted)
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(param.SiteName), t => t.Site.SiteName.Contains(param.SiteName))
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(param.TrialSiteAliasName), t => t.TrialSiteAliasName.Contains(param.TrialSiteAliasName))
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(param.TrialSiteCode), t => t.TrialSiteAliasName.Contains(param.TrialSiteCode))
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(param.TrialSiteCode), t => t.TrialSiteCode.Contains(param.TrialSiteCode))
|
||||
.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ClinicalResearchCoordinator, t => t.CRCUserList.Any(k => k.UserId == _userInfo.Id))
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(param.UserKeyInfo), t => t.CRCUserList.Any(k => (k.User.LastName + " / " + k.User.FirstName).Contains(param.UserKeyInfo)
|
||||
|| k.User.UserName.Contains(param.UserKeyInfo) || k.User.EMail.Contains(param.UserKeyInfo)))
|
||||
|
@ -145,7 +144,7 @@ namespace IRaCIS.Core.Application.Services
|
|||
.WhereIf(param.IsDeleted != null, t => t.IsDeleted == param.IsDeleted)
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(param.SiteName), t => t.Site.SiteName.Contains(param.SiteName))
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(param.TrialSiteAliasName), t => t.TrialSiteAliasName.Contains(param.TrialSiteAliasName))
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(param.TrialSiteCode), t => t.TrialSiteAliasName.Contains(param.TrialSiteCode))
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(param.TrialSiteCode), t => t.TrialSiteCode.Contains(param.TrialSiteCode))
|
||||
.WhereIf(_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ClinicalResearchCoordinator, t => t.CRCUserList.Any(k => k.UserId == _userInfo.Id))
|
||||
.WhereIf(!string.IsNullOrWhiteSpace(param.UserKeyInfo), t => t.CRCUserList.Any(k => (k.User.LastName + " / " + k.User.FirstName).Contains(param.UserKeyInfo)
|
||||
|| k.User.UserName.Contains(param.UserKeyInfo) || k.User.EMail.Contains(param.UserKeyInfo)))
|
||||
|
|
Loading…
Reference in New Issue