登录信息

This commit is contained in:
黎润豪 2025-10-24 15:30:53 +08:00
parent 91c94c55fe
commit 3ead8762a3
1 changed files with 7 additions and 35 deletions

View File

@ -2,18 +2,16 @@ package com.chinaweal.youfool.course.controller;
import cn.dev33.satoken.session.SaSession; import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import com.chinaweal.youfool.course.common.constants.SessionConstants;
import com.chinaweal.youfool.course.entity.SysUser; import com.chinaweal.youfool.course.entity.SysUser;
import com.chinaweal.youfool.course.entity.UserBaseExtend; import com.chinaweal.youfool.course.entity.UserBaseExtend;
import com.chinaweal.youfool.course.service.SysUserService; import com.chinaweal.youfool.course.service.SysUserService;
import com.chinaweal.youfool.framework.springboot.common.base.BaseController;
import com.chinaweal.youfool.framework.springboot.common.util.AssertUtils; import com.chinaweal.youfool.framework.springboot.common.util.AssertUtils;
import com.chinaweal.youfool.framework.springboot.common.util.RSAUtil;
import com.chinaweal.youfool.framework.springboot.rest.BaseResultCode; import com.chinaweal.youfool.framework.springboot.rest.BaseResultCode;
import com.chinaweal.youfool.framework.springboot.rest.RestResult; import com.chinaweal.youfool.framework.springboot.rest.RestResult;
import com.chinaweal.youfool.framework.springboot.user.entity.UserBase; import com.chinaweal.youfool.framework.springboot.user.entity.UserBase;
import com.chinaweal.youfool.framework.springboot.user.service.UserBaseService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -32,33 +30,24 @@ import java.util.Set;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/user/auth") @RequestMapping("/user/auth")
@RequiredArgsConstructor
public class LoginController { public class LoginController {
@Autowired private final SysUserService sysUserService;
private SysUserService sysUserService; private final UserBaseService userBaseService;
/** /**
* 登录接口 * 登录接口
* *
* @param username 用户名 * @param username 用户名
* @param password 密码 * @param password 密码
* @param encrypt 密码是否已经加密
* @return 登录结果 * @return 登录结果
* @author lroyia * @author lroyia
* @since 2022年4月20日 15:47:35 * @since 2022年4月20日 15:47:35
*/ */
@PostMapping("login") @PostMapping("login")
public RestResult<?> doLogin(String username, String password, Boolean encrypt) { public RestResult<?> doLogin(String username, String password) {
AssertUtils.isNotBlank(username, password); AssertUtils.isNotBlank(username, password);
if (encrypt != null && encrypt) {
String privateKey = getPrivateKey();
try {
password = RSAUtil.decrypt(password, privateKey);
} catch (Exception e) {
log.error("密码解密失败:{}", password, e);
return RestResult.error(BaseResultCode.BUSINESS_LOGIC_ERROR, "密码解密失败");
}
}
// 查询用户信息 // 查询用户信息
SysUser sysUser = sysUserService.getUserByUsername(username); SysUser sysUser = sysUserService.getUserByUsername(username);
@ -84,18 +73,6 @@ public class LoginController {
return RestResult.ok(); return RestResult.ok();
} }
/**
* 获取当前持有的公钥
*
* @return 获取结果
* @author lroyia
* @since 2022年4月20日 15:55:13
*/
@GetMapping("publicKey")
public RestResult<String> getCurrentPublicKey() {
return RestResult.ok(getPublicKey());
}
/** /**
* 登录信息 * 登录信息
* *
@ -105,12 +82,7 @@ public class LoginController {
*/ */
@GetMapping("login/info") @GetMapping("login/info")
public RestResult<UserBase> loginInfo() { public RestResult<UserBase> loginInfo() {
boolean login = StpUtil.isLogin(); return RestResult.ok(userBaseService.getCurrentUser());
if (login) {
SaSession session = getSession();
return RestResult.ok((UserBase) session.get(SessionConstants.USER_KEY));
}
return RestResult.ok(null);
} }
/** /**