Skip to content

Commit

Permalink
Merge pull request #10 from tiwater/9-bug-use-same-jwt-as-the-builder
Browse files Browse the repository at this point in the history
fix: sync with builder's jwt
  • Loading branch information
shaoyie authored May 13, 2024
2 parents 21dd359 + 0e37687 commit bb73251
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 21 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ ENV CONDA_PREFIX /root/miniconda3/envs/py11
ENV PATH /root/miniconda3/bin:$PATH
ENV PATH $CONDA_PREFIX/bin:$PATH

ADD ./requirements.txt ./requirements.txt
RUN conda run -n py11 pip install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt
RUN conda run -n py11 pip install -i https://mirrors.aliyun.com/pypi/simple/ pocketbase --no-deps

ADD ./web ./web
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ To update the default HTTP serving port (80), go to [docker-compose.yml](./docke
To build the Docker images from source:
```bash
$ git clone https://github.com/infiniflow/ragflow.git
$ git clone https://github.com/tiwater/ragflow.git
$ cd ragflow/
$ docker build -t infiniflow/ragflow:dev .
$ docker build -t penless/ragflow:dev .
$ cd ragflow/docker
$ chmod +x ./entrypoint.sh
$ docker compose up -d
Expand All @@ -203,7 +203,7 @@ To launch the service from source, please follow these steps:
1. Clone the repository
```bash
$ git clone https://github.com/infiniflow/ragflow.git
$ git clone https://github.com/tiwater/ragflow.git
$ cd ragflow/
```
Expand Down
6 changes: 3 additions & 3 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@
ソースからDockerイメージをビルドするには:
```bash
$ git clone https://github.com/infiniflow/ragflow.git
$ git clone https://github.com/tiwater/ragflow.git
$ cd ragflow/
$ docker build -t infiniflow/ragflow:v0.5.0 .
$ docker build -t penless/ragflow:v0.5.0 .
$ cd ragflow/docker
$ chmod +x ./entrypoint.sh
$ docker compose up -d
Expand All @@ -195,7 +195,7 @@ $ docker compose up -d

1. リポジトリをクローンします
```bash
$ git clone https://github.com/infiniflow/ragflow.git
$ git clone https://github.com/tiwater/ragflow.git
$ cd ragflow/
```

Expand Down
6 changes: 3 additions & 3 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@
如需从源码安装 Docker 镜像:
```bash
$ git clone https://github.com/infiniflow/ragflow.git
$ git clone https://github.com/tiwater/ragflow.git
$ cd ragflow/
$ docker build -t infiniflow/ragflow:v0.5.0 .
$ docker build -t penless/ragflow:v0.5.0 .
$ cd ragflow/docker
$ chmod +x ./entrypoint.sh
$ docker compose up -d
Expand All @@ -194,7 +194,7 @@ $ docker compose up -d

1. 克隆仓库
```bash
$ git clone https://github.com/infiniflow/ragflow.git
$ git clone https://github.com/tiwater/ragflow.git
$ cd ragflow/
```

Expand Down
13 changes: 10 additions & 3 deletions api/apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from api.utils.user_utils import user_register, rollback_user_registration
from api.utils import get_format_time
from threading import Lock
import jwt
registration_lock = Lock()

__all__ = ['app']
Expand Down Expand Up @@ -121,15 +122,21 @@ def register_page(page_path):
# return None

# Integrate with Penless

@login_manager.request_loader
def load_user(web_request):
pb = PocketBase(POCKETBASE_HOST)
jwt = Serializer(secret_key=SECRET_KEY)
authorization = web_request.headers.get("Authorization")
stat_logger.warning(authorization)
if authorization:
try:
pb.auth_store.base_token=str(jwt.loads(authorization))
# Remove the 'Bearer ' prefix from the token if it exists
if authorization.startswith('Bearer '):
authorization = authorization[len('Bearer '):]

# Decode the token
decoded_token = jwt.decode(authorization, SECRET_KEY, algorithms=["HS256"])
pb.auth_store.base_token = str(decoded_token['access_token'])

pb.collection("users").authRefresh()

if pb.auth_store.model and pb.auth_store.model.id:
Expand Down
2 changes: 0 additions & 2 deletions api/apps/user_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ def login():
email = request.json.get('email', "")

password = request.json.get('password')

stat_logger.warning(f"login request: email={email}, password={password}")
try:
res = pb.collection("users").auth_with_password(email, password)
if res:
Expand Down
5 changes: 3 additions & 2 deletions api/db/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from api.settings import DATABASE, stat_logger, SECRET_KEY
from api.utils.log_utils import getLogger
from api import utils
import jwt

LOGGER = getLogger()

Expand Down Expand Up @@ -413,8 +414,8 @@ def __str__(self):
return self.email

def get_id(self):
jwt = Serializer(secret_key=SECRET_KEY)
return jwt.dumps(str(self.access_token))
encoded_jwt = jwt.encode({'access_token': str(self.access_token)}, SECRET_KEY, algorithm='HS256')
return encoded_jwt

class Meta:
db_table = "user"
Expand Down
2 changes: 1 addition & 1 deletion api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
RAG_FLOW_SERVICE_NAME,
{}).get(
"secret_key",
"infiniflow")
"penless")
TOKEN_EXPIRE_IN = get_base_config(
RAG_FLOW_SERVICE_NAME, {}).get(
"token_expires_in", 3600)
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose-CN-oc9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
condition: service_healthy
es01:
condition: service_healthy
image: edwardelric233/ragflow:oc9
image: penless/ragflow:oc9
container_name: ragflow-server
ports:
- ${SVR_HTTP_PORT}:9380
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
condition: service_healthy
es01:
condition: service_healthy
image: swr.cn-north-4.myhuaweicloud.com/infiniflow/ragflow:${RAGFLOW_VERSION}
image: penless/ragflow:${RAGFLOW_VERSION}
container_name: ragflow-server
ports:
- ${SVR_HTTP_PORT}:9380
Expand Down
11 changes: 9 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
condition: service_healthy
es01:
condition: service_healthy
image: swr.cn-north-4.myhuaweicloud.com/infiniflow/ragflow:${RAGFLOW_VERSION}
image: penless/ragflow:${RAGFLOW_VERSION}
container_name: ragflow-server
ports:
- ${SVR_HTTP_PORT}:9380
Expand All @@ -22,6 +22,7 @@ services:
- ./nginx/proxy.conf:/etc/nginx/proxy.conf
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- model_cache:/root/.cache
- ragflow_cache:/root/.ragflow
environment:
- TZ=${TIMEZONE}
- HF_ENDPOINT=https://huggingface.com
Expand All @@ -31,4 +32,10 @@ services:

volumes:
model_cache:
driver: local
driver: local
ragflow_cache:
driver: local

networks:
ragflow:
driver: bridge
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,4 @@ yarl==1.9.4
zhipuai==2.0.1
BCEmbedding
loguru==0.7.2
PyJWT==2.8.0
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,4 @@ BCEmbedding
loguru==0.7.2
ollama==0.1.8
redis==5.0.4
PyJWT==2.8.0

0 comments on commit bb73251

Please sign in to comment.