Page MenuHomeSealhub

No OneTemporary

diff --git a/src/back/routes/login.form.ts b/src/back/routes/login.form.ts
index 0b40e18..708bec6 100644
--- a/src/back/routes/login.form.ts
+++ b/src/back/routes/login.form.ts
@@ -1,67 +1,74 @@
/* eslint-disable @typescript-eslint/consistent-type-assertions */
import type { Context } from "koa";
import type { FormData } from "@sealcode/sealgen";
import { Form, Controls, fieldsToShape } from "@sealcode/sealgen";
import html from "../html.js";
import { Fields } from "@sealcode/sealgen";
import { hasShape, predicates } from "@sealcode/ts-predicates";
+import { AdminURL } from "./urls.js";
export const actionName = "Login";
const fields = {
username: new Fields.SimpleFormField(true),
password: new Fields.SimpleFormField(true),
};
export const LoginShape = fieldsToShape(fields);
export default new (class LoginForm extends Form<typeof fields, void> {
- defaultSuccessMessage = "Formularz wypełniony poprawnie";
+ defaultSuccessMessage = "Logged in";
fields = fields;
controls = [
new Controls.SimpleInput(fields.username, {
label: "Username:",
type: "text",
}),
new Controls.SimpleInput(fields.password, {
label: "Password:",
type: "password",
}),
];
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async canAccess(_: Context) {
return { canAccess: true, message: "" };
}
async onSubmit(ctx: Context) {
const body = ctx.$body;
if (
!hasShape({ username: predicates.string, password: predicates.string }, body)
) {
throw new Error("Missing username or password");
}
const session_id = await ctx.$app.collections.sessions.login(
body.username,
body.password
);
ctx.cookies.set("sealious-session", session_id, {
maxAge: 1000 * 60 * 60 * 24 * 7,
secure: ctx.request.protocol === "https",
overwrite: true,
});
- ctx.redirect("/user");
- ctx.status = 303;
+ }
+
+ async onSuccess() {
+ return {
+ action: <const>"redirect",
+ url: AdminURL,
+ messages: [],
+ };
}
async render(ctx: Context, data: FormData, show_field_errors: boolean) {
return html({
ctx,
title: "Form",
description: "",
body: super.render(ctx, data, show_field_errors) as Promise<string>,
});
}
})();

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jul 8, 08:26 (1 d, 2 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
810460
Default Alt Text
(2 KB)

Event Timeline