Skip to content

Commit c85dd1e

Browse files
committed
initial commit
1 parent b7e0f74 commit c85dd1e

8 files changed

Lines changed: 1424 additions & 2 deletions

File tree

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM python:3.10.10
2+
3+
WORKDIR /app
4+
5+
RUN pip install --upgrade pip
6+
7+
COPY requirements.txt requirements.txt
8+
9+
RUN pip install -r requirements.txt
10+
11+
COPY . .
12+
13+
EXPOSE 8080
14+
15+
ENV PYTHONUNBUFFERED=1
16+
17+
CMD ["uvicorn", "--host", "0.0.0.0", "--port", "8080", "main:app"]

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,42 @@
11
# Backend-API
2+
Hiya! Gabriel here, this repo is for the backend of the app (ai model not included). Some of the features :
3+
- Auth
4+
- Article
5+
- Forum
6+
- Image resizer
7+
- Comment system
8+
9+
## how to use
10+
install the requirements
11+
```bash
12+
pip install -r requirements.txt
13+
```
14+
boot uvicorn
15+
```bash
16+
uvicorn main:app
17+
```
18+
or
19+
```bash
20+
python3 -m uvicorn main:app
21+
```
22+
ENV list
23+
```
24+
> PORT
25+
> cres (service account for cloud storage)
26+
> secret
27+
> algorithm
28+
> dbase
29+
> duser
30+
> dpw
31+
> dip
32+
```
33+
34+
35+
236
# side-API
3-
**Api things in case I forgot**
37+
**Development notes**
438
here me testing before making the api,
5-
before that the sql relation will look like this :
39+
before that the sql relation will look like this :
640
![enter image description here](https://cdn.discordapp.com/attachments/1023598916857499680/1106228887899357225/image.png)
741
So we got 3 tables in total to make: users, article, comps
842
in article we have 5 parameters:

app/auth/jwt_bearer.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# authorization (verify the route)
2+
from fastapi import Request, HTTPException
3+
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
4+
from .jwt_handler import decodeJWT
5+
6+
7+
class jwtBearer(HTTPBearer):
8+
def __init__(self, auto_Error : bool = True):
9+
super(jwtBearer, self).__init__(auto_error=auto_Error)
10+
11+
async def __call__(self, request : Request):
12+
credentials : HTTPAuthorizationCredentials = await super(jwtBearer,
13+
self).__call__(request)
14+
if credentials:
15+
if not credentials.scheme == "Bearer":
16+
raise HTTPException(status_code = 403, details="token is no longer available :(((")
17+
return credentials.credentials
18+
#for any reason why everything is not according to plan we still will make fun of their's credentials
19+
else:
20+
raise HTTPException(status_code = 403, details="token is no longer available :(((")
21+
22+
def verify_jwt(self, jwtoken : str):
23+
isTokenValid : bool = False # a false flag
24+
payload = decodeJWT(jwtoken)
25+
if payload:
26+
isTokenValid = True
27+
28+
29+
return isTokenValid

app/auth/jwt_handler.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#this file for encoding and decoding and returning jwts
2+
import hashlib
3+
import jwt
4+
import time
5+
from decouple import config
6+
from typing import Dict
7+
8+
JWT_SECRET = config("secret")
9+
JWT_ALGORITHM = config("algorithm")
10+
11+
#deez generated tokens (jwts)
12+
def token_response(token: str):
13+
return{
14+
"access token": token
15+
}
16+
17+
def signJWT(userID : str):
18+
payload = {
19+
"userID" : userID,
20+
"expiry" : time.time() + 600
21+
}
22+
token = jwt.encode(payload,JWT_SECRET, algorithm=JWT_ALGORITHM)
23+
return token_response(token)
24+
25+
26+
def decodeJWT(token:str):
27+
try:
28+
decode_token = jwt.decode(token, JWT_SECRET, algorithm=JWT_ALGORITHM)
29+
return decode_token if decode_token['expires'] >= time.time()else None
30+
except:
31+
return {}
32+
33+
34+
35+

0 commit comments

Comments
 (0)