feat: auth develop

This commit is contained in:
2024-02-18 15:07:07 +08:00
parent 4e025dc47d
commit 3d475f690f
9 changed files with 68 additions and 97 deletions

View File

@@ -37,5 +37,11 @@
<artifactId>jc-club-auth-domain</artifactId>
<version>1.0-SNAPSHOT</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>

View File

@@ -1,13 +0,0 @@
package com.landaiqing;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

View File

@@ -0,0 +1,42 @@
package com.landaiqing.auth.application.controller;
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Classname UserController
* @BelongsProject: jc-club
* @BelongsPackage: com.landaiqing.auth.application.controller
* @Author: landaiqing
* @CreateTime: 2024-02-18 14:24
* @Description: TODO
* @Version: 1.0
*/
@RestController
@RequestMapping("/user/")
public class UserController {
// 测试登录,浏览器访问: http://localhost:3001/user/doLogin?username=zhang&password=123456
@RequestMapping("doLogin")
public SaResult doLogin(String username, String password) {
// 此处仅作模拟示例,真实项目需要从数据库中查询数据进行比对
if("zhang".equals(username) && "123456".equals(password)) {
StpUtil.login(10001);
SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
// 第3步返回给前端
return SaResult.data(tokenInfo);
}
return SaResult.error("登录失败");
}
// 查询登录状态,浏览器访问: http://localhost:3001/user/isLogin
@RequestMapping("isLogin")
public String isLogin() {
return "当前会话是否登录:" + StpUtil.isLogin();
}
}

View File

@@ -1,38 +0,0 @@
package com.landaiqing;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}