diff --git a/nflg-mobilebroken-admin/src/main/java/com/nflg/mobilebroken/admin/controller/AppUserController.java b/nflg-mobilebroken-admin/src/main/java/com/nflg/mobilebroken/admin/controller/AppUserController.java index d09a0285..144f38ef 100644 --- a/nflg-mobilebroken-admin/src/main/java/com/nflg/mobilebroken/admin/controller/AppUserController.java +++ b/nflg-mobilebroken-admin/src/main/java/com/nflg/mobilebroken/admin/controller/AppUserController.java @@ -386,14 +386,28 @@ public class AppUserController extends ControllerBase { public ApiResult sendResetPasswordEmail(@Valid @RequestBody @NotEmpty List ids){ try { for (Integer id : ids) { - String password=RandomUtil.randomString(6); - AppUser appUser=appUserService.resetPassword(id,password); - 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("${password}",password); - emailService.sendEmail(appUser.getEmail(), subject, content); + AppUser appUser = appUserService.getById(id); + if (Objects.nonNull(appUser)) { + if (Objects.equals(appUser.getState().intValue(), 1)) { + String password = RandomUtil.randomString(6); + appUserService.resetPassword(id, password); + 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("${password}", password); + emailService.sendEmail(appUser.getEmail(), subject, content); + } 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()) + .replace("${loginName}", appUser.getEmail()) + .replace("${url}", activateUrl + "?code=" + Base64.getUrlEncoder().encodeToString((appUser.getEmail() + "|0").getBytes())) + .replace("${password}", password) + .replace("${website}", websiteUrl); + emailService.sendEmail(appUser.getEmail(), subject, content); + } + } } }catch (Exception ex){ throw new NflgException(STATE.BusinessError,"发送邮件失败:"+ex.getMessage()); diff --git a/nflg-mobilebroken-cfs-app/src/main/java/com/nflg/mobilebroken/cfs/controller/UserController.java b/nflg-mobilebroken-cfs-app/src/main/java/com/nflg/mobilebroken/cfs/controller/UserController.java index 7a75d455..41750927 100644 --- a/nflg-mobilebroken-cfs-app/src/main/java/com/nflg/mobilebroken/cfs/controller/UserController.java +++ b/nflg-mobilebroken-cfs-app/src/main/java/com/nflg/mobilebroken/cfs/controller/UserController.java @@ -310,15 +310,29 @@ public class UserController extends ControllerBase { public ApiResult sendResetPasswordEmail(@Valid @RequestBody @NotEmpty List ids){ try { for (Integer id : ids) { - String password=RandomUtil.randomString(6); - AppUser appUser=appUserService.resetPassword(id,password); - 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("${password}",password) - .replace("${website}",websiteUrl); - emailService.sendEmail(appUser.getEmail(), subject, content); + AppUser appUser = appUserService.getById(id); + if (Objects.nonNull(appUser)) { + if (Objects.equals(appUser.getState().intValue(), 1)) { + String password = RandomUtil.randomString(6); + appUserService.resetPassword(id, password); + 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("${password}", password) + .replace("${website}", websiteUrl); + emailService.sendEmail(appUser.getEmail(), subject, content); + } 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()) + .replace("${loginName}", appUser.getEmail()) + .replace("${url}", activateUrl + "?code=" + Base64.getUrlEncoder().encodeToString((appUser.getEmail() + "|0").getBytes())) + .replace("${password}", password) + .replace("${website}", websiteUrl); + emailService.sendEmail(appUser.getEmail(), subject, content); + } + } } }catch (Exception ex){ throw new NflgException(STATE.BusinessError,"发送邮件失败:"+ex.getMessage());