admin
2020-06-20 0ab8a2ea521a838124f517daf4e61dee971a6d4c
src/main/java/com/ks/tool/bkz/controller/UserController.java
@@ -1,12 +1,19 @@
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;
@@ -31,6 +38,12 @@
    @Resource
    private UserService userService;
    @Resource
    private SDLJShareOpenHistoryService sdljShareOpenHistoryService;
    @Resource
    private UserUpgradeService userUpgradeService;
    private String getVCodeKey(String account) {
@@ -53,8 +66,8 @@
            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);
@@ -75,10 +88,63 @@
            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, "用户不存在");
        }
    }
@@ -92,7 +158,7 @@
    @RequestMapping("getVerifyCode")
    @ResponseBody
    public String getVerifyCode(String email, String vcode, HttpServletRequest request) {
        if(!StringUtil.isEmail(email)){
        if (!StringUtil.isEmail(email)) {
            return JsonUtil.loadFalseResult(1, "邮箱格式不正确");
        }
@@ -107,7 +173,7 @@
        }
        MailSenderUtil.sendEmail(email, "爆款猪登录验证", "登录验证码为:" + code);
        redisManager.save(getVCodeKey(email), code, 5 * 60);
        return JsonUtil.loadTrueResult(null);
        return JsonUtil.loadTrueResult("");
    }
    /**
@@ -136,6 +202,5 @@
            e.printStackTrace();
        }
    }
}