Merge remote-tracking branch 'origin/main'

# Conflicts:
#	backend/src/main/resources/application.yaml
This commit is contained in:
@jyuhsin
2025-05-06 17:44:55 +08:00
27 changed files with 1341 additions and 126 deletions
@@ -7,6 +7,7 @@ import com.budwk.app.base.result.Result;
import com.budwk.app.client.auth.models.Client_user;
import com.budwk.app.client.auth.service.ClientAuthService;
import com.budwk.app.client.auth.vo.ClientLoginBody;
import com.budwk.app.client.auth.vo.ClientRegisterBody;
import com.budwk.app.sys.services.SysMsgService;
import com.budwk.app.sys.services.SysUserService;
import com.budwk.app.web.commons.auth.satoken.StpClientUtil;
@@ -59,6 +60,22 @@ public class ClientAuthController {
public void login(HttpServletRequest req, HttpSession session) {
}
@At("/register")
@Ok("json")
@AdaptBy(type = JsonAdaptor.class)
@ApiOperation(value = "注册", nickname = "/register", httpMethod = "POST")
public Result register(ClientRegisterBody registerBody) {
try {
// String token = clientAuthService.doRegister(registerBody);
// return Result.success().addData(token);
return Result.success();
} catch (Exception e) {
log.error(e.getMessage(), e);
return Result.error(e.getMessage());
}
}
/**
* 短信登录
*/
@@ -68,7 +85,7 @@ public class ClientAuthController {
@ApiOperation(value = "短信登录", nickname = "/sms-login", httpMethod = "POST")
public Object doSmsLogin(ClientLoginBody loginBody, HttpServletRequest req) {
try {
String token = clientAuthService.doSmsLogin(loginBody);
String token = clientAuthService.doLogin(loginBody);
return Result.success().addData(token);
} catch (Exception e) {
log.error(e.getMessage(), e);
@@ -76,6 +93,23 @@ public class ClientAuthController {
}
}
@At("/send-reg-code/?")
@Ok("json")
@ApiOperation(value = "发送注册验证码", nickname = "/send-reg-code", httpMethod = "POST")
public Result sendRegCode(String phone) {
try {
int count = dao.count(Client_user.class, Cnd.where("phone", "=", phone));
if (count > 0) {
return Result.error("手机号码已注册,请直接登录");
}
validateService.getSmsCode(phone);
return Result.success(NutMap.NEW().addv("key", RedisConstant.UCENTER_SMSCODE + phone)).addMsg("发送成功");
} catch (BaseException e) {
return Result.error(e.getMessage());
}
}
/**
* 发送短信验证码
*/
@@ -43,6 +43,21 @@ public class Client_user extends BaseModel implements Serializable {
@Comment("头像")
private String avatar;
@Column
@ColDefine(type = ColType.VARCHAR, width = 32)
@Comment("单位ID")
private String unitId;
@Column
@ColDefine(type = ColType.VARCHAR, width = 255)
@Comment("密码")
private String password;
@Column
@ColDefine(type = ColType.VARCHAR, width = 255)
@Comment("盐")
private String salt;
@Column
@ColDefine(type = ColType.VARCHAR, width = 255)
@Comment("openId")
@@ -1,6 +1,7 @@
package com.budwk.app.client.auth.service;
import com.budwk.app.client.auth.vo.ClientLoginBody;
import com.budwk.app.client.auth.vo.ClientRegisterBody;
public interface ClientAuthService {
@@ -9,6 +10,12 @@ public interface ClientAuthService {
* @param loginBody 登录信息
* @return token
*/
String doSmsLogin(ClientLoginBody loginBody);
String doLogin(ClientLoginBody loginBody);
/**
* 注册
* @param registerBody 注册信息
* @return token
*/
String doRegister(ClientRegisterBody registerBody);
}
@@ -1,14 +1,21 @@
package com.budwk.app.client.auth.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.budwk.app.base.exception.BaseException;
import com.budwk.app.base.utils.PwdUtil;
import com.budwk.app.client.auth.vo.ClientLoginBody;
import com.budwk.app.client.auth.models.Client_user;
import com.budwk.app.client.auth.vo.ClientRegisterBody;
import com.budwk.app.web.commons.auth.satoken.StpClientUtil;
import com.budwk.app.web.commons.auth.service.ValidateService;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;
import java.util.List;
@IocBean
public class ClientAuthServiceImpl implements ClientAuthService {
@@ -19,22 +26,50 @@ public class ClientAuthServiceImpl implements ClientAuthService {
private ValidateService validateService;
@Override
public String doSmsLogin(ClientLoginBody loginBody) {
public String doLogin(ClientLoginBody loginBody) {
Client_user user = null;
int count = dao.count(Client_user.class, Cnd.where(Client_user::getPhone, "=", loginBody.getPhone()));
if (count == 0) {
// 自动注册
user = new Client_user();
user.setPhone(loginBody.getPhone());
user.setUserName("用户" + loginBody.getPhone());
dao.insert(user);
throw new BaseException("手机号码不存在");
}
validateService.checkSMSCode(loginBody.getPhone(), loginBody.getSmsCode());
user = dao.fetch(Client_user.class, Cnd.where(Client_user::getPhone, "=", loginBody.getPhone()));
if (user == null) {
throw new BaseException("用户登录失败");
throw new BaseException("用户不存在");
}
if (StrUtil.isBlank(loginBody.getLoginMethod()) || !List.of("sms", "password").contains(loginBody.getLoginMethod())) {
throw new BaseException("登录方式不正确");
}
if (loginBody.getLoginMethod().equals("sms")) {
validateService.checkSMSCode(loginBody.getPhone(), loginBody.getSmsCode());
}
if (loginBody.getLoginMethod().equals("password")) {
String hashedPassword = PwdUtil.getPassword(loginBody.getPassword(), user.getSalt());
if (!Strings.sNull(hashedPassword).equalsIgnoreCase(user.getPassword())) {
throw new BaseException("密码不正确");
}
}
StpClientUtil.STP.login(user.getId());
StpClientUtil.STP.checkLogin();
return StpClientUtil.STP.getTokenValue();
}
@Override
public String doRegister(ClientRegisterBody registerBody) {
int count = dao.count(Client_user.class, Cnd.where(Client_user::getPhone, "=", registerBody.getPhone()));
if (count > 0) {
throw new BaseException("手机号码已注册,请直接登录");
}
validateService.checkSMSCode(registerBody.getPhone(), registerBody.getSmsCode());
Client_user user = BeanUtil.copyProperties(registerBody, Client_user.class);
dao.insert(user);
StpClientUtil.STP.login(user.getId());
StpClientUtil.STP.checkLogin();
return StpClientUtil.STP.getTokenValue();
@@ -9,4 +9,8 @@ public class ClientLoginBody {
private String smsCode;
private String password;
private String loginMethod;
}
@@ -0,0 +1,21 @@
package com.budwk.app.client.auth.vo;
import lombok.Data;
@Data
public class ClientRegisterBody {
private String userName;
private String sex;
private String phone;
private String idCard;
private String avatar;
private String unitId;
private String smsCode;
}
@@ -81,6 +81,7 @@ public class ClientActivityController {
return Result.success();
}
/**
* 查询报名人员
* 报名人不见得参加活动
@@ -117,4 +117,18 @@ public class ClientItemController {
}
/**
* 取消项目报名
* @param signVO
* @return
*/
@At("/cancel-team-sign-up")
@AdaptBy(type = JsonAdaptor.class)
@SaCheckLogin(type = StpClientUtil.TYPE)
public synchronized Result cancelTeamSignUp(ClientActivitySignVO signVO) {
clientItemService.cancelTeamSignUp(signVO);
return Result.success();
}
}
@@ -1,9 +1,12 @@
package com.budwk.app.client.module.activity.service;
import com.budwk.app.base.service.BaseService;
import com.budwk.app.client.module.activity.vo.ClientActivitySignVO;
import com.budwk.app.client.module.activity.vo.ClientItemSignUpVO;
import com.budwk.app.module.activity.models.ActivityItemUser;
public interface ClientItemService extends BaseService<ActivityItemUser> {
void signUp(ClientItemSignUpVO signVO);
void cancelTeamSignUp(ClientActivitySignVO signVO);
}
@@ -2,6 +2,7 @@ package com.budwk.app.client.module.activity.service.impl;
import com.budwk.app.base.service.impl.BaseServiceImpl;
import com.budwk.app.client.module.activity.service.ClientItemService;
import com.budwk.app.client.module.activity.vo.ClientActivitySignVO;
import com.budwk.app.client.module.activity.vo.ClientItemSignUpVO;
import com.budwk.app.module.activity.models.ActGroupUser;
import com.budwk.app.module.activity.models.Activity;
@@ -59,4 +60,10 @@ public class ClientItemServiceImpl extends BaseServiceImpl<ActivityItemUser> imp
}
insert(userList);
}
@Override
public void cancelTeamSignUp(ClientActivitySignVO signVO) {
clear(Cnd.where(ActivityItemUser::getActivityId, "=", signVO.getActivityId())
.and(ActivityItemUser::getItemId, "=", signVO.getItemId()));
}
}
@@ -12,6 +12,7 @@ import java.util.List;
public class ClientActivitySignVO {
private Long activityId;
private Long itemId;
private String unitName;
@@ -50,8 +50,8 @@ public class ValidateService {
if (Strings.isNotBlank(codeFromRedis)) {
// throw new BaseException("请1分钟之后再试");
}
ThreadUtil.execute(()->{
smsSendServer.sendMsg(mobile, "验证码为:"+text);
ThreadUtil.execute(() -> {
smsSendServer.sendCode(mobile, "验证码为:" + text);
log.debug("sms code:::" + text);
redisService.setex(RedisConstant.UCENTER_SMSCODE + mobile, 300, text);
redisService.setex(RedisConstant.UCENTER_SMSCODE + mobile + ":LOCK", 60, text);
@@ -1,7 +1,14 @@
package com.budwk.app.web.commons.ext.sms;
import com.budwk.app.base.exception.BaseException;
import com.budwk.app.base.service.BaseService;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20190711.SmsClient;
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
import lombok.extern.slf4j.Slf4j;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
@@ -14,27 +21,124 @@ import org.nutz.log.Logs;
* @author wizzer@qq.com
*/
@IocBean
@Slf4j
public class SmsService {
private static final Log log = Logs.get();
@Inject
private PropertiesProxy conf;
@Inject
private BaseService baseService;
/**
* 发送短信验证码
*
* @param mobile 手机号
* @param text 验证码
* @return true发送成功
* @throws BaseException
*/
public boolean sendCode(String mobile, String text) throws BaseException {
try {
if (!conf.getBoolean("sms.enabled")) {
return true;
}
Credential cred = new Credential(conf.get("sms.tencent.secret-id"), conf.get("sms.tencent.secret-key"));
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("sms.tencentcloudapi.com");
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
SmsClient client = new SmsClient(cred, "", clientProfile);
SendSmsRequest req = new SendSmsRequest();
String[] phoneNumberSet1 = {"+86" + mobile};
req.setPhoneNumberSet(phoneNumberSet1);
String[] templateParamSet1 = {text, "5"};
req.setTemplateParamSet(templateParamSet1);
req.setTemplateID(conf.get("sms.tencent.tpl.login_code"));
req.setSmsSdkAppid(conf.get("sms.tencent.appid"));
req.setSign(conf.get("sms.tencent.sign"));
SendSmsResponse resp = client.SendSms(req);
log.debug(SendSmsResponse.toJsonString(resp));
return true;
} catch (TencentCloudSDKException tencentCloudSDKException) {
throw new BaseException(tencentCloudSDKException.getMessage());
}
}
/**
* 发送注册验证码
* @param mobile 手机号码
* @param text 验证码
* @return true发送成功
* @throws BaseException
*/
public boolean sendRegCode(String mobile,String text) throws BaseException {
try {
if (!conf.getBoolean("sms.enabled")) {
return true;
}
Credential cred = new Credential(conf.get("sms.tencent.secret-id"), conf.get("sms.tencent.secret-key"));
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("sms.tencentcloudapi.com");
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
SmsClient client = new SmsClient(cred, "", clientProfile);
SendSmsRequest req = new SendSmsRequest();
String[] phoneNumberSet1 = {"+86" + mobile};
req.setPhoneNumberSet(phoneNumberSet1);
String[] templateParamSet1 = {text, "5"};
req.setTemplateParamSet(templateParamSet1);
req.setTemplateID(conf.get("sms.tencent.tpl.reg_code"));
req.setSmsSdkAppid(conf.get("sms.tencent.appid"));
req.setSign(conf.get("sms.tencent.sign"));
SendSmsResponse resp = client.SendSms(req);
log.debug(SendSmsResponse.toJsonString(resp));
return true;
} catch (TencentCloudSDKException tencentCloudSDKException) {
throw new BaseException(tencentCloudSDKException.getMessage());
}
}
/**
* 发送短信通知
*
* @param mobile 手机号码(最多200)
* @param text 模板参数值
* @param param 模板参数值
* @return
* @throws BaseException
*/
public boolean sendMsg(String mobile, String text) throws BaseException {
public boolean sendMsg(String[] mobile, String[] param) throws BaseException {
try {
if (!conf.getBoolean("sms.enabled")) {
return true;
}
Credential cred = new Credential(conf.get("sms.tencent.secret-id"), conf.get("sms.tencent.secret-key"));
return true;
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("sms.tencentcloudapi.com");
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
SmsClient client = new SmsClient(cred, "", clientProfile);
SendSmsRequest req = new SendSmsRequest();
req.setPhoneNumberSet(mobile);
req.setTemplateParamSet(param);
req.setTemplateID(conf.get("sms.tencent.tpl.msg"));
req.setSmsSdkAppid(conf.get("sms.tencent.appid"));
req.setSign(conf.get("sms.tencent.sign"));
SendSmsResponse resp = client.SendSms(req);
log.debug(SendSmsResponse.toJsonString(resp));
return true;
} catch (TencentCloudSDKException tencentCloudSDKException) {
throw new BaseException(tencentCloudSDKException.getMessage());
}
}
}
@@ -0,0 +1,28 @@
package com.budwk.app.web.controllers.open;
import com.budwk.app.base.result.Result;
import com.budwk.app.sys.models.Sys_unit;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import java.util.List;
@IocBean
@At("/open/common")
@Ok("json")
public class OpenCommonController {
@Inject
private Dao dao;
@At
public Result units() {
List<Sys_unit> units = dao.query(Sys_unit.class, Cnd.where(Sys_unit::getIsEnable, "=", 1).asc(Sys_unit::getId));
return Result.success(units);
}
}
+16 -10
View File
@@ -23,11 +23,11 @@ jetty:
#结合ftp使用,或用nginx代理ftp路径
#staticPath: E:/project/NutzWk/upload
#开发模式静态资源
staticPathLocal: D:/project/hmc_gbhd/backend/src/main/resources/static
staticPathLocal: E:/projects/hmc_gbhd/src/main/resources/static
security:
tokenName: token
timeout: 3600
timeout: 86400
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
# 允许同一账号并发登录,则系统参数 SessionOnlyOne 有效,亦可踢人下线并多了弹框提示功能
isConcurrent: true
@@ -69,7 +69,7 @@ xsssql:
beetl:
RESOURCE:
#本地路径,开发时设置本地路径,便于调试
rootLocal: D:/project/hmc_gbhd/backend/src/main/resources/views/
rootLocal: E:/projects/hmc_gbhd/src/main/resources/views/
root: views/
DELIMITER_STATEMENT_START: '<!--#'
DELIMITER_STATEMENT_END: '#-->'
@@ -141,18 +141,24 @@ quartz:
connectionProvider:
class: com.budwk.app.task.conn.NutConnectionProvider
swagger:
info:
title: 趣味运动会系统
description: 趣味运动会系统
sms:
enabled: false
#腾讯云短信配置
tencent:
secret-id: 1
secret-key: 2
appid: 1 #应用ID
sign: '萌发开源' #短信签名
secret-id: 1301383032
secret-key: AKIDMZWDepjNnxqSotiHZeU6SYOyIMAj24rO
appid: 1400934413 #应用ID
sign: '武汉地大三思科技' #短信签名
tpl:
#验证码模板ID
code: 1
#登录验证码模板ID
login_code: 2422443
#注册验证码模板ID
reg_code: 2422440
#短信通知模板ID
msg: 2
msg: '?'
@@ -31,15 +31,15 @@ const itemForm = {
<el-table-column label="报名人数">
<template #default="{row}">
<el-input-number v-model="row.num" :disabled="row.isTeamApply"
placeholder="请输入报名人数"></el-input-number>
placeholder="请输入报名人数" style="width: 100%"></el-input-number>
</template>
</el-table-column>
<el-table-column label="图片">
<template #default="{row}">
{{row.img}}
<image-upload v-model="row.img" :maxCount="1"></image-upload>
</template>
</el-table-column>
<!-- <el-table-column label="图片">
<template #default="{row}">
{{row.img}}
<image-upload v-model="row.img" :max-count="1"></image-upload>
</template>
</el-table-column>-->
<el-table-column label="操作" fixed="right" width="100px">
<template #default="{$index}">
<el-button type="text" class="text-danger" @click="removeRow($index)">删除</el-button>