add status
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
from datetime import timedelta
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
@@ -26,6 +27,7 @@ def session(
|
|||||||
username: Annotated[str, Body()],
|
username: Annotated[str, Body()],
|
||||||
password: Annotated[str, Body()],
|
password: Annotated[str, Body()],
|
||||||
):
|
):
|
||||||
|
now_ = now()
|
||||||
user_id, password_hash = _get_user(username)
|
user_id, password_hash = _get_user(username)
|
||||||
|
|
||||||
if not pbkdf2_sha256.verify(password, password_hash):
|
if not pbkdf2_sha256.verify(password, password_hash):
|
||||||
@@ -40,6 +42,7 @@ def session(
|
|||||||
http_only=True,
|
http_only=True,
|
||||||
secure=True,
|
secure=True,
|
||||||
same_site=None,
|
same_site=None,
|
||||||
|
expires=now_ + timedelta(seconds=JWT_EXP_SECONDS),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
2
id.saladeaula.digital/client/app/lib/http-status.ts
Normal file
2
id.saladeaula.digital/client/app/lib/http-status.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export const FOUND = 302
|
||||||
|
export const BAD_REQUEST = 400
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { parse } from 'cookie'
|
import { parse } from 'cookie'
|
||||||
|
|
||||||
|
import * as httpStatus from '@/lib/http-status'
|
||||||
import type { Route } from './+types/authorize'
|
import type { Route } from './+types/authorize'
|
||||||
|
|
||||||
export async function loader({ request, context }: Route.LoaderArgs) {
|
export async function loader({ request, context }: Route.LoaderArgs) {
|
||||||
@@ -12,7 +13,7 @@ export async function loader({ request, context }: Route.LoaderArgs) {
|
|||||||
|
|
||||||
if (!cookies.session_id) {
|
if (!cookies.session_id) {
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
status: 302,
|
status: httpStatus.FOUND,
|
||||||
headers: {
|
headers: {
|
||||||
Location: redirect.toString()
|
Location: redirect.toString()
|
||||||
}
|
}
|
||||||
@@ -29,9 +30,9 @@ export async function loader({ request, context }: Route.LoaderArgs) {
|
|||||||
redirect: 'manual'
|
redirect: 'manual'
|
||||||
})
|
})
|
||||||
|
|
||||||
if (r.status === 400) {
|
if (r.status === httpStatus.BAD_REQUEST) {
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
status: 302,
|
status: httpStatus.FOUND,
|
||||||
headers: {
|
headers: {
|
||||||
Location: redirect.toString()
|
Location: redirect.toString()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { Button } from '@/components/ui/button'
|
|||||||
import { Checkbox } from '@/components/ui/checkbox'
|
import { Checkbox } from '@/components/ui/checkbox'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
import { Label } from '@/components/ui/label'
|
import { Label } from '@/components/ui/label'
|
||||||
|
import * as httpStatus from '@/lib/http-status'
|
||||||
|
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import logo from './logo.svg'
|
import logo from './logo.svg'
|
||||||
@@ -49,7 +50,7 @@ export async function action({ request, context }: Route.ActionArgs) {
|
|||||||
headers.set('Location', url.toString())
|
headers.set('Location', url.toString())
|
||||||
|
|
||||||
return new Response(await r.text(), {
|
return new Response(await r.text(), {
|
||||||
status: 302,
|
status: httpStatus.FOUND,
|
||||||
headers
|
headers
|
||||||
})
|
})
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user