Skip to content

Commit 96a404b

Browse files
committed
完善readme
1 parent 95a3f68 commit 96a404b

55 files changed

Lines changed: 2312 additions & 21 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# ORANGE
22

3-
ORANGE is a Shadcn Admin UI built with `Shadcn` , `Vite` , `React`,`Zustand`,`React-Router`
3+
<img height="80" src="./readme/images/orange.png">
4+
5+
ORANGE is a full-stack project with a React frontend located in the vite-shadcn directory, a Java Spring Boot backend in the springboot directory, and a PostgreSQL database in the database directory. Future expansions will include additional frontend frameworks (Vue, Angular, etc.), backend languages (Go, Python, Node.js, Rust, C#, C++, etc.), and databases (MySQL, MariaDB, etc.).
6+
47

58
Project URL: https://yluiop123.github.io/orange
69

README.zh-CN.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# ORANGE
2+
<img height="80" src="./readme/images/orange.png">
23

3-
ORANGE 是一个基于 `Shadcn` , `Vite` , `React`,`Zustand`,`React-Router` 等构建的SHADCN ADMIN UI
4+
ORANGE 是一个前后端分离项目,前端在vite-shadcn目录下(react版本),后端在springboot目录下(java版本),数据库在database目录下(已实现postgres版本)。后期前端会扩展vue、angular等,后端会扩展(go、python、node、rust、c#、c++等),数据库会扩展mysql、mariadb等
45

56
项目访问地址: https://yluiop123.github.io/orange
67

nestjs/AUTH_README.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# NestJS 登录鉴权和权限守卫
2+
3+
## 功能概述
4+
5+
本项目实现了基于JWT的登录认证和权限控制系统。
6+
7+
## API 端点
8+
9+
### 认证相关
10+
11+
#### 登录
12+
```
13+
POST /auth/login
14+
Content-Type: application/json
15+
16+
{
17+
"username": "admin",
18+
"password": "password"
19+
}
20+
```
21+
22+
#### 注册
23+
```
24+
POST /auth/register
25+
Content-Type: application/json
26+
27+
{
28+
"username": "newuser",
29+
"password": "password",
30+
"name": "新用户",
31+
"email": "user@example.com"
32+
}
33+
```
34+
35+
### 用户管理 (需要认证)
36+
37+
所有用户管理API都需要在请求头中包含JWT token:
38+
```
39+
Authorization: Bearer <your-jwt-token>
40+
```
41+
42+
#### 查询用户
43+
```
44+
POST /api/system/users
45+
```
46+
47+
#### 添加用户
48+
```
49+
POST /api/system/users/add
50+
Content-Type: application/json
51+
52+
{
53+
"name": "张三",
54+
"username": "zhangsan",
55+
"password": "123456",
56+
"email": "zhangsan@example.com"
57+
}
58+
```
59+
60+
#### 编辑用户
61+
```
62+
POST /api/system/users/edit
63+
```
64+
65+
#### 删除用户
66+
```
67+
DELETE /api/system/users
68+
```
69+
70+
#### 获取用户详情
71+
```
72+
GET /api/system/users/detail/:userId
73+
```
74+
75+
## 权限控制
76+
77+
### 权限装饰器
78+
79+
使用 `@RequirePermissions` 装饰器为路由设置权限要求:
80+
81+
```typescript
82+
@Post()
83+
@RequirePermissions('user:add')
84+
async addUser(@Body() dto: AddUserDto) {
85+
// 只有拥有 'user:add' 权限的用户才能访问
86+
}
87+
```
88+
89+
### 守卫顺序
90+
91+
控制器使用以下守卫:
92+
1. `JwtAuthGuard` - 验证JWT token
93+
2. `PermissionGuard` - 检查用户权限
94+
95+
## 环境变量
96+
97+
设置以下环境变量:
98+
99+
```bash
100+
JWT_SECRET=your-secret-key
101+
POSTGRES_HOST=localhost
102+
POSTGRES_PORT=5432
103+
POSTGRES_USER=postgres
104+
POSTGRES_PASSWORD=postgres
105+
POSTGRES_DB=orange
106+
```
107+
108+
## 启动应用
109+
110+
```bash
111+
pnpm install
112+
pnpm run build
113+
pnpm run start:prod
114+
```
115+
116+
## 测试认证流程
117+
118+
1. 注册新用户或使用现有用户登录
119+
2. 使用返回的 `access_token` 在后续请求中设置 `Authorization`
120+
3. 访问受保护的API端点
121+
122+
## 注意事项
123+
124+
- 当前权限检查是简化的,所有已认证用户都可以访问所有API
125+
- 后续可以扩展为从数据库查询用户的实际权限
126+
- JWT token 默认24小时过期

nestjs/package.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,21 @@
2222
"dependencies": {
2323
"@nestjs/common": "^11.0.1",
2424
"@nestjs/core": "^11.0.1",
25+
"@nestjs/jwt": "^11.0.2",
26+
"@nestjs/passport": "^11.0.5",
2527
"@nestjs/platform-express": "^11.0.1",
28+
"@nestjs/typeorm": "^11.0.0",
29+
"@types/bcryptjs": "^3.0.0",
30+
"@types/passport-jwt": "^4.0.1",
31+
"bcryptjs": "^3.0.3",
32+
"class-transformer": "^0.5.1",
33+
"class-validator": "^0.15.1",
34+
"passport": "^0.7.0",
35+
"passport-jwt": "^4.0.1",
36+
"pg": "^8.20.0",
2637
"reflect-metadata": "^0.2.2",
27-
"rxjs": "^7.8.1"
38+
"rxjs": "^7.8.1",
39+
"typeorm": "^0.3.28"
2840
},
2941
"devDependencies": {
3042
"@eslint/eslintrc": "^3.2.0",

0 commit comments

Comments
 (0)