|
@@ -2,15 +2,22 @@ package com.dgtly.member.controller;
|
|
|
|
|
|
import com.auth0.jwt.JWT;
|
|
|
import com.auth0.jwt.algorithms.Algorithm;
|
|
|
+import com.dgtly.common.annotation.ApiNoCheckSign;
|
|
|
+import com.dgtly.common.annotation.ApiPassToken;
|
|
|
import com.dgtly.common.core.controller.ApiBaseController;
|
|
|
import com.dgtly.common.core.domain.AjaxResult;
|
|
|
import com.dgtly.common.core.domain.ParameterObject;
|
|
|
import com.dgtly.common.utils.DateUtils;
|
|
|
import com.dgtly.member.domain.MemberInfo;
|
|
|
import com.dgtly.member.service.IMemberInfoService;
|
|
|
+import com.google.code.kaptcha.Constants;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
@@ -22,6 +29,10 @@ import java.util.Date;
|
|
|
* @date 2020-2-25 14:41
|
|
|
* @since JDK1.8
|
|
|
*/
|
|
|
+@RestController
|
|
|
+@RequestMapping("/member/info")
|
|
|
+@ApiPassToken
|
|
|
+@ApiNoCheckSign
|
|
|
public class MemberInfoController extends ApiBaseController {
|
|
|
|
|
|
@Autowired
|
|
@@ -48,7 +59,7 @@ public class MemberInfoController extends ApiBaseController {
|
|
|
if(memberInfo1 != null){
|
|
|
return AjaxResult.error(302,"手机号码已存在");
|
|
|
}
|
|
|
-
|
|
|
+ memberInfo.setLoginTime(DateUtils.getNowDate());
|
|
|
memberInfo.setCreateTime(DateUtils.getNowDate());
|
|
|
int flag = iMemberInfoService.insertMemberInfo(memberInfo);
|
|
|
return toAjax(flag);
|
|
@@ -66,19 +77,29 @@ public class MemberInfoController extends ApiBaseController {
|
|
|
public Object memberLogin(){
|
|
|
ParameterObject obj = getParameterObject();
|
|
|
MemberInfo memberInfo = obj.parseBean(MemberInfo.class);
|
|
|
- MemberInfo memberInfo1 = iMemberInfoService.memberLogin(memberInfo);
|
|
|
- if(memberInfo1 == null){
|
|
|
- return AjaxResult.error(303,"登录账号或密码错误");
|
|
|
+
|
|
|
+ HttpServletRequest request = getRequest();
|
|
|
+ HttpSession httpSession = request.getSession();
|
|
|
+ String key = httpSession.getAttribute(Constants.KAPTCHA_SESSION_KEY)+"";
|
|
|
+
|
|
|
+
|
|
|
+ if(null != key && key.equals(memberInfo.getValidateCode())){
|
|
|
+ MemberInfo memberInfo1 = iMemberInfoService.memberLogin(memberInfo);
|
|
|
+ if(memberInfo1 == null){
|
|
|
+ return AjaxResult.error(304,"登录账号或密码错误");
|
|
|
+ }
|
|
|
+ Date start = new Date();
|
|
|
+ long currentTime = System.currentTimeMillis() + 12*60* 60 * 1000;
|
|
|
+ Date end = new Date(currentTime);
|
|
|
+ String token = JWT.create().withAudience(memberInfo1.getId()+"")
|
|
|
+ .withIssuedAt(start)
|
|
|
+ .withExpiresAt(end)
|
|
|
+ .sign(Algorithm.HMAC256(memberInfo1.getLoginPassword()));
|
|
|
+
|
|
|
+ return AjaxResult.success().putKV("token",token);
|
|
|
}
|
|
|
- Date start = new Date();
|
|
|
- long currentTime = System.currentTimeMillis() + 12*60* 60 * 1000;
|
|
|
- Date end = new Date(currentTime);
|
|
|
- String token = JWT.create().withAudience(memberInfo1.getId()+"")
|
|
|
- .withIssuedAt(start)
|
|
|
- .withExpiresAt(end)
|
|
|
- .sign(Algorithm.HMAC256(memberInfo1.getLoginPassword()));
|
|
|
|
|
|
- return AjaxResult.success("登录成功",token);
|
|
|
+ return AjaxResult.error(303,"验证码错误");
|
|
|
|
|
|
}
|
|
|
}
|