2024-08-29 17:06:00 +08:00
|
|
|
package com.changhu.enums.handler;
|
|
|
|
|
|
|
|
import cn.dev33.satoken.stp.SaTokenInfo;
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
2024-09-04 17:13:01 +08:00
|
|
|
import com.baomidou.mybatisplus.extension.toolkit.Db;
|
2024-09-06 14:54:14 +08:00
|
|
|
import com.changhu.common.annotation.UserType;
|
2024-08-29 17:06:00 +08:00
|
|
|
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;
|
2024-09-04 17:13:01 +08:00
|
|
|
import com.changhu.enums.ClientType;
|
2024-08-29 17:06:00 +08:00
|
|
|
import com.changhu.module.management.pojo.entity.ManagementSuperUser;
|
|
|
|
import com.changhu.pojo.params.ManagementSuperLoginParams;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author 20252
|
|
|
|
* @createTime 2024/8/28 下午5:25
|
|
|
|
* @desc ManagementSuperLogin...
|
|
|
|
*/
|
|
|
|
public class ManagementSuperLogin extends AbstractLoginHandler {
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
//用户是否存在
|
2024-09-04 17:13:01 +08:00
|
|
|
ManagementSuperUser user = Db.lambdaQuery(ManagementSuperUser.class)
|
2024-08-29 17:06:00 +08:00
|
|
|
.eq(ManagementSuperUser::getTelephone, telephone)
|
|
|
|
.oneOpt()
|
2024-09-03 10:51:15 +08:00
|
|
|
.orElseThrow(() -> new MessageException(ResultCode.USER_NOT_FOUND));
|
2024-08-29 17:06:00 +08:00
|
|
|
|
|
|
|
//判断密码是否正确
|
|
|
|
if (!UserUtil.verifyPassWord(password, user.getSalt(), user.getPassword())) {
|
|
|
|
throw new MessageException(ResultCode.PASSWORD_ERROR);
|
|
|
|
}
|
|
|
|
//登录
|
2024-09-04 17:13:01 +08:00
|
|
|
SaTokenInfo saTokenInfo = UserUtil.loginAndTokenInfo(
|
|
|
|
user.getSnowFlakeId(),
|
2024-09-06 14:54:14 +08:00
|
|
|
UserType.MANAGEMENT_SUPER,
|
2024-09-04 17:13:01 +08:00
|
|
|
null);
|
2024-08-29 17:06:00 +08:00
|
|
|
//返回token
|
|
|
|
return new TokenInfo(saTokenInfo.getTokenName(), saTokenInfo.getTokenValue());
|
|
|
|
}
|
|
|
|
}
|