davidtran999 commited on
Commit
9afa8f1
·
verified ·
1 Parent(s): feba922

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +26 -34
README.md CHANGED
@@ -1,45 +1,37 @@
1
- ---
2
- title: Hue Portal Backend
3
- affiliation: Cong An Thanh Pho Hue
4
- colorFrom: green
5
- colorTo: blue
6
- sdk: docker
7
- pinned: false
8
- license: apache-2.0
9
- ---
10
 
11
- ## Deployment Notes
12
 
13
- This Space packages the Django backend (OCR + RAG stack) from the `TryHarDemNayProject` repo. It installs the full backend inside the container and exposes the API on port **7860** via Gunicorn.
14
 
15
- ### Environment variables required
 
 
 
 
 
16
 
17
- Set the following secrets in **Settings Repository secrets** before building the Space:
18
 
19
- | Variable | Description |
20
- |----------|-------------|
21
- | `DATABASE_URL` | PostgreSQL connection string (Railway instance) with `?sslmode=require`. |
22
- | `DJANGO_SECRET_KEY` | Secret key for Django. |
23
- | `DJANGO_ALLOWED_HOSTS` | e.g. `*.hf.space,localhost`. |
24
- | `DEFAULT_LLM_PROVIDER`, `LLM_PROVIDER`, etc. | Optional overrides reused from the original `.env`. |
 
 
25
 
26
- You can push these secrets via the helper script:
27
 
28
- ```bash
29
- cp ops/hf.secrets.env.example ops/hf.secrets.env
30
- # edit ops/hf.secrets.env with real values
31
- export HF_TOKEN=hf_xxx # token with write access to the Space
32
- python backend/scripts/update_hf_space_secrets.py \
33
- --space davidttran999/hue-portal-backendDocker \
34
- --secrets-file ops/hf.secrets.env
35
- ```
36
 
37
- ### Startup process
38
 
39
- `entrypoint.sh` automatically runs:
 
40
 
41
- 1. `python hue_portal/manage.py migrate`
42
- 2. `python hue_portal/manage.py createcachetable`
43
- 3. `gunicorn hue_portal.hue_portal.wsgi:application --bind 0.0.0.0:7860`
44
 
45
- Logs are streamed in the Space console. If migrations fail because the DB already contains the schema, re-run after fixing credentials or drop the DB manually.
 
1
+ ## Authentication & Authorization
 
 
 
 
 
 
 
 
2
 
3
+ ### Seed tài khoản mặc định
4
 
5
+ Sau khi thiết lập môi trường:
6
 
7
+ ```bash
8
+ cd backend/hue_portal
9
+ source ../venv/bin/activate
10
+ python manage.py migrate
11
+ python manage.py seed_default_users
12
+ ```
13
 
14
+ Các biến môi trường hỗ trợ tuỳ biến (tùy chọn):
15
 
16
+ | Biến | Mặc định |
17
+ |------|----------|
18
+ | `DEFAULT_ADMIN_USERNAME` | `admin` |
19
+ | `DEFAULT_ADMIN_EMAIL` | `admin@example.com` |
20
+ | `DEFAULT_ADMIN_PASSWORD` | `Admin@123` |
21
+ | `DEFAULT_USER_USERNAME` | `user` |
22
+ | `DEFAULT_USER_EMAIL` | `user@example.com` |
23
+ | `DEFAULT_USER_PASSWORD` | `User@123` |
24
 
25
+ ### API đăng nhập
26
 
27
+ - `POST /api/auth/login/` – body `{ "username": "...", "password": "..." }`
28
+ - `POST /api/auth/logout/` – body `{ "refresh": "<refresh_token>" }` (header `Authorization: Bearer <access>`)
29
+ - `GET /api/auth/me/` lấy thông tin user hiện tại
30
+ - `POST /api/auth/register/` chỉ admin gọi được; truyền thêm `role` (`admin` hoặc `user`) khi tạo tài khoản mới.
 
 
 
 
31
 
32
+ ### Phân quyền
33
 
34
+ - Upload tài liệu (`/api/legal-documents/upload/`) yêu cầu user role `admin` hoặc cung cấp header `X-Upload-Token`.
35
+ - Frontend hiển thị nút “Đăng nhập” ở trang chủ và trên thanh điều hướng. Khi đăng nhập thành công sẽ hiển thị tên + role, kèm nút “Đăng xuất”.
36
 
 
 
 
37