forked from cereci5049/8
032
This commit is contained in:
parent
fef48d9535
commit
fd68545d61
3 changed files with 37 additions and 2 deletions
|
@ -4,7 +4,7 @@ import
|
||||||
strutils,
|
strutils,
|
||||||
json,
|
json,
|
||||||
strformat,
|
strformat,
|
||||||
./lib/mics,
|
./lib/[mics, htmx],
|
||||||
./db/users,
|
./db/users,
|
||||||
./model/model,
|
./model/model,
|
||||||
./controller/signup
|
./controller/signup
|
||||||
|
@ -45,11 +45,14 @@ import
|
||||||
"/htmx/login" -> post:
|
"/htmx/login" -> post:
|
||||||
var em =ctx.urlForm["email"]
|
var em =ctx.urlForm["email"]
|
||||||
var ps=ctx.urlForm["password"]
|
var ps=ctx.urlForm["password"]
|
||||||
|
|
||||||
|
if em.len==0 or ps.len==0:
|
||||||
|
ctx.send(sendLogin(em, ps))
|
||||||
|
|
||||||
let conn=newTurso()
|
let conn=newTurso()
|
||||||
var temp=getUser(conn, em, ps)
|
var temp=getUser(conn, em, ps)
|
||||||
if temp[0]:
|
if temp[0]:
|
||||||
ctx &= initCookie("user", $(%* temp[1]))
|
ctx &= initCookie("user", $(%* temp[1]))
|
||||||
# redirect using HX-Redict to / url
|
|
||||||
ctx.response.headers.add("HX-Redirect", "/")
|
ctx.response.headers.add("HX-Redirect", "/")
|
||||||
else:
|
else:
|
||||||
echo "user not found"
|
echo "user not found"
|
||||||
|
|
|
@ -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>
|
||||||
|
"""
|
|
@ -11,6 +11,7 @@
|
||||||
<form id="input_form" class="" novalidate
|
<form id="input_form" class="" novalidate
|
||||||
hx-trigger="submit"
|
hx-trigger="submit"
|
||||||
hx-post="/htmx/login"
|
hx-post="/htmx/login"
|
||||||
|
hx-target="#input_form"
|
||||||
>
|
>
|
||||||
|
|
||||||
<label class="text-danger"></label>
|
<label class="text-danger"></label>
|
||||||
|
|
Loading…
Reference in a new issue