feat: SaToken
This commit is contained in:
@@ -70,23 +70,12 @@
|
||||
<version>3.11</version>
|
||||
</dependency>
|
||||
|
||||
<!-- <!– Sa-Token 权限认证,在线文档:https://sa-token.cc –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>cn.dev33</groupId>-->
|
||||
<!-- <artifactId>sa-token-spring-boot-starter</artifactId>-->
|
||||
<!-- <version>1.37.0</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <!– Sa-Token 整合 Redis (使用 jackson 序列化方式) –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>cn.dev33</groupId>-->
|
||||
<!-- <artifactId>sa-token-redis-jackson</artifactId>-->
|
||||
<!-- <version>1.37.0</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <!– 提供Redis连接池 –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.apache.commons</groupId>-->
|
||||
<!-- <artifactId>commons-pool2</artifactId>-->
|
||||
<!-- <version>2.9.0</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- Sa-Token 权限认证,在线文档:https://sa-token.cc -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-spring-boot-starter</artifactId>
|
||||
<version>1.37.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.landaiqing.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.SaTokenInfo;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.base.Preconditions;
|
||||
@@ -21,7 +22,9 @@ import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Classname StudentController
|
||||
@@ -132,7 +135,7 @@ public class StudentController {
|
||||
* @date: 2024/3/5 17:28
|
||||
*/
|
||||
@RequestMapping("login")
|
||||
public Result<Boolean> login(@RequestBody StudentDTO studentDTO) {
|
||||
public Result<SaTokenInfo> login(@RequestBody StudentDTO studentDTO) {
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("StudentController.queryStudentPermission.dto:{}", JSON.toJSONString(studentDTO));
|
||||
@@ -140,11 +143,11 @@ public class StudentController {
|
||||
Preconditions.checkArgument(!StringUtils.isBlank(studentDTO.getUsername()), "用户名不能为空!");
|
||||
Preconditions.checkArgument(!StringUtils.isBlank(studentDTO.getPassword()), "密码不能为空!");
|
||||
StudentBO studentBO = StudentInfoDtoConvert.INSTANCE.convertDtoToBO(studentDTO);
|
||||
Boolean result = studentDomainService.login(studentBO);
|
||||
return Result.ok(result);
|
||||
SaTokenInfo saTokenInfo = studentDomainService.login(studentBO);
|
||||
return Result.ok(saTokenInfo);
|
||||
} catch (Exception e) {
|
||||
log.error("StudentController.queryStudentPermission.error:{}", e.getMessage(), e);
|
||||
return Result.fail("查询失败失败!");
|
||||
log.error("StudentController.login.error:{}", e.getMessage(), e);
|
||||
return Result.fail("登录失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.landaiqing.domain.service;
|
||||
|
||||
import cn.dev33.satoken.stp.SaTokenInfo;
|
||||
import com.landaiqing.auth.common.entity.PageResult;
|
||||
import com.landaiqing.domain.bo.StudentBO;
|
||||
|
||||
@@ -11,5 +12,5 @@ public interface StudentDomainService {
|
||||
|
||||
PageResult<StudentBO> queryAllStudentByPage(StudentBO studentBO);
|
||||
|
||||
Boolean login(StudentBO studentBO);
|
||||
SaTokenInfo login(StudentBO studentBO);
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package com.landaiqing.domain.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.SaTokenInfo;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.landaiqing.auth.common.entity.PageResult;
|
||||
import com.landaiqing.auth.common.enums.IsDeletedFlagEnum;
|
||||
import com.landaiqing.domain.bo.StudentBO;
|
||||
@@ -58,10 +60,12 @@ public class StudentDomainServiceImpl implements StudentDomainService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean login(StudentBO studentBO) {
|
||||
public SaTokenInfo login(StudentBO studentBO) {
|
||||
Student student = StudentBOConvert.INSTANCE.convertBOToEntity(studentBO);
|
||||
Integer count= studentService.login(student);
|
||||
return count>0;
|
||||
Integer id= studentService.login(student);
|
||||
StpUtil.login(id);
|
||||
SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
|
||||
return tokenInfo;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -151,7 +151,7 @@ id,sno,password,username,class_name,grade,age,sex,avatar,date_of_birth,email,pho
|
||||
select count(1) from student
|
||||
</select>
|
||||
<select id="login" resultType="java.lang.Integer">
|
||||
select * from student
|
||||
select id from student
|
||||
where username=#{username}
|
||||
and password=#{password}
|
||||
</select>
|
||||
|
@@ -61,22 +61,22 @@ logging:
|
||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
############## Sa-Token 配置 (文档: https://sa-token.cc) ##############
|
||||
#sa-token:
|
||||
# # token 名称(同时也是 cookie 名称)
|
||||
# token-name: satoken
|
||||
# # token 有效期(单位:秒) 默认30天,-1 代表永久有效
|
||||
# timeout: 2592000
|
||||
# # token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
|
||||
# active-timeout: -1
|
||||
# # 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录)
|
||||
# is-concurrent: true
|
||||
# # 在多人登录同一账号时,是否共用一个 token (为 true 时所有登录共用一个 token, 为 false 时每次登录新建一个 token)
|
||||
# is-share: true
|
||||
# # token 风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik)
|
||||
# token-style: random-32
|
||||
# # 是否输出操作日志
|
||||
# is-log: true
|
||||
# token-prefix: auth
|
||||
sa-token:
|
||||
# token 名称(同时也是 cookie 名称)
|
||||
token-name: satoken
|
||||
# token 有效期(单位:秒) 默认30天,-1 代表永久有效
|
||||
timeout: 2592000
|
||||
# token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
|
||||
active-timeout: -1
|
||||
# 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录)
|
||||
is-concurrent: true
|
||||
# 在多人登录同一账号时,是否共用一个 token (为 true 时所有登录共用一个 token, 为 false 时每次登录新建一个 token)
|
||||
is-share: true
|
||||
# token 风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik)
|
||||
token-style: random-32
|
||||
# 是否输出操作日志
|
||||
is-log: true
|
||||
token-prefix: auth
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user