This commit is contained in:
2026-02-03 22:05:39 +08:00
parent d53e286b7e
commit c0acba8180
5 changed files with 81 additions and 66 deletions

View File

@@ -3,6 +3,7 @@ package org.springblade.modules.appFormal.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qiniu.util.Auth;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -48,12 +49,19 @@ public class FormalCustomerController {
return R.data(formalAppCustomerManager.findUserInfo(AuthUtil.getUserId()));
}
@Operation(summary = "修改密码")
@PutMapping("/update-password")
public R<Boolean> updatePassword(@RequestBody UpdatePasswordRequest request) {
return R.data(formalAppCustomerManager.updatePassword(request.setId(AuthUtil.getUserId())));
}
@Operation(summary = "修改密码")
@PutMapping("/update-password-non-code")
public R<Boolean> updatePasswordNonCode(@RequestBody UpdatePasswordRequest request) {
return R.data(formalAppCustomerManager.updatePasswordNonCode(request.setId(AuthUtil.getUserId())));
}
@Operation(summary = "用户退出登录")
@PostMapping("/userLogout")
public R<Boolean> userLogout() {
@@ -95,5 +103,12 @@ public class FormalCustomerController {
return R.status(formalAppCustomerManager.readUserNotice(userNotice.getId()));
}
@Operation(summary = "未读消息总数")
@GetMapping("/not-read-notice-count")
public R<Integer> notReadNoticeCount(AppUserNoticeVO userNotice) {
return R.data(formalAppCustomerManager.notReadNoticeCount(userNotice ,AuthUtil.getUserId()));
}
}

View File

@@ -44,6 +44,7 @@ import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
@Component
@AllArgsConstructor
@@ -95,17 +96,46 @@ public class FormalAppCustomerManager {
.eq(User::getPhone, String.valueOf(phone))
);
Assert.notNull(user, "用户不存在");
String decrypt = SM2Util.decrypt(request.getPassword(), properties.getPrivateKey());
String decryptPassword = SM2Util.decrypt(request.getPassword(), properties.getPrivateKey());
Predicate<String> isPasswordValid = passwd -> passwd.matches("^(?=.*[0-9])(?=.*[a-zA-Z]){6,12}$");
//去掉上面特殊字符校验
Assert.isTrue(!isPasswordValid.test(decryptPassword), "密码长度必须在6到12位之间,且需要包含大小写英文与数字");
return userService.update(
Wrappers.lambdaUpdate(User.class)
.eq(User::getId, user.getId())
.set(User::getPassword, DigestUtil.encrypt(decrypt))
.set(User::getPassword, DigestUtil.encrypt(decryptPassword))
);
}
public Boolean updatePasswordNonCode(UpdatePasswordRequest request) {
Assert.notNull(request.getPhone() , "手机号不能为空");
Assert.notNull(request.getCode() , "验证码不能为空");
Assert.isTrue(PhoneUtil.isMobile(String.valueOf(request.getPhone())), "手机号格式不正确");
Long phone = request.getPhone();
User user = userService.getOne(
Wrappers.lambdaQuery(User.class)
.eq(User::getPhone, String.valueOf(phone))
);
Assert.notNull(user, "用户不存在");
String decryptPassword = SM2Util.decrypt(request.getPassword(), properties.getPrivateKey());
Predicate<String> isPasswordValid = passwd -> passwd.matches("^(?=.*[0-9])(?=.*[a-zA-Z]){6,12}$");
//去掉上面特殊字符校验
Assert.isTrue(!isPasswordValid.test(decryptPassword), "密码长度必须在6到12位之间,且需要包含大小写英文与数字");
return userService.update(
Wrappers.lambdaUpdate(User.class)
.eq(User::getId, user.getId())
.set(User::getPassword, DigestUtil.encrypt(decryptPassword))
);
}
public Boolean userLogout() {
BladeUser user = AuthUtil.getUser();
if (user != null && this.jwtProperties.getState()) {
@@ -194,10 +224,23 @@ public class FormalAppCustomerManager {
return userNoticeService.updateById(userNotice);
}
public Integer notReadNoticeCount(AppUserNoticeVO userNotice ,Long userId) {
long count = userNoticeService.count(
Wrappers.lambdaQuery(UserNoticeEntity.class)
.eq(UserNoticeEntity::getUserId, userId)
.eq(Objects.nonNull(userNotice.getNoticeType()), UserNoticeEntity::getNoticeType, userNotice.getNoticeType())
.orderByDesc(UserNoticeEntity::getHasRead, UserNoticeEntity::getId)
);
return Math.toIntExact(count);
}
private String phoneTo32Hex(String phone) {
return RadixUtil.encode(BladeAuthConstant.BINARY_TEMPLATE, Long.parseLong(phone));
}
}

View File

@@ -56,6 +56,12 @@ public class OfflineCustomerController {
return R.status(formalAppCustomerManager.readUserNotice(userNotice.getId()));
}
@Operation(summary = "未读消息总数")
@GetMapping("/not-read-notice-count")
public R<Integer> notReadNoticeCount(AppUserNoticeVO userNotice) {
return R.data(formalAppCustomerManager.notReadNoticeCount(userNotice ,AuthUtil.getUserId()));
}
@Operation(summary = "查询积分")
@GetMapping("/find-user-integral")

View File

@@ -27,16 +27,11 @@ package org.springblade.modules.auth.granter;
import cn.hutool.core.util.PhoneUtil;
import cn.hutool.core.util.RadixUtil;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.jetbrains.annotations.NotNull;
import org.springblade.common.cache.ParamCache;
import org.springblade.common.utils.date.DateUtil;
import org.springblade.core.launch.constant.TokenConstant;
import org.springblade.core.oauth2.exception.ExceptionCode;
import org.springblade.core.oauth2.exception.UserInvalidException;
import org.springblade.core.oauth2.granter.AbstractTokenGranter;
@@ -52,13 +47,11 @@ import org.springblade.core.oauth2.service.impl.OAuth2UserDetail;
import org.springblade.core.oauth2.utils.OAuth2Util;
import org.springblade.core.secure.TokenInfo;
import org.springblade.core.social.props.SocialProperties;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SM2Util;
import org.springblade.modules.appOffline.event.AppUserRegisterEvent;
import org.springblade.modules.auth.constant.BladeAuthConstant;
import org.springblade.modules.auth.provider.UserType;
import org.springblade.modules.auth.ymlConfigFile.AppFormalClientConfig;
import org.springblade.modules.sms.service.AliYunSmsService;
import org.springblade.modules.system.pojo.entity.User;
import org.springblade.modules.system.service.IUserService;
@@ -82,7 +75,6 @@ public class RegisterTokenGranter extends AbstractTokenGranter {
private final IUserService service;
private final OAuth2Properties properties;
private final AppFormalClientConfig appFormalClientConfig;
private final SocialProperties socialProperties;
private final ApplicationEventPublisher publisher;
private final AliYunSmsService aliYunSmsService;
@@ -93,13 +85,11 @@ public class RegisterTokenGranter extends AbstractTokenGranter {
IUserService service,
OAuth2Properties properties,
SocialProperties socialProperties,
AppFormalClientConfig appFormalClientConfig,
ApplicationEventPublisher publisher,
AliYunSmsService aliYunSmsService) {
super(clientService, userService, passwordHandler);
this.service = service;
this.properties = properties;
this.appFormalClientConfig = appFormalClientConfig;
this.socialProperties = socialProperties;
this.publisher = publisher;
this.aliYunSmsService = aliYunSmsService;
@@ -113,35 +103,30 @@ public class RegisterTokenGranter extends AbstractTokenGranter {
@Override
public OAuth2User user(OAuth2Request request) {
log.info("参数parameter:[{}]", request);
// 校验注册功能是否开启
Boolean registerOpen = Func.toBoolean(ParamCache.getValue(REGISTER_USER_VALUE), false);
String clientId = request.getClientId();
if (!registerOpen || !clientId.equals(appFormalClientConfig.getName())) {
if (!registerOpen || !clientId.equals("app")) {
throw new UserInvalidException("注册功能暂未开启,请联系管理员");
}
Kv parameterArgs = request.getParameterArgs();
log.info("参数parameterArgs:[{}]", parameterArgs);
// 验证码
String code = request.getCode();
String password = SM2Util.decrypt(request.getPassword(), properties.getPrivateKey());
log.info("password:[{}]", password);
String password = "";
if (code != null){
aliYunSmsService.verifySms(request.getPhone(), code);
// 截取手机号后六位
password = createDefaultPassword(request.getPhone());
}else {
Assert.notNull(password, "密码不能为空");
password = SM2Util.decrypt(request.getPassword(), properties.getPrivateKey());
//校验密码长度是6到12位, 可以包含字母、数字
Predicate<String> isPasswordValid = passwd -> passwd.matches("^(?=.*[0-9])(?=.*[a-z]){6,12}$");
Predicate<String> isPasswordValid = passwd -> passwd.matches("^(?=.*[0-9])(?=.*[a-zA-Z]){6,12}$");
//去掉上面特殊字符校验
Assert.isTrue(!isPasswordValid.test(password), "密码长度必须在6到12位之间,且需要包含英文与数字");
Assert.isTrue(!isPasswordValid.test(password), "密码长度必须在6到12位之间,且需要包含大小写英文与数字");
}
String sourceParameter = request.getSource();

View File

@@ -69,45 +69,7 @@ public class ParamServiceImpl extends BaseServiceImpl<ParamMapper, Param> implem
private static final String APP_FORMAL_DAILY_SIGN_IS_LOOK_ADS = "yichayilu:app:dailysign.is.look.ads";
private static final String APP_FORMAL_WATCH_VIDEO_TIME_RANG = "yichayilu:app:dailysign:watch.video.time.rang";
private UserRegisterRoleDTO userRegisterRoleDTO;
private Boolean dailySignIsLookAtAds;
private WatchVideoTimeRangeDTO watchVideoTimeRangeDTO;
private String appFormalUserPrivacy;
private String appFormalUserAgreement;
@XxlJob("yichayilu-app-userRegisterInfo")
@PostConstruct
public void initAppUserRegisterInfo() {
Param param = this.getOne(Wrappers.<Param>query().lambda().eq(Param::getParamKey, APP_USER_REGISTER_ROLE));
userRegisterRoleDTO = JSONObject.parseObject(param.getParamValue(), UserRegisterRoleDTO.class);
}
@XxlJob("yichayilu-app-privacy-agreement")
@PostConstruct
public void initAppUserPrivacyAgreement() {
Param privacyParam = this.getOne(Wrappers.<Param>query().lambda().eq(Param::getParamKey, APP_FORMAL_USER_PRIVACY));
Param agreementParam = this.getOne(Wrappers.<Param>query().lambda().eq(Param::getParamKey, APP_FORMAL_USER_AGREEMENT));
appFormalUserPrivacy = privacyParam.getParamValue();
appFormalUserAgreement = agreementParam.getParamValue();
}
@XxlJob("yichayilu-dailysign-isLookAds")
@PostConstruct
public void initDailySignIsLookAds() {
Param param = this.getOne(Wrappers.<Param>query().lambda().eq(Param::getParamKey, APP_FORMAL_DAILY_SIGN_IS_LOOK_ADS));
dailySignIsLookAtAds = Boolean.valueOf(param.getParamValue());
}
@XxlJob("yichayilu-dailysign-watchVideoTimeRange")
@PostConstruct
public void initDailySignWatchVideoTimeRange() {
Param param = this.getOne(Wrappers.<Param>query().lambda().eq(Param::getParamKey, APP_FORMAL_WATCH_VIDEO_TIME_RANG));
watchVideoTimeRangeDTO = JSONObject.parseObject(param.getParamValue(), WatchVideoTimeRangeDTO.class);
}
@Override
public String getValue(String paramKey) {
@@ -117,18 +79,20 @@ public class ParamServiceImpl extends BaseServiceImpl<ParamMapper, Param> implem
@Override
public UserRegisterRoleDTO getUserRegisterRoleInfo() {
return userRegisterRoleDTO;
Param param = this.getOne(Wrappers.<Param>query().lambda().eq(Param::getParamKey, APP_USER_REGISTER_ROLE));
return JSONObject.parseObject(param.getParamValue(), UserRegisterRoleDTO.class);
}
@Override
public String getFormalAppPrivacy() {
return appFormalUserPrivacy;
Param param = this.getOne(Wrappers.<Param>query().lambda().eq(Param::getParamKey, APP_FORMAL_USER_PRIVACY));
return param.getParamValue();
}
@Override
public String formalAppAgreement() {
return appFormalUserAgreement;
Param param = this.getOne(Wrappers.<Param>query().lambda().eq(Param::getParamKey, APP_FORMAL_USER_AGREEMENT));
return param.getParamValue();
}
@Override
@@ -162,12 +126,14 @@ public class ParamServiceImpl extends BaseServiceImpl<ParamMapper, Param> implem
@Override
public Boolean isLookAtAdsByOutput() {
return dailySignIsLookAtAds;
Param param = this.getOne(Wrappers.<Param>query().lambda().eq(Param::getParamKey, APP_FORMAL_DAILY_SIGN_IS_LOOK_ADS));
return Boolean.valueOf(param.getParamValue());
}
@Override
public WatchVideoTimeRangeDTO watchVideoTimeRange() {
return watchVideoTimeRangeDTO;
Param param = this.getOne(Wrappers.<Param>query().lambda().eq(Param::getParamKey, APP_FORMAL_WATCH_VIDEO_TIME_RANG));
return JSONObject.parseObject(param.getParamValue(), WatchVideoTimeRangeDTO.class);
}
}