53 lines
2.0 KiB
Java
53 lines
2.0 KiB
Java
|
package com.changhu.enums.handler;
|
||
|
|
||
|
import cn.dev33.satoken.stp.SaTokenInfo;
|
||
|
import cn.hutool.extra.spring.SpringUtil;
|
||
|
import com.alibaba.fastjson2.JSONObject;
|
||
|
import com.changhu.common.enums.ResultCode;
|
||
|
import com.changhu.common.exception.MessageException;
|
||
|
import com.changhu.common.pojo.vo.TokenInfo;
|
||
|
import com.changhu.common.utils.RsaUtil;
|
||
|
import com.changhu.common.utils.UserUtil;
|
||
|
import com.changhu.common.utils.ValidatorUtil;
|
||
|
import com.changhu.module.management.pojo.entity.ManagementSuperUser;
|
||
|
import com.changhu.module.management.service.ManagementSuperUserService;
|
||
|
import com.changhu.pojo.params.ManagementSuperLoginParams;
|
||
|
|
||
|
/**
|
||
|
* @author 20252
|
||
|
* @createTime 2024/8/28 下午5:25
|
||
|
* @desc ManagementSuperLogin...
|
||
|
*/
|
||
|
public class ManagementSuperLogin extends AbstractLoginHandler {
|
||
|
|
||
|
private static final ManagementSuperUserService managementSuperUserService = SpringUtil.getBean(ManagementSuperUserService.class);
|
||
|
|
||
|
public static final ManagementSuperLogin instance = new ManagementSuperLogin();
|
||
|
|
||
|
private ManagementSuperLogin() {
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public TokenInfo login(JSONObject jsonObject) {
|
||
|
ManagementSuperLoginParams loginParams = jsonObject.to(ManagementSuperLoginParams.class);
|
||
|
ValidatorUtil.manual(loginParams);
|
||
|
String telephone = loginParams.getTelephone();
|
||
|
String password = RsaUtil.decrypt(loginParams.getPassword());
|
||
|
|
||
|
//用户是否存在
|
||
|
ManagementSuperUser user = managementSuperUserService.lambdaQuery()
|
||
|
.eq(ManagementSuperUser::getTelephone, telephone)
|
||
|
.oneOpt()
|
||
|
.orElseThrow(() -> new MessageException("用户不存在"));
|
||
|
|
||
|
//判断密码是否正确
|
||
|
if (!UserUtil.verifyPassWord(password, user.getSalt(), user.getPassword())) {
|
||
|
throw new MessageException(ResultCode.PASSWORD_ERROR);
|
||
|
}
|
||
|
//登录
|
||
|
SaTokenInfo saTokenInfo = UserUtil.loginAndTokenInfo(user.getSnowFlakeId());
|
||
|
//返回token
|
||
|
return new TokenInfo(saTokenInfo.getTokenName(), saTokenInfo.getTokenValue());
|
||
|
}
|
||
|
}
|