中扬CRM客户关系管理系统
#
LSH
2023-12-01 09ee5added9d59e90310a2586e846137ea597b19
src/main/java/com/zy/crm/common/web/AuthController.java
@@ -8,6 +8,8 @@
import com.core.common.Cools;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.crm.manager.service.SmsCodeService;
import com.zy.crm.manager.utils.SmsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
@@ -53,9 +55,11 @@
    private RolePermissionService rolePermissionService;
    @Autowired
    private HostService hostService;
    @Autowired
    private SmsCodeService smsCodeService;
    @RequestMapping("/login.action")
    @ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "登录")
    @ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "密码登录")
    public R loginAction(String username, String password){
        if (username.equals("super") && password.equals(Cools.md5(superPwd))) {
            Map<String, Object> res = new HashMap<>();
@@ -72,6 +76,9 @@
        if (user.getStatus()!=1){
            return R.parse(CodeRes.USER_10002);
        }
        if (Cools.isEmpty(user.getPassword())){
            return R.parse(CodeRes.USER_10004);
        }
        if (!user.getPassword().equals(password)){
            return R.parse(CodeRes.USER_10003);
        }
@@ -92,6 +99,39 @@
        return R.ok(res);
    }
    @RequestMapping("/smsLogin.action")
    @ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "短信登录")
    public R smsLoginAction(String phone, String code){
        EntityWrapper<User> userWrapper = new EntityWrapper<>();
        userWrapper.eq("mobile", phone);
        User user = userService.selectOne(userWrapper);
        if (Cools.isEmpty(user)){
            return R.parse(CodeRes.USER_10001);
        }
        if (user.getStatus()!=1){
            return R.parse(CodeRes.USER_10002);
        }
        boolean verify = smsCodeService.verifySmsCode(phone, code);
        if (!verify) {
            return R.parse(CodeRes.USER_10005);
        }
        String token = Cools.enToken(System.currentTimeMillis() + phone, code);
        userLoginService.delete(new EntityWrapper<UserLogin>().eq("user_id", user.getId()));
        UserLogin userLogin = new UserLogin();
        userLogin.setUserId(user.getId());
        userLogin.setToken(token);
        userLogin.setCreateTime(new Date());
        if (user.getRoleId() == 1) {
            userLogin.setHostId(hostService.getTop1().getId());
        }
        userLoginService.insert(userLogin);
        Map<String, Object> res = new HashMap<>();
        res.put("username", user.getUsername());
        res.put("nickname", user.getNickname());
        res.put("token", token);
        return R.ok(res);
    }
    @RequestMapping("/show/host.action")
    @ManagerAuth
    public R showHosts() {