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