Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Riveong committed Jun 8, 2023
1 parent b7e0f74 commit c85dd1e
Show file tree
Hide file tree
Showing 8 changed files with 1,424 additions and 2 deletions.
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.10.10

WORKDIR /app

RUN pip install --upgrade pip

COPY requirements.txt requirements.txt

RUN pip install -r requirements.txt

COPY . .

EXPOSE 8080

ENV PYTHONUNBUFFERED=1

CMD ["uvicorn", "--host", "0.0.0.0", "--port", "8080", "main:app"]
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,42 @@
# Backend-API
Hiya! Gabriel here, this repo is for the backend of the app (ai model not included). Some of the features :
- Auth
- Article
- Forum
- Image resizer
- Comment system

## how to use
install the requirements
```bash
pip install -r requirements.txt
```
boot uvicorn
```bash
uvicorn main:app
```
or
```bash
python3 -m uvicorn main:app
```
ENV list
```
> PORT
> cres (service account for cloud storage)
> secret
> algorithm
> dbase
> duser
> dpw
> dip
```



# side-API
**Api things in case I forgot**
**Development notes**
here me testing before making the api,
before that the sql relation will look like this :
before that the sql relation will look like this :
![enter image description here](https://cdn.discordapp.com/attachments/1023598916857499680/1106228887899357225/image.png)
So we got 3 tables in total to make: users, article, comps
in article we have 5 parameters:
Expand Down
29 changes: 29 additions & 0 deletions app/auth/jwt_bearer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# authorization (verify the route)
from fastapi import Request, HTTPException
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from .jwt_handler import decodeJWT


class jwtBearer(HTTPBearer):
def __init__(self, auto_Error : bool = True):
super(jwtBearer, self).__init__(auto_error=auto_Error)

async def __call__(self, request : Request):
credentials : HTTPAuthorizationCredentials = await super(jwtBearer,
self).__call__(request)
if credentials:
if not credentials.scheme == "Bearer":
raise HTTPException(status_code = 403, details="token is no longer available :(((")
return credentials.credentials
#for any reason why everything is not according to plan we still will make fun of their's credentials
else:
raise HTTPException(status_code = 403, details="token is no longer available :(((")

def verify_jwt(self, jwtoken : str):
isTokenValid : bool = False # a false flag
payload = decodeJWT(jwtoken)
if payload:
isTokenValid = True


return isTokenValid
35 changes: 35 additions & 0 deletions app/auth/jwt_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#this file for encoding and decoding and returning jwts
import hashlib
import jwt
import time
from decouple import config
from typing import Dict

JWT_SECRET = config("secret")
JWT_ALGORITHM = config("algorithm")

#deez generated tokens (jwts)
def token_response(token: str):
return{
"access token": token
}

def signJWT(userID : str):
payload = {
"userID" : userID,
"expiry" : time.time() + 600
}
token = jwt.encode(payload,JWT_SECRET, algorithm=JWT_ALGORITHM)
return token_response(token)


def decodeJWT(token:str):
try:
decode_token = jwt.decode(token, JWT_SECRET, algorithm=JWT_ALGORITHM)
return decode_token if decode_token['expires'] >= time.time()else None
except:
return {}




Loading

0 comments on commit c85dd1e

Please sign in to comment.