客户端修改密码支持管理端用户
This commit is contained in:
parent
9d58b51998
commit
3ef915295c
|
|
@ -95,7 +95,7 @@ public class UserController extends ControllerBase {
|
|||
* @return 用户信息
|
||||
**/
|
||||
@GetMapping("getInfo")
|
||||
public ApiResult<AppUserVO> getInfo(){
|
||||
public ApiResult<AppUserVO> getInfo() {
|
||||
if (StrUtil.equals(AppUserUtil.getFrom(), "app")) {
|
||||
return ApiResult.success(appUserService.getInfo(AppUserUtil.getUserId()));
|
||||
} else if (StrUtil.equals(AppUserUtil.getFrom(), "admin")) {
|
||||
|
|
@ -120,7 +120,7 @@ public class UserController extends ControllerBase {
|
|||
* @return 用户信息
|
||||
**/
|
||||
@GetMapping("getInfoById")
|
||||
public ApiResult<AppUserVO> getInfoById(@Valid @RequestParam @NotNull Integer userId){
|
||||
public ApiResult<AppUserVO> getInfoById(@Valid @RequestParam @NotNull Integer userId) {
|
||||
return ApiResult.success(appUserService.getInfo(userId));
|
||||
}
|
||||
|
||||
|
|
@ -133,11 +133,12 @@ public class UserController extends ControllerBase {
|
|||
String email = AppUserUtil.getEmail();
|
||||
String kaptcha = RandomUtil.randomString(6);
|
||||
// 将生成的验证码存入redis
|
||||
stringRedisTemplate.opsForValue().set(StrUtil.format(Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_APP, email), kaptcha, Duration.ofHours(72));
|
||||
String key = StrUtil.equals(AppUserUtil.getFrom(), Constant.FROM_APP) ? Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_APP : Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_ADMIN;
|
||||
stringRedisTemplate.opsForValue().set(StrUtil.format(key, email), kaptcha, Duration.ofHours(72));
|
||||
String subject = dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_EMAIL_NOTIFY, Constant.DICTIONARY_ITEM_EMAIL_TITLE_ACCOUNT_CHANGE_PASSWORD, Constant.DEFAULT_LANGUAGE_CODE);
|
||||
String content = dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_EMAIL_NOTIFY, Constant.DICTIONARY_ITEM_EMAIL_CONTENT_ACCOUNT_CHANGE_PASSWORD, Constant.DEFAULT_LANGUAGE_CODE)
|
||||
.replace("${loginName}",email)
|
||||
.replace("${password}",kaptcha);
|
||||
.replace("${loginName}", email)
|
||||
.replace("${password}", kaptcha);
|
||||
emailService.sendEmail(email, subject, content);
|
||||
} catch (Exception ex) {
|
||||
throw new NflgException(STATE.BusinessError, "发送邮件失败:" + ex.getMessage());
|
||||
|
|
@ -151,12 +152,17 @@ public class UserController extends ControllerBase {
|
|||
* @return 更新结果
|
||||
**/
|
||||
@PostMapping("updatePassword")
|
||||
public ApiResult<Void> updatePassword(@Valid @RequestBody UpdatePasswordRequest request){
|
||||
String redisKey = StrUtil.format(Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_APP, AppUserUtil.getEmail());
|
||||
public ApiResult<Void> updatePassword(@Valid @RequestBody UpdatePasswordRequest request) {
|
||||
String key = StrUtil.equals(AppUserUtil.getFrom(), Constant.FROM_APP) ? Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_APP : Constant.REDIS_KEY_USER_UPDATE_KAPTCHA_ADMIN;
|
||||
String redisKey = StrUtil.format(key, AppUserUtil.getEmail());
|
||||
String captcha = stringRedisTemplate.opsForValue().get(redisKey);
|
||||
VUtils.trueThrowBusinessError(StrUtil.isBlank(captcha)).throwMessage("验证码已失效,请重新获取");
|
||||
VUtils.trueThrowBusinessError(!StrUtil.equals(captcha, request.getCaptcha())).throwMessage("验证码不正确");
|
||||
appUserService.updatePassword(AppUserUtil.getUserId(), request.getNewPassword());
|
||||
if (StrUtil.equals(AppUserUtil.getFrom(), Constant.FROM_APP)) {
|
||||
appUserService.updatePassword(AppUserUtil.getUserId(), request.getNewPassword());
|
||||
} else if (StrUtil.equals(AppUserUtil.getFrom(), Constant.FROM_ADMIN)) {
|
||||
adminUserService.updatePassword(AppUserUtil.getUserId(), request.getNewPassword());
|
||||
}
|
||||
stringRedisTemplate.delete(redisKey);
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
|
@ -206,15 +212,15 @@ public class UserController extends ControllerBase {
|
|||
**/
|
||||
@PostMapping("addUser")
|
||||
//@SaUserCheckRole("primary")
|
||||
public ApiResult<Void> addUser(@Valid @RequestBody AddUserRequest request){
|
||||
AppUserApplyfor applyfor=appUserApplyforService.add(request);
|
||||
List<AdminUser> adminUsers=adminUserService.getForAccountReview();
|
||||
if (CollectionUtil.isNotEmpty(adminUsers)){
|
||||
AppUser createdUser=appUserService.getById(AppUserUtil.getUserId());
|
||||
public ApiResult<Void> addUser(@Valid @RequestBody AddUserRequest request) {
|
||||
AppUserApplyfor applyfor = appUserApplyforService.add(request);
|
||||
List<AdminUser> adminUsers = adminUserService.getForAccountReview();
|
||||
if (CollectionUtil.isNotEmpty(adminUsers)) {
|
||||
AppUser createdUser = appUserService.getById(AppUserUtil.getUserId());
|
||||
adminUsers.forEach(c -> adminMessageService.add(
|
||||
new AdminMessage()
|
||||
.setNo(request.getEmail())
|
||||
.setTitle(createdUser.getName()+"申请新的账号")
|
||||
.setTitle(createdUser.getName() + "申请新的账号")
|
||||
.setUserId(c.getId())
|
||||
.setSourceId(applyfor.getId())
|
||||
.setSource(1)
|
||||
|
|
@ -233,17 +239,17 @@ public class UserController extends ControllerBase {
|
|||
**/
|
||||
@PostMapping("changeUserEnable")
|
||||
//@SaUserCheckRole("primary")
|
||||
public ApiResult<Void> changeUserEnable(@Valid @RequestBody EnableRequest request){
|
||||
if (request.getEnable()){
|
||||
AppUserApplyfor applyfor=appUserApplyforService.addEnable(request);
|
||||
AppUser user=appUserService.getById(request.getId());
|
||||
List<AdminUser> adminUsers=adminUserService.getForAccountReview();
|
||||
if (CollectionUtil.isNotEmpty(adminUsers)){
|
||||
AppUser createdUser=appUserService.getById(AppUserUtil.getUserId());
|
||||
public ApiResult<Void> changeUserEnable(@Valid @RequestBody EnableRequest request) {
|
||||
if (request.getEnable()) {
|
||||
AppUserApplyfor applyfor = appUserApplyforService.addEnable(request);
|
||||
AppUser user = appUserService.getById(request.getId());
|
||||
List<AdminUser> adminUsers = adminUserService.getForAccountReview();
|
||||
if (CollectionUtil.isNotEmpty(adminUsers)) {
|
||||
AppUser createdUser = appUserService.getById(AppUserUtil.getUserId());
|
||||
adminUsers.forEach(c -> adminMessageService.add(
|
||||
new AdminMessage()
|
||||
.setNo(user.getEmail())
|
||||
.setTitle(createdUser.getName()+"申请账号启用")
|
||||
.setTitle(createdUser.getName() + "申请账号启用")
|
||||
.setUserId(c.getId())
|
||||
.setSourceId(applyfor.getId())
|
||||
.setSource(1)
|
||||
|
|
@ -253,7 +259,7 @@ public class UserController extends ControllerBase {
|
|||
.setCreateTime(LocalDateTime.now()))
|
||||
);
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
appUserService.disable(request.getId());
|
||||
}
|
||||
return ApiResult.success();
|
||||
|
|
@ -264,15 +270,15 @@ public class UserController extends ControllerBase {
|
|||
* @param request 请求信息
|
||||
**/
|
||||
@PostMapping("applyForExtension")
|
||||
public ApiResult<Void> applyForExtension(@Valid @RequestBody ApplyForExtensionRequest request){
|
||||
AppUserApplyfor applyfor=appUserApplyforService.applyForExtension(request);
|
||||
List<AdminUser> adminUsers=adminUserService.getForAccountReview();
|
||||
if (CollectionUtil.isNotEmpty(adminUsers)){
|
||||
AppUser createdUser=appUserService.getById(AppUserUtil.getUserId());
|
||||
public ApiResult<Void> applyForExtension(@Valid @RequestBody ApplyForExtensionRequest request) {
|
||||
AppUserApplyfor applyfor = appUserApplyforService.applyForExtension(request);
|
||||
List<AdminUser> adminUsers = adminUserService.getForAccountReview();
|
||||
if (CollectionUtil.isNotEmpty(adminUsers)) {
|
||||
AppUser createdUser = appUserService.getById(AppUserUtil.getUserId());
|
||||
adminUsers.forEach(c -> adminMessageService.add(
|
||||
new AdminMessage()
|
||||
.setNo(applyfor.getUserEmail())
|
||||
.setTitle(createdUser.getName()+"申请账号延期")
|
||||
.setTitle(createdUser.getName() + "申请账号延期")
|
||||
.setUserId(c.getId())
|
||||
.setSourceId(applyfor.getId())
|
||||
.setSource(1)
|
||||
|
|
@ -291,7 +297,7 @@ public class UserController extends ControllerBase {
|
|||
**/
|
||||
@PostMapping("deleteUser")
|
||||
//@SaUserCheckRole("primary")
|
||||
public ApiResult<Boolean> deleteUser(@Valid @RequestBody @NotEmpty List<Integer> ids){
|
||||
public ApiResult<Boolean> deleteUser(@Valid @RequestBody @NotEmpty List<Integer> ids) {
|
||||
appUserService.remove(new LambdaQueryWrapper<AppUser>()
|
||||
.eq(AppUser::getIsPrimary, false)
|
||||
.eq(AppUser::getCreateBy, AppUserUtil.getUserName())
|
||||
|
|
@ -312,14 +318,14 @@ public class UserController extends ControllerBase {
|
|||
@PostMapping("forgetPassword")
|
||||
public ApiResult<Void> forgetPassword(@Valid @RequestParam @NotBlank String email) {
|
||||
String password = RandomUtil.randomString(6);
|
||||
AppUser appUser=appUserService.forgetPassword(email, password);
|
||||
AppUser appUser = appUserService.forgetPassword(email, password);
|
||||
try {
|
||||
String subject = dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_EMAIL_NOTIFY, Constant.DICTIONARY_ITEM_EMAIL_TITLE_ACCOUNT_RESET_PASSWORD, appUser.getLanguageCode());
|
||||
String content = dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_EMAIL_NOTIFY, Constant.DICTIONARY_ITEM_EMAIL_CONTENT_RESET_PASSWORD_NOTIFY, appUser.getLanguageCode())
|
||||
.replace("${loginName}",appUser.getLoginName())
|
||||
.replace("${url}",activateUrl + "?code=" + Base64.getUrlEncoder().encodeToString((email+"|0").getBytes()))
|
||||
.replace("${password}",password);
|
||||
emailService.sendEmail(email, subject,content);
|
||||
.replace("${loginName}", appUser.getLoginName())
|
||||
.replace("${url}", activateUrl + "?code=" + Base64.getUrlEncoder().encodeToString((email + "|0").getBytes()))
|
||||
.replace("${password}", password);
|
||||
emailService.sendEmail(email, subject, content);
|
||||
} catch (Exception ex) {
|
||||
throw new NflgException(STATE.BusinessError, "发送邮件失败:" + ex.getMessage());
|
||||
}
|
||||
|
|
@ -333,7 +339,7 @@ public class UserController extends ControllerBase {
|
|||
@Transactional
|
||||
@PostMapping("sendResetPasswordEmail")
|
||||
//@SaUserCheckRole("primary")
|
||||
public ApiResult<Void> sendResetPasswordEmail(@Valid @RequestBody @NotEmpty List<Integer> ids){
|
||||
public ApiResult<Void> sendResetPasswordEmail(@Valid @RequestBody @NotEmpty List<Integer> ids) {
|
||||
try {
|
||||
for (Integer id : ids) {
|
||||
AppUser appUser = appUserService.getById(id);
|
||||
|
|
@ -344,11 +350,11 @@ public class UserController extends ControllerBase {
|
|||
String subject = dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_EMAIL_NOTIFY, Constant.DICTIONARY_ITEM_EMAIL_TITLE_ACCOUNT_RESET_PASSWORD, appUser.getLanguageCode());
|
||||
String content = dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_EMAIL_NOTIFY, Constant.DICTIONARY_ITEM_EMAIL_CONTENT_RESET_PASSWORD_NOTIFY, appUser.getLanguageCode())
|
||||
.replace("${loginName}", appUser.getLoginName())
|
||||
.replace("${url}", activateUrl + "?code=" + Base64.getUrlEncoder().encodeToString((appUser.getEmail()+"|0").getBytes()))
|
||||
.replace("${url}", activateUrl + "?code=" + Base64.getUrlEncoder().encodeToString((appUser.getEmail() + "|0").getBytes()))
|
||||
.replace("${password}", password)
|
||||
.replace("${website}", websiteUrl);
|
||||
emailService.sendEmail(appUser.getEmail(), subject, content);
|
||||
} else if(Objects.equals(appUser.getState().intValue(), 0)){
|
||||
} else if (Objects.equals(appUser.getState().intValue(), 0)) {
|
||||
String password = RandomUtil.randomString(6);
|
||||
String subject = dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_EMAIL_NOTIFY, Constant.DICTIONARY_ITEM_EMAIL_TITLE_ACCOUNT_ACTIVATION, appUser.getLanguageCode());
|
||||
String content = dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_EMAIL_NOTIFY, Constant.DICTIONARY_ITEM_EMAIL_CONTENT_ACCOUNT_ACTIVATION_NOTIFY, appUser.getLanguageCode())
|
||||
|
|
@ -360,8 +366,8 @@ public class UserController extends ControllerBase {
|
|||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception ex){
|
||||
throw new NflgException(STATE.BusinessError,"发送邮件失败:"+ex.getMessage());
|
||||
} catch (Exception ex) {
|
||||
throw new NflgException(STATE.BusinessError, "发送邮件失败:" + ex.getMessage());
|
||||
}
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
|
@ -389,7 +395,7 @@ public class UserController extends ControllerBase {
|
|||
* 获取关注二维码链接
|
||||
*/
|
||||
@GetMapping("getFollowUrl")
|
||||
public ApiResult<String> getFollowUrl(){
|
||||
public ApiResult<String> getFollowUrl() {
|
||||
return ApiResult.success(wxQRCodeService.getFollowUrl(AppUserUtil.getUserId()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue