From 9b51a908448c23eff673934f023d247a6c47519d Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Fri, 31 May 2024 13:39:05 -0500 Subject: Add: initial login form and authentication --- site/login.lisp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'site/login.lisp') diff --git a/site/login.lisp b/site/login.lisp index afbd80e..66d20ff 100644 --- a/site/login.lisp +++ b/site/login.lisp @@ -1,10 +1,36 @@ (in-package #:vampire) (defun login-page () - "login") + (with-html-string + (:div (:h1 "I vant to suck your blood") + (:form :method "POST" :action "/login" + (:input :placeholder "Name" :name "name") + (:br) + (:input :placeholder "Password" :type "password" :name "password") + (:br) + (:button :type "submit" "Click to Login"))) + (:a :href "/new-account" "Come to the Dark Side"))) (wknd:defendpoint login :get :route "login" :returns "text/html" :handle (login-page)) +(wknd:defendpoint login-user + :post :route "login" + :parameters + (name string) + (password string) + :properties + (user user) + :authenticate (authenticate-login-user name password) + :handle (wknd:endpoint-redirect 'home)) + +(defun authenticate-login-user (name password) + (do> + found-user :when= (user-with-name name) + :when (equal (user-pwhash found-user) + (hash-string password (user-pwsalt found-user))) + session := (db:with-transaction () (make-instance 'session :user found-user)) + (wknd:set-cookie +session-cookie+ :value (key session)))) + -- cgit v1.2.3