summaryrefslogtreecommitdiff
path: root/pages
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2025-09-16 17:21:51 +0600
committerunwox <me@unwox.com>2025-09-19 14:54:41 +0600
commitb3fd9c6aad5828fae482794f3719c40a3dceb72e (patch)
treeb0154502f04c8dd7f2366ebd388eda481ea039a6 /pages
parent1df376b3b7b1e77de2730fa93f499083116baf4f (diff)
small improvements
Diffstat (limited to 'pages')
-rw-r--r--pages/auth.fnl40
1 files changed, 20 insertions, 20 deletions
diff --git a/pages/auth.fnl b/pages/auth.fnl
index c6c1832..3afb517 100644
--- a/pages/auth.fnl
+++ b/pages/auth.fnl
@@ -3,22 +3,23 @@
(local lib (require :lib))
(local templates (require :templates))
-(local auth-form [
- {:title ""
- :fields [
- (forms.text-input "name" "Пользователь" true)
- (forms.password-input "password" "Пароль" true)]}])
+(local auth-form
+ [{:title ""
+ :fields [
+ (forms.text-input "name" "Пользователь" true)
+ (forms.password-input "password" "Пароль" true)]}])
(fn content [data errors]
- (set data.password nil)
- [(HTML
- [:div {:class "side"}
- (templates.header "/auth")])
- (HTML
- [:section {:class "content"}
- [:div {:class "mb-1"} [:a {:href "/"} "⟵ Обратно на главную"]]
- [:h2 {} "Войти"]
- (forms.render-form auth-form data errors)])])
+ (set data.password nil)
+
+ [(HTML
+ [:div {:class "side"}
+ (templates.header "/auth")])
+ (HTML
+ [:section {:class "content"}
+ [:div {:class "mb-1"} [:a {:href "/"} "⟵ Обратно на главную"]]
+ [:h2 {} "Войти"]
+ (forms.render-form auth-form data errors)])])
(fn create-session [db user expires-at]
(local id (_G.must (luna.crypto.random-string 64)))
@@ -27,7 +28,6 @@
db "INSERT INTO auth_sessions (id, user, creation_time, expires_at)
VALUES (?, ?, ?, ?)"
[id user (lib.now) expires-at]))
-
id)
(fn check-user [db name entered-pass]
@@ -50,10 +50,7 @@
(if request.form
(let [name request.form.name
entered-password request.form.password
- correct-creds? (check-user db name entered-password)
- errors (if (not correct-creds?)
- {:password "Пользователя с таким именем и паролем не существует."}
- nil)]
+ correct-creds? (check-user db name entered-password)]
(if correct-creds?
(let [next-week (+ (os.time) (* 60 60 24 7))
session-id (create-session
@@ -63,7 +60,10 @@
:Set-Cookie (.. "auth= " session-id "; HttpOnly; SameSite=strict;"
"Expires=" cookie-expires
(if luna.debug? "" "; Secure"))} ""))
- (values 200 {} (templates.base (content request.form errors)))))
+ (values 400 {}
+ (templates.base
+ (content request.form
+ {:password "Пользователя с таким именем и паролем не существует."})))))
(values 200 {} (templates.base (content {} {}))))))
{: render}