This commit is contained in:
cereci5049 2024-08-08 01:59:42 +05:30
parent fef48d9535
commit fd68545d61
3 changed files with 37 additions and 2 deletions

View file

@ -4,7 +4,7 @@ import
strutils,
json,
strformat,
./lib/mics,
./lib/[mics, htmx],
./db/users,
./model/model,
./controller/signup
@ -45,11 +45,14 @@ import
"/htmx/login" -> post:
var em =ctx.urlForm["email"]
var ps=ctx.urlForm["password"]
if em.len==0 or ps.len==0:
ctx.send(sendLogin(em, ps))
let conn=newTurso()
var temp=getUser(conn, em, ps)
if temp[0]:
ctx &= initCookie("user", $(%* temp[1]))
# redirect using HX-Redict to / url
ctx.response.headers.add("HX-Redirect", "/")
else:
echo "user not found"

View file

@ -0,0 +1,31 @@
import strformat
proc sendLogin*(em, pw: string): string =
result = fmt"""
<form id="input_form" class="" novalidate
hx-trigger="submit"
hx-post="/htmx/login"
hx-target="#input_form"
>
<label class="text-danger"></label>
<div class="form-group mt-5">
<label for="email">Email:</label>
<label class="text-danger">Email is Required</label>
<input type="email" name="email" id="email" class="form-control" required autocomplete="off" value="{em}">
</div>
<div class="form-group">
<label for="password">Password:</label>
<label class="text-danger">Password is Required</label>
<input type="password" name="password" id="password" class="form-control" required autocomplete="off" value="{pw}">
</div>
<hr>
<button id="b4" type="submit" class="btn btn-primary">Submit</button>
<a id="b4" href="/signup" class="btn btn-outline-primary">Sign Up</a>
<hr>
</form>
"""

View file

@ -11,6 +11,7 @@
<form id="input_form" class="" novalidate
hx-trigger="submit"
hx-post="/htmx/login"
hx-target="#input_form"
>
<label class="text-danger"></label>