diff --git a/backend/src/main/java/com/budwk/app/client/auth/controller/ClientAuthController.java b/backend/src/main/java/com/budwk/app/client/auth/controller/ClientAuthController.java index ec37e6f..333250f 100644 --- a/backend/src/main/java/com/budwk/app/client/auth/controller/ClientAuthController.java +++ b/backend/src/main/java/com/budwk/app/client/auth/controller/ClientAuthController.java @@ -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()); + } + } + /** * 短信登录 */ @@ -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()); + } + } + /** * 发送短信验证码 */ diff --git a/backend/src/main/java/com/budwk/app/client/auth/models/Client_user.java b/backend/src/main/java/com/budwk/app/client/auth/models/Client_user.java index d2dfbb5..89417fb 100644 --- a/backend/src/main/java/com/budwk/app/client/auth/models/Client_user.java +++ b/backend/src/main/java/com/budwk/app/client/auth/models/Client_user.java @@ -43,6 +43,11 @@ 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("openId") diff --git a/backend/src/main/java/com/budwk/app/client/auth/service/ClientAuthService.java b/backend/src/main/java/com/budwk/app/client/auth/service/ClientAuthService.java index cd68c13..551a5be 100644 --- a/backend/src/main/java/com/budwk/app/client/auth/service/ClientAuthService.java +++ b/backend/src/main/java/com/budwk/app/client/auth/service/ClientAuthService.java @@ -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 { @@ -11,4 +12,10 @@ public interface ClientAuthService { */ String doSmsLogin(ClientLoginBody loginBody); + /** + * 注册 + * @param registerBody 注册信息 + * @return token + */ + String doRegister(ClientRegisterBody registerBody); } diff --git a/backend/src/main/java/com/budwk/app/client/auth/service/ClientAuthServiceImpl.java b/backend/src/main/java/com/budwk/app/client/auth/service/ClientAuthServiceImpl.java index 625393c..2cb8a49 100644 --- a/backend/src/main/java/com/budwk/app/client/auth/service/ClientAuthServiceImpl.java +++ b/backend/src/main/java/com/budwk/app/client/auth/service/ClientAuthServiceImpl.java @@ -1,8 +1,10 @@ package com.budwk.app.client.auth.service; +import cn.hutool.core.bean.BeanUtil; import com.budwk.app.base.exception.BaseException; 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; @@ -23,11 +25,12 @@ public class ClientAuthServiceImpl implements ClientAuthService { 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); +// // 自动注册 +// user = new Client_user(); +// user.setPhone(loginBody.getPhone()); +// user.setUserName("用户" + loginBody.getPhone()); +// dao.insert(user); + throw new BaseException("手机号码不存在"); } validateService.checkSMSCode(loginBody.getPhone(), loginBody.getSmsCode()); @@ -39,4 +42,20 @@ public class ClientAuthServiceImpl implements ClientAuthService { 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(); + } } diff --git a/backend/src/main/java/com/budwk/app/client/auth/vo/ClientRegisterBody.java b/backend/src/main/java/com/budwk/app/client/auth/vo/ClientRegisterBody.java new file mode 100644 index 0000000..bfc5fe4 --- /dev/null +++ b/backend/src/main/java/com/budwk/app/client/auth/vo/ClientRegisterBody.java @@ -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; +} diff --git a/backend/src/main/java/com/budwk/app/web/commons/auth/service/ValidateService.java b/backend/src/main/java/com/budwk/app/web/commons/auth/service/ValidateService.java index 763b2e9..12a1f06 100644 --- a/backend/src/main/java/com/budwk/app/web/commons/auth/service/ValidateService.java +++ b/backend/src/main/java/com/budwk/app/web/commons/auth/service/ValidateService.java @@ -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); diff --git a/backend/src/main/java/com/budwk/app/web/commons/ext/sms/SmsService.java b/backend/src/main/java/com/budwk/app/web/commons/ext/sms/SmsService.java index 4a39c16..3976ad9 100644 --- a/backend/src/main/java/com/budwk/app/web/commons/ext/sms/SmsService.java +++ b/backend/src/main/java/com/budwk/app/web/commons/ext/sms/SmsService.java @@ -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()); + } } - - } diff --git a/backend/src/main/java/com/budwk/app/web/controllers/open/OpenCommonController.java b/backend/src/main/java/com/budwk/app/web/controllers/open/OpenCommonController.java new file mode 100644 index 0000000..8a9e8f9 --- /dev/null +++ b/backend/src/main/java/com/budwk/app/web/controllers/open/OpenCommonController.java @@ -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 units = dao.query(Sys_unit.class, Cnd.where(Sys_unit::getIsEnable, "=", 1).asc(Sys_unit::getId)); + return Result.success(units); + } + +} diff --git a/backend/src/main/resources/application.yaml b/backend/src/main/resources/application.yaml index eaba89b..b3d8611 100644 --- a/backend/src/main/resources/application.yaml +++ b/backend/src/main/resources/application.yaml @@ -27,7 +27,7 @@ jetty: security: tokenName: token - timeout: 3600 + timeout: 86400 # 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录) # 允许同一账号并发登录,则系统参数 SessionOnlyOne 有效,亦可踢人下线并多了弹框提示功能 isConcurrent: true @@ -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: '?' diff --git a/frontend/src/pages.json b/frontend/src/pages.json index 4e46ffa..837e460 100644 --- a/frontend/src/pages.json +++ b/frontend/src/pages.json @@ -13,6 +13,13 @@ "navigationStyle": "custom" } }, + { + "path": "pages/login/register", + "style": { + "navigationBarTitleText": "注册", + "navigationStyle": "custom" + } + }, { "path": "pages/activity/list/index", "style": { diff --git a/frontend/src/pages/index/index.vue b/frontend/src/pages/index/index.vue index ac33db2..0bc056d 100644 --- a/frontend/src/pages/index/index.vue +++ b/frontend/src/pages/index/index.vue @@ -2,7 +2,7 @@ diff --git a/frontend/src/pages/login/index.vue b/frontend/src/pages/login/index.vue index 7d0e4e2..b20beb9 100644 --- a/frontend/src/pages/login/index.vue +++ b/frontend/src/pages/login/index.vue @@ -109,11 +109,11 @@ 立即登录 - - - - - + + + 没有账号? + 去注册 + @@ -317,6 +317,13 @@ async function handleLogin() { Toast({message: e.message, theme: 'error'}) } } + +function navigateToRegister(){ + uni.redirectTo({ + url: '/pages/login/register' + }) +} + diff --git a/frontend/src/static/img/index.png b/frontend/src/static/img/index.png new file mode 100644 index 0000000..6cc8cf4 Binary files /dev/null and b/frontend/src/static/img/index.png differ diff --git a/frontend/src/utils/routerInterceptor.js b/frontend/src/utils/routerInterceptor.js index 3210941..a88672e 100644 --- a/frontend/src/utils/routerInterceptor.js +++ b/frontend/src/utils/routerInterceptor.js @@ -124,6 +124,7 @@ async function routeInterceptor(args, whiteList) { export const getDefaultWhiteList = () => { return [ '/pages/index/index', - '/pages/login/index' + '/pages/login/index', + '/pages/login/register' ] }