| | |
| | | package com.ks.tool.bkz.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.google.gson.Gson; |
| | | import com.ks.tool.bkz.entity.user.SDLJShareOpenHistory; |
| | | import com.ks.tool.bkz.entity.user.UserInfo; |
| | | import com.ks.tool.bkz.exception.CardPwdException; |
| | | import com.ks.tool.bkz.exception.SDLJShareOpenHistoryException; |
| | | import com.ks.tool.bkz.exception.UserException; |
| | | import com.ks.tool.bkz.service.manager.RedisManager; |
| | | import com.ks.tool.bkz.service.user.SDLJShareOpenHistoryService; |
| | | import com.ks.tool.bkz.service.user.UserService; |
| | | import com.ks.tool.bkz.service.user.UserUpgradeService; |
| | | import com.ks.tool.bkz.util.*; |
| | | import com.ks.tool.bkz.util.email.MailSenderUtil; |
| | | import com.ks.tool.bkz.vo.user.UserInfoVO; |
| | | import io.netty.util.Constant; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | @Resource |
| | | private UserService userService; |
| | | |
| | | @Resource |
| | | private SDLJShareOpenHistoryService sdljShareOpenHistoryService; |
| | | |
| | | @Resource |
| | | private UserUpgradeService userUpgradeService; |
| | | |
| | | |
| | | private String getVCodeKey(String account) { |
| | | |
| | |
| | | return JsonUtil.loadFalseResult(1, "验证码不能为空"); |
| | | String key = getVCodeKey(account); |
| | | String oldVcode = redisManager.get(key); |
| | | if (oldVcode == null || !oldVcode.equalsIgnoreCase(vcode)) |
| | | return JsonUtil.loadFalseResult(1, "验证码错误"); |
| | | // if (oldVcode == null || !oldVcode.equalsIgnoreCase(vcode)) |
| | | // return JsonUtil.loadFalseResult(1, "验证码错误"); |
| | | redisManager.delete(key); |
| | | account = account.trim(); |
| | | UserInfo user = userService.selectByAccount(account); |
| | |
| | | userService.login(account, request.getRemoteHost() + ":" + request.getRemotePort()); |
| | | } |
| | | |
| | | SDLJShareOpenHistory history = sdljShareOpenHistoryService.selectLatestHistory(user.getId()); |
| | | |
| | | String token = UserUtil.getToken(account, System.currentTimeMillis()); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("token", token); |
| | | return JsonUtil.loadTrueResult(data); |
| | | return JsonUtil.loadTrueResult(JsonUtil.getSimpleGson().toJson(new UserInfoVO(user.getAccount(), token, history == null ? null : history.getExpireTime()))); |
| | | } |
| | | |
| | | @RequestMapping(value = "getUserInfo", method = RequestMethod.POST) |
| | | @ResponseBody |
| | | public String getUserInfo(HttpServletRequest request) { |
| | | String token = request.getHeader("token"); |
| | | String account = UserUtil.getAccountFromToken(token); |
| | | UserInfo user = userService.selectByAccount(account); |
| | | if (user != null) { |
| | | SDLJShareOpenHistory history = sdljShareOpenHistoryService.selectLatestHistory(user.getId()); |
| | | return JsonUtil.loadTrueResult(JsonUtil.getSimpleGson().toJson(new UserInfoVO(user.getAccount(), "", history == null ? null : history.getExpireTime()))); |
| | | } |
| | | return JsonUtil.loadFalseResult(1, "用户不存在"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 分享版续费 |
| | | * |
| | | * @param request |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "renewShare", method = RequestMethod.POST) |
| | | @ResponseBody |
| | | public String renewShare(String card, String pwd, HttpServletRequest request) { |
| | | if (StringUtil.isNullOrEmpty(card) || StringUtil.isNullOrEmpty(pwd)) |
| | | return JsonUtil.loadFalseResult(1, "请输入卡号和密码"); |
| | | String token = request.getHeader("token"); |
| | | String account = UserUtil.getAccountFromToken(token); |
| | | UserInfo user = userService.selectByAccount(account); |
| | | if (user != null) { |
| | | try { |
| | | userUpgradeService.upgradeSDLJShare(user.getId(), card, pwd); |
| | | SDLJShareOpenHistory history = sdljShareOpenHistoryService.selectLatestHistory(user.getId()); |
| | | if (history == null) { |
| | | try { |
| | | Thread.sleep(100); |
| | | } catch (Exception e) { |
| | | } |
| | | history = sdljShareOpenHistoryService.selectLatestHistory(user.getId()); |
| | | } |
| | | return JsonUtil.loadTrueResult(JsonUtil.getSimpleGson().toJson(new UserInfoVO(user.getAccount(), "", history.getExpireTime()))); |
| | | } catch (UserException e) { |
| | | return JsonUtil.loadFalseResult(2, e.getMsg()); |
| | | } catch (CardPwdException e) { |
| | | return JsonUtil.loadFalseResult(3, e.getMsg()); |
| | | } catch (SDLJShareOpenHistoryException e) { |
| | | return JsonUtil.loadFalseResult(4, e.getMsg()); |
| | | } |
| | | |
| | | } else { |
| | | return JsonUtil.loadFalseResult(1, "用户不存在"); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | @RequestMapping("getVerifyCode") |
| | | @ResponseBody |
| | | public String getVerifyCode(String email, String vcode, HttpServletRequest request) { |
| | | if(!StringUtil.isEmail(email)){ |
| | | if (!StringUtil.isEmail(email)) { |
| | | return JsonUtil.loadFalseResult(1, "邮箱格式不正确"); |
| | | } |
| | | |
| | |
| | | } |
| | | MailSenderUtil.sendEmail(email, "爆款猪登录验证", "登录验证码为:" + code); |
| | | redisManager.save(getVCodeKey(email), code, 5 * 60); |
| | | return JsonUtil.loadTrueResult(null); |
| | | return JsonUtil.loadTrueResult(""); |
| | | } |
| | | |
| | | /** |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |