cool changes

This commit is contained in:
2026-01-15 12:08:11 +00:00
parent c88f3e84ea
commit c9f597b54c
5 changed files with 12 additions and 17 deletions

View File

@@ -30,7 +30,7 @@ const props = defineProps({
return fetch("/logout").then( return fetch("/logout").then(
(response) => { (response) => {
if (response.ok) { if (response.ok) {
window.location.reload; window.location.reload();
} }
} }
) )

View File

@@ -53,23 +53,15 @@ class register_model(BaseModel):
async def create_user(req: Request): async def create_user(req: Request):
body = await req.json() body = await req.json()
#body = register_model(**body)
# Auto exceptions give more verbose to Nuxt. # Auto exceptions give more verbose to Nuxt.
#try:
# body = register_model(**body)
#except ValidationError:
# raise HTTPException(status_code=400, detail="Missing / invalid arguments")
body["password"] = bcrypt.hashpw(body["password"].encode(), bcrypt.gensalt()).decode() body["password"] = bcrypt.hashpw(body["password"].encode(), bcrypt.gensalt()).decode()
async with db.pool.acquire() as conn: async with db.pool.acquire() as conn:
async with conn.cursor() as cur: async with conn.cursor() as cur:
await cur.execute("INSERT INTO users (`first_name`,`last_name`,`email`,`password`) VALUES (%s,%s,%s,%s)", (body.first_name, body.last_name, body.email, body.password)) await cur.execute("INSERT INTO users (`first_name`,`last_name`,`email`,`password`) VALUES (%s,%s,%s,%s)", (body.first_name, body.last_name, body.email, body.password))
await conn.commit() await conn.commit()
class login_data(BaseModel):
email: str
password: str
@app.post("/login") @app.post("/login")
async def login_endpoint(req: Request): async def login_endpoint(req: Request):
@@ -77,8 +69,6 @@ async def login_endpoint(req: Request):
body = await req.json() body = await req.json()
#print(body) #print(body)
try: try:
#login = login_data(**body)
# ensure it's only email and password
user_data = await fetch_user_info(body["email"]) user_data = await fetch_user_info(body["email"])
if (user_data is None): if (user_data is None):
raise HTTPException(status_code=401, detail="User doesn't exist") raise HTTPException(status_code=401, detail="User doesn't exist")

View File

@@ -1,7 +1,9 @@
export default defineEventHandler((event) => { export default defineEventHandler(async (event) => {
// this one requires auth // this one requires auth
//const login = fetch("http://127.0.0.1:81/login"); //const login = fetch("http://127.0.0.1:81/login");
throw createError({ statusCode: 401 }); const session = await getUserSession(event)
if (session.secure!.user_id == undefined)
throw createError({ statusCode: 401 });
}) })

View File

@@ -5,7 +5,7 @@ export default defineEventHandler(async (event) => {
if ( !body.email || !body.password ) if ( !body.email || !body.password )
throw createError({ statusCode: 400, message: "Bad form. Use e-mail and password" }) throw createError({ statusCode: 400, message: "Bad form. Use e-mail and password" })
console.log(body) //console.log(body)
const req = await fetch(conf.fastapi_url + "/login", const req = await fetch(conf.fastapi_url + "/login",
{ {
method: "POST", method: "POST",
@@ -29,10 +29,11 @@ export default defineEventHandler(async (event) => {
surname: body.last_name, surname: body.last_name,
email: body.email email: body.email
}, },
private: { secure: {
user_id: body.id user_id: body.id
} }
}) })
console.log(await getUserSession(event))
return; return;
} }

View File

@@ -1,4 +1,6 @@
export default defineEventHandler(async (event) => { export default defineEventHandler(async (event) => {
// log them out // log them out
await clearUserSession(event); console.log(await clearUserSession(event))
return;
}) })