generated from youfool-project/youfool-prj-springboot-template
登录信息
This commit is contained in:
parent
91c94c55fe
commit
3ead8762a3
|
|
@ -2,18 +2,16 @@ package com.chinaweal.youfool.course.controller;
|
|||
|
||||
import cn.dev33.satoken.session.SaSession;
|
||||
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.UserBaseExtend;
|
||||
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.RSAUtil;
|
||||
import com.chinaweal.youfool.framework.springboot.rest.BaseResultCode;
|
||||
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
|
@ -32,33 +30,24 @@ import java.util.Set;
|
|||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/user/auth")
|
||||
@RequiredArgsConstructor
|
||||
public class LoginController {
|
||||
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
private final SysUserService sysUserService;
|
||||
private final UserBaseService userBaseService;
|
||||
|
||||
/**
|
||||
* 登录接口
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
* @param encrypt 密码是否已经加密
|
||||
* @return 登录结果
|
||||
* @author lroyia
|
||||
* @since 2022年4月20日 15:47:35
|
||||
*/
|
||||
@PostMapping("login")
|
||||
public RestResult<?> doLogin(String username, String password, Boolean encrypt) {
|
||||
public RestResult<?> doLogin(String username, String 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);
|
||||
|
|
@ -84,18 +73,6 @@ public class LoginController {
|
|||
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")
|
||||
public RestResult<UserBase> loginInfo() {
|
||||
boolean login = StpUtil.isLogin();
|
||||
if (login) {
|
||||
SaSession session = getSession();
|
||||
return RestResult.ok((UserBase) session.get(SessionConstants.USER_KEY));
|
||||
}
|
||||
return RestResult.ok(null);
|
||||
return RestResult.ok(userBaseService.getCurrentUser());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue