|
@@ -1,7 +1,9 @@
|
|
package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
|
|
|
|
|
|
+import org.apache.commons.lang3.RandomUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -11,8 +13,14 @@ import org.springframework.web.bind.annotation.RestController;
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
import cn.com.qmth.examcloud.commons.web.security.bean.User;
|
|
import cn.com.qmth.examcloud.commons.web.security.bean.User;
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.Student;
|
|
import cn.com.qmth.examcloud.core.basic.service.AuthService;
|
|
import cn.com.qmth.examcloud.core.basic.service.AuthService;
|
|
import cn.com.qmth.examcloud.core.basic.service.bean.LoginInfo;
|
|
import cn.com.qmth.examcloud.core.basic.service.bean.LoginInfo;
|
|
|
|
+import cn.com.qmth.examcloud.exchange.inner.api.SendSmsCloudService;
|
|
|
|
+import cn.com.qmth.examcloud.exchange.inner.api.request.CheckSmsCodeReq;
|
|
|
|
+import cn.com.qmth.examcloud.exchange.inner.api.request.SendSmsReq;
|
|
|
|
+import cn.com.qmth.examcloud.exchange.inner.api.response.CheckIdentifyingCodeResp;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -29,6 +37,30 @@ public class AuthController extends ControllerSupport {
|
|
@Autowired
|
|
@Autowired
|
|
AuthService authService;
|
|
AuthService authService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ SendSmsCloudService sendSmsCloudService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ StudentRepo studentRepo;
|
|
|
|
+
|
|
|
|
+ @Value("${$sendVerificationCode.sign}")
|
|
|
|
+ private String smsSign;
|
|
|
|
+
|
|
|
|
+ @Value("${$sendVerificationCode.templatecode}")
|
|
|
|
+ private String smsTemplatecode;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 短信验证码有效期/秒
|
|
|
|
+ */
|
|
|
|
+ @Value("${$sendVerificationCode.effectivetime}")
|
|
|
|
+ private Integer smsEffectivetime;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 短信验证码 发送间隔时间/秒
|
|
|
|
+ */
|
|
|
|
+ @Value("${$sendVerificationCode.intervalseconds}")
|
|
|
|
+ private Integer smsIntervalSeconds;
|
|
|
|
+
|
|
@ApiOperation(value = "登入", notes = "")
|
|
@ApiOperation(value = "登入", notes = "")
|
|
@PostMapping("login")
|
|
@PostMapping("login")
|
|
public User login(@RequestBody LoginInfo loginInfo) {
|
|
public User login(@RequestBody LoginInfo loginInfo) {
|
|
@@ -68,4 +100,41 @@ public class AuthController extends ControllerSupport {
|
|
return authService.thirdPartyAccess(orgId, loginName, appId, timestamp, token);
|
|
return authService.thirdPartyAccess(orgId, loginName, appId, timestamp, token);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @ApiOperation(value = "发送验证码", notes = "")
|
|
|
|
+ @PostMapping("/bindSecurityPhone")
|
|
|
|
+ public void sendVerificationCode(@RequestParam String phone) {
|
|
|
|
+ SendSmsReq req = new SendSmsReq();
|
|
|
|
+ req.setPhone(phone);
|
|
|
|
+ int code = 1000 + RandomUtils.nextInt(1, 9999);
|
|
|
|
+ req.setCode(String.valueOf(code));
|
|
|
|
+ req.setEffectiveTime(smsEffectivetime);
|
|
|
|
+ req.setIntervalSeconds(smsIntervalSeconds);
|
|
|
|
+ req.setSign(smsSign);
|
|
|
|
+ req.setTemplateCode(smsTemplatecode);
|
|
|
|
+ sendSmsCloudService.sendIdentifyingCode(req);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "绑定手机号", notes = "")
|
|
|
|
+ @PostMapping("/bindSecurityPhone")
|
|
|
|
+ public void bindSecurityPhone(@RequestParam String phone,
|
|
|
|
+ @RequestParam String verificationCode) {
|
|
|
|
+ CheckSmsCodeReq req = new CheckSmsCodeReq();
|
|
|
|
+ req.setCode(verificationCode);
|
|
|
|
+ req.setPhone(phone);
|
|
|
|
+ CheckIdentifyingCodeResp resp = sendSmsCloudService.checkIdentifyingCode(req);
|
|
|
|
+ if (!resp.getSuccess()) {
|
|
|
|
+ throw new StatusException("B-001050", "验证码错误");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ User accessUser = getAccessUser();
|
|
|
|
+ Long studentId = accessUser.getStudentId();
|
|
|
|
+
|
|
|
|
+ if (null != studentId) {
|
|
|
|
+ Student s = studentRepo.findOne(studentId);
|
|
|
|
+ s.setSecurityPhone(phone);
|
|
|
|
+ } else {
|
|
|
|
+ throw new StatusException("B-001051", "绑定失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|