Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ test.py
temp.txt
utilities\login.py
settings.json
launch.json
testIgnore
legacy

# C extensions
*.so
Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,29 @@
│ ├── user
│ │ ├── __init__.py
│ │ ├── route.py
│ ├── board
│ │ ├── __init__.py
│ │ ├── route.py
│ ├── auth
│ │ ├── __init__.py
│ │ ├── route.py
├── test
│ ├── mealList
│ ├── temp.py
│ ├── testAuthCode.py
│ ├── testMealConverter.py
│ ├── testRunEmail.py
├── utilities
│ ├── __init__.py
│ ├── config.py
│ ├── logger.py
│ ├── emailSender.py
│ ├── http.py
│ ├── logger.py
│ ├── mealJSONConverter.py
│ ├── security.py
│ ├── userGenerator.py
│ ├── database
│ │ ├── func.py
│ │ ├── schema.py
├── config.ini
├── config.example.ini
├── requirements.txt
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ scrypt
pytz
pick
pyjwt
python-barcode
pillow
aiosmtplib
Empty file added routes/auth/__init__.py
Empty file.
61 changes: 61 additions & 0 deletions routes/auth/route.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from fastapi import APIRouter, Request
from fastapi.responses import JSONResponse

from utilities.config import GetConfig
from utilities.database.func import GetDatabase
from utilities.emailSender import SendEmail


router = APIRouter()

config = GetConfig()

database = GetDatabase(config["DATABASE"]["URI"])


@router.get("/send/{userId}/")
async def SendEmailToUser(request: Request, userId: str):
findUser = await database["pending"].find_one({"userId": userId})

if findUser is None:
return JSONResponse(
status_code=500, content={"message": "Pending User Not Found"}
)

await SendEmail(
receiver=findUser["email"],
subject="늘봄 이메일 인증 코드",
content="귀하의 이메일 인증 코드는 다음과 같습니다. : "
+ findUser["authCode"]
+ "\n대문자로 입력해주세요.",
)

return JSONResponse(
status_code=200, content={"message": "Email sent to " + findUser["email"]}
)


@router.post("/check/{userId}")
async def AuthPendingUser(request: Request, userId):
findUser = await database["pending"].find_one({"userId": userId})
authData = await request.json()

if findUser is None:
return JSONResponse(
status_code=500, content={"message": "Pending User Not Found"}
)

if await database["pending"].find_one({"authCode": authData["authCode"]}) is None:
return JSONResponse(
status_code=400, content={"message": "Invalid Authorization Code"}
)

del findUser["authCode"]

await database["user"].insert_one(findUser)

await database["pending"].delete_one({"userId": userId})

return JSONResponse(
status_code=200, content={"message": "User Successfully Authorized"}
)
Loading