diff --git a/sa-token-demo/sa-token-demo-remeber-me/page_project/.gitignore b/sa-token-demo/sa-token-demo-remeber-me/page_project/.gitignore new file mode 100644 index 00000000..cc5b432e --- /dev/null +++ b/sa-token-demo/sa-token-demo-remeber-me/page_project/.gitignore @@ -0,0 +1,23 @@ +# vite创建项目时自动生成的git忽略配置文件 +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/sa-token-demo/sa-token-demo-remeber-me/page_project/README.md b/sa-token-demo/sa-token-demo-remeber-me/page_project/README.md new file mode 100644 index 00000000..6be21563 --- /dev/null +++ b/sa-token-demo/sa-token-demo-remeber-me/page_project/README.md @@ -0,0 +1,11 @@ +# Vue 3 + Vite + +[Node下载地址](https://nodejs.org/zh-cn/) + +安装最新版本Node环境, 然后执行如下命令开启开发服务: +``` +npm install +npm run dev +``` + +[cookie/sessionstorage/localstorage三者的区别](https://blog.csdn.net/weixin_45541388/article/details/125367823) diff --git a/sa-token-demo/sa-token-demo-remeber-me/page_project/index.html b/sa-token-demo/sa-token-demo-remeber-me/page_project/index.html new file mode 100644 index 00000000..6bb3cf29 --- /dev/null +++ b/sa-token-demo/sa-token-demo-remeber-me/page_project/index.html @@ -0,0 +1,12 @@ + + + + + + 记住我模式Demo页面 + + +
+ + + diff --git a/sa-token-demo/sa-token-demo-remeber-me/page_project/package.json b/sa-token-demo/sa-token-demo-remeber-me/page_project/package.json new file mode 100644 index 00000000..aab21333 --- /dev/null +++ b/sa-token-demo/sa-token-demo-remeber-me/page_project/package.json @@ -0,0 +1,22 @@ +{ + "name": "page_project", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "vite build", + "preview": "vite preview" + }, + "dependencies": { + "axios": "^1.3.4", + "element-plus": "^2.2.33", + "qs": "^6.11.0", + "vue": "^3.2.45", + "vue-axios": "^3.5.2" + }, + "devDependencies": { + "@vitejs/plugin-vue": "^4.0.0", + "vite": "^4.1.0" + } +} diff --git a/sa-token-demo/sa-token-demo-remeber-me/page_project/src/App.vue b/sa-token-demo/sa-token-demo-remeber-me/page_project/src/App.vue new file mode 100644 index 00000000..63ab65b1 --- /dev/null +++ b/sa-token-demo/sa-token-demo-remeber-me/page_project/src/App.vue @@ -0,0 +1,161 @@ + + + + + \ No newline at end of file diff --git a/sa-token-demo/sa-token-demo-remeber-me/page_project/src/main.js b/sa-token-demo/sa-token-demo-remeber-me/page_project/src/main.js new file mode 100644 index 00000000..dcd05f43 --- /dev/null +++ b/sa-token-demo/sa-token-demo-remeber-me/page_project/src/main.js @@ -0,0 +1,20 @@ +import { createApp } from 'vue' +import App from './App.vue' +import axios from 'axios' // 请求发送接收工具 +import VueAxios from 'vue-axios' // vue封装axios +import qs from 'qs' // axios请求参数类型封装 +import ElementPlus from 'element-plus' // elementUI for vue3 +import 'element-plus/dist/index.css' // 加载elementUI样式 +import zhCn from 'element-plus/es/locale/lang/zh-cn' // 引入中文本地化组件 + + +app = createApp(App) + +// vue组件内通过 this.$f() 来调用 +app.config.globalProperties.$f = (params) => { + return qs.stringify(params) +} + +app.use(VueAxios, axios) +.use(ElementPlus, { locale: zhCn }) +.mount('#app') diff --git a/sa-token-demo/sa-token-demo-remeber-me/page_project/vite.config.js b/sa-token-demo/sa-token-demo-remeber-me/page_project/vite.config.js new file mode 100644 index 00000000..f4ad736d --- /dev/null +++ b/sa-token-demo/sa-token-demo-remeber-me/page_project/vite.config.js @@ -0,0 +1,17 @@ +import { defineConfig } from 'vite' +import vue from '@vitejs/plugin-vue' + +// 开启代理服务 +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [vue()], + server: { + port: 5173, + host: true, + proxy: { + '^/back/.*$': { + target: 'http://localhost:80' + } + } + } +}) diff --git a/sa-token-demo/sa-token-demo-remeber-me/server_project/pom.xml b/sa-token-demo/sa-token-demo-remeber-me/server_project/pom.xml new file mode 100644 index 00000000..af9c50ef --- /dev/null +++ b/sa-token-demo/sa-token-demo-remeber-me/server_project/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + + cn.dev33 + remember_me + 1.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-parent + 2.5.14 + + + + + 1.34.0 + + + + + + org.springframework.boot + spring-boot-starter-web + + + + + cn.dev33 + sa-token-spring-boot-starter + ${sa-token.version} + + + + + cn.dev33 + sa-token-dao-redis-jackson + ${sa-token.version} + + + org.apache.commons + commons-pool2 + + + \ No newline at end of file diff --git a/sa-token-demo/sa-token-demo-remeber-me/server_project/src/main/java/cc/sa_token/RememberMeApplication.java b/sa-token-demo/sa-token-demo-remeber-me/server_project/src/main/java/cc/sa_token/RememberMeApplication.java new file mode 100644 index 00000000..ab7757bc --- /dev/null +++ b/sa-token-demo/sa-token-demo-remeber-me/server_project/src/main/java/cc/sa_token/RememberMeApplication.java @@ -0,0 +1,11 @@ +package cc.sa_token; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class RememberMeApplication { + public static void main(String[] args) { + SpringApplication.run(RememberMeApplication.class, args); + } +} \ No newline at end of file diff --git a/sa-token-demo/sa-token-demo-remeber-me/server_project/src/main/java/cc/sa_token/controller/UserLoginController.java b/sa-token-demo/sa-token-demo-remeber-me/server_project/src/main/java/cc/sa_token/controller/UserLoginController.java new file mode 100644 index 00000000..fcfd7fe1 --- /dev/null +++ b/sa-token-demo/sa-token-demo-remeber-me/server_project/src/main/java/cc/sa_token/controller/UserLoginController.java @@ -0,0 +1,37 @@ +package cc.sa_token.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; + +@RestController +@RequestMapping("/back/user") +public class UserLoginController { + + @RequestMapping("/login") + public SaResult doLogin(String name, String pwd, Boolean remember) { + if("zhang".equals(name) && "123456".equals(pwd)) { + StpUtil.login(10001, remember); + SaTokenInfo tokenInfo = StpUtil.getTokenInfo(); + return SaResult.ok() + .set("tokenName", tokenInfo.getTokenName()) + .set("tokenValue", tokenInfo.getTokenValue()); + } else { + return SaResult.error("登录失败"); + } + } + + @RequestMapping("/state") + public SaResult checkNowLoginState() { + return SaResult.ok().setData(StpUtil.isLogin()); + } + + @RequestMapping("/logout") + public SaResult doLogout() { + StpUtil.logout(); + return SaResult.ok().setData(StpUtil.isLogin()); + } + +} diff --git a/sa-token-demo/sa-token-demo-remeber-me/server_project/src/main/resources/application.yml b/sa-token-demo/sa-token-demo-remeber-me/server_project/src/main/resources/application.yml new file mode 100644 index 00000000..424afda2 --- /dev/null +++ b/sa-token-demo/sa-token-demo-remeber-me/server_project/src/main/resources/application.yml @@ -0,0 +1,51 @@ +# 端口 +server: + port: 80 + +# sa-token配置 +sa-token: + # token名称 (同时也是cookie名称) + token-name: satoken + # token有效期,单位s 默认30天, -1代表永不过期 + timeout: 2592000 + # token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒 + activity-timeout: -1 + # 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录) + is-concurrent: true + # 禁止写入cookie + is-read-cookie: false + # 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token) + is-share: false + # token风格 + token-style: uuid + # 是否输出操作日志 + is-log: false + +spring: + # redis配置 + redis: + # Redis数据库索引(默认为0) + database: 0 + # Redis服务器地址 + host: 127.0.0.1 + # Redis服务器连接端口 + port: 6379 + # Redis服务器连接密码(默认为空) + password: + # 连接超时时间 + timeout: 10s + lettuce: + pool: + # 连接池最大连接数 + max-active: 200 + # 连接池最大阻塞等待时间(使用负值表示没有限制) + max-wait: -1ms + # 连接池中的最大空闲连接 + max-idle: 10 + # 连接池中的最小空闲连接 + min-idle: 0 + + + + + \ No newline at end of file