Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7188618
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
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
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jul 8, 08:21 (23 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
810460
Default Alt Text
(2 KB)
Attached To
Mode
rPLAY Sealious playground
Attached
Detach File
Event Timeline
Log In to Comment