Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F1262864
index.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
index.ts
View Options
import
{
Middlewares
}
from
"sealious"
;
import
{
router
}
from
"../.."
;
import
html
from
"../../html"
;
router
.
get
(
"/login"
,
Middlewares
.
extractContext
(),
async
(
ctx
)
=>
{
ctx
.
body
=
html
(
ctx
,
LoginForm
());
});
router
.
post
(
"/login"
,
Middlewares
.
extractContext
(),
Middlewares
.
parseBody
(),
async
(
ctx
)
=>
{
try
{
const
session_id
=
await
ctx
.
$app
.
collections
.
sessions
.
login
(
ctx
.
$body
.
username
as
string
,
ctx
.
$body
.
password
as
string
);
ctx
.
cookies
.
set
(
"sealious-session"
,
session_id
,
{
maxAge
:
1000
*
60
*
60
*
24
*
7
,
secure
:
ctx
.
request
.
protocol
===
"https"
,
overwrite
:
true
,
});
ctx
.
redirect
(
"/user"
);
}
catch
(
e
)
{
ctx
.
status
=
422
;
ctx
.
body
=
html
(
ctx
,
LoginForm
(
ctx
.
$body
.
username
as
string
,
(
e
as
Error
).
message
)
);
}
}
);
function
LoginForm
(
username
=
""
,
error_message
?:
string
)
:
string
{
if
(
error_message
)
{
error_message
=
error_message
==
"Incorrect username!"
?
"Niepoprawna nazwa użytkownika!"
:
"Niepoprawne hasło!"
;
}
return
/* HTML */
`
<turbo-frame id="login">
<h2>Zaloguj</h2>
<form method="POST" action="/login" data-turbo-frame="_top">
${
error_message
?
`<div>
${
error_message
}
</div>`
:
""
}
<label for="username">
Nazwa użytkownika:
<input
id="username"
name="username"
type="text"
value="
${
username
}
"
required
/>
</label>
<label for="password"
>Hasło:
<input
id="password"
name="password"
type="password"
value=""
required
/></label>
<input type="submit" value="Zaloguj" />
</form>
</turbo-frame>
`
;
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Fri, Jan 24, 15:16 (20 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
601296
Default Alt Text
index.ts (1 KB)
Attached To
Mode
rREWRITE Configurable rewriter
Attached
Detach File
Event Timeline
Log In to Comment