login almost complete
This commit is contained in:
@@ -86,8 +86,6 @@
|
|||||||
background-clip: text;
|
background-clip: text;
|
||||||
color: transparent;
|
color: transparent;
|
||||||
|
|
||||||
/* optional glow */
|
|
||||||
/*filter: drop-shadow(0 0 10px rgba(255,255,255,.4));*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes rgb {
|
@keyframes rgb {
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ function onSubmit(payload: FormSubmitEvent<Schema>) {
|
|||||||
<UAuthForm
|
<UAuthForm
|
||||||
:schema="schema"
|
:schema="schema"
|
||||||
title="Login"
|
title="Login"
|
||||||
description="Enter your credentials to access your account."
|
icon="solar:shield-user-broken"
|
||||||
icon="i-lucide-user"
|
|
||||||
:fields="fields"
|
:fields="fields"
|
||||||
:submit="{
|
:submit="{
|
||||||
label: 'Login',
|
label: 'Login',
|
||||||
|
|||||||
@@ -14,5 +14,8 @@ export default defineNuxtConfig({
|
|||||||
css: [ "@/assets/global.css" ],
|
css: [ "@/assets/global.css" ],
|
||||||
vite: {
|
vite: {
|
||||||
plugins: [ tailwindcss() ]
|
plugins: [ tailwindcss() ]
|
||||||
|
},
|
||||||
|
runtimeConfig: {
|
||||||
|
fastapi_url: "http://127.0.0.1:8001"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -1,81 +1,72 @@
|
|||||||
from fastapi import FastAPI, HTTPException
|
from fastapi import FastAPI, HTTPException, Request, Response
|
||||||
from pydantic import BaseModel
|
#from fastapi import Body, Cookie, File, Form, Header, Path, Query
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
import uvicorn
|
import uvicorn
|
||||||
import pymysql
|
import aiomysql
|
||||||
|
import bcrypt
|
||||||
class mysql_params:
|
|
||||||
host = "127.0.0.1"
|
|
||||||
user = "yt2mp3_nuxt"
|
|
||||||
db = "yt2mp3_nuxt"
|
|
||||||
pwd = "ultratopsecret,bro"
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
class ConversionData(BaseModel):
|
class db:
|
||||||
input_value: str
|
pool = None
|
||||||
conversion_type: str
|
|
||||||
|
|
||||||
class LoginData(BaseModel):
|
host = "127.0.0.1"
|
||||||
username: str
|
user = "yt2mp3_nuxt"
|
||||||
password: str
|
db_name = "yt2mp3_nuxt"
|
||||||
|
pwd = "ultratopsecret,bro"
|
||||||
|
|
||||||
class MeData(BaseModel):
|
@staticmethod
|
||||||
username: str
|
async def init_db_pool():
|
||||||
email: str
|
db.pool = await aiomysql.create_pool(db.host,db.user,db.pwd,db.db_name)
|
||||||
profile_picture: Optional[str] = None
|
|
||||||
|
@staticmethod
|
||||||
|
async def get_conn():
|
||||||
|
return db.pool.acquire()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async def fetch_user_info(email: str):
|
||||||
|
async with await db.get_conn() as conn:
|
||||||
|
async with conn.cursor(aiomysql.DictCursor) as cur:
|
||||||
|
await cur.execute("SELECT * FROM users WHERE email = %s", (email,))
|
||||||
|
return await cur.fetchone()
|
||||||
|
|
||||||
|
|
||||||
@app.post("/convert")
|
@app.post("/convert")
|
||||||
async def convert_endpoint(data: ConversionData):
|
async def convert_endpoint(): pass
|
||||||
"""
|
|
||||||
Converts an input value based on the specified conversion type.
|
|
||||||
"""
|
|
||||||
# Dummy conversion logic
|
|
||||||
if data.conversion_type == "uppercase":
|
|
||||||
converted_value = data.input_value.upper()
|
|
||||||
elif data.conversion_type == "lowercase":
|
|
||||||
converted_value = data.input_value.lower()
|
|
||||||
else:
|
|
||||||
raise HTTPException(status_code=400, detail="Invalid conversion type")
|
|
||||||
|
|
||||||
return {"converted_value": converted_value}
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/login")
|
@app.post("/login")
|
||||||
async def login_endpoint(data: LoginData):
|
async def login_endpoint(req: Request, res: Response):
|
||||||
"""
|
|
||||||
Verifies login credentials.
|
body = await req.json()
|
||||||
"""
|
if sorted(list(body.keys())) != sorted(["email","password"]):
|
||||||
# Dummy verification logic
|
# ensure it's only email and password
|
||||||
if data.username == "user" and data.password == "password":
|
raise HTTPException(status_code=400)
|
||||||
return {"message": "Login successful"}
|
try:
|
||||||
else:
|
user_data = await fetch_user_info(body["email"])
|
||||||
raise HTTPException(status_code=401, detail="Invalid credentials")
|
if (user_data is None):
|
||||||
|
raise HTTPException(status_code=401)
|
||||||
|
else:
|
||||||
|
pwd = user_data.get("password")
|
||||||
|
if (bcrypt.checkpw(body["password"].encode(), user_data.get("password").encode())):
|
||||||
|
return user_data
|
||||||
|
else:
|
||||||
|
raise HTTPException(status_code=401)
|
||||||
|
except KeyError:
|
||||||
|
raise HTTPException(status_code=400)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/me")
|
@app.get("/me")
|
||||||
async def me_get_endpoint():
|
async def me_get_endpoint():
|
||||||
"""
|
"""
|
||||||
Retrieves user profile data.
|
Retrieves user profile data.
|
||||||
"""
|
|
||||||
# Dummy user data
|
|
||||||
user_data = {
|
|
||||||
"username": "example_user",
|
|
||||||
"email": "user@example.com",
|
|
||||||
"profile_picture": "https://example.com/profile.jpg"
|
|
||||||
}
|
|
||||||
return user_data
|
|
||||||
|
|
||||||
@app.post("/me")
|
Trusts Nuxt's backend to allow it or not.
|
||||||
async def me_post_endpoint(data: MeData):
|
|
||||||
"""
|
"""
|
||||||
Updates user profile data.
|
|
||||||
"""
|
return await fetch_user_info()
|
||||||
# Dummy update logic
|
|
||||||
return {"message": "Profile updated successfully", **data.dict()}
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
|
const conf = useRuntimeConfig()
|
||||||
|
|
||||||
const body = await readBody(event)
|
const body = await readBody(event)
|
||||||
|
|
||||||
const req = await fetch("http://127.0.0.1:99",
|
if ( !body.email || !body.password )
|
||||||
|
throw createError({ statusCode: 400, message: "Bad form. Use e-mail and password" })
|
||||||
|
|
||||||
|
const req = await fetch(conf.fastapi_url + "/login",
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
Reference in New Issue
Block a user