feur
This commit is contained in:
parent
8b6a86f17a
commit
3aea126342
14 changed files with 205 additions and 67 deletions
15
api/login.ts
15
api/login.ts
|
@ -1,7 +1,16 @@
|
|||
import { Context } from "https://deno.land/x/hono@v4.3.10/mod.ts";
|
||||
import { Env } from "https://deno.land/x/hono@v4.3.10/mod.ts";
|
||||
import { BlankInput } from "https://deno.land/x/hono@v4.3.10/types.ts";
|
||||
import { FeurEnv } from "../main.ts";
|
||||
import { login, set_user } from "../lib/auth.ts";
|
||||
|
||||
export function login_route(context: Context<Env, string, BlankInput>) {
|
||||
return context.text("E");
|
||||
export async function login_route(context: Context<FeurEnv, string, BlankInput>) {
|
||||
const data = await context.req.formData();
|
||||
let username = data.get("login"), pass = data.get("password");
|
||||
if (username === null || pass === null) return context.redirect("/login");
|
||||
username = username.toString(), pass = pass.toString();
|
||||
const logged = await login(username, pass);
|
||||
if (logged === null) return context.redirect("/login");
|
||||
console.log("Logged in", { username });
|
||||
set_user(context, logged);
|
||||
return context.redirect("/user");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue