ayushman #14
3 changed files with 43 additions and 5 deletions
11
src/hh1.nim
11
src/hh1.nim
|
@ -4,7 +4,7 @@ import
|
|||
strutils,
|
||||
json,
|
||||
strformat,
|
||||
./lib/mics,
|
||||
./lib/[mics, htmx],
|
||||
./db/users,
|
||||
./model/model,
|
||||
./controller/signup
|
||||
|
@ -42,15 +42,18 @@ import
|
|||
|
||||
"/login" -> get:
|
||||
compileTemplateFile(getScriptDir() / "view" / "login.nimja")
|
||||
"/login" -> post:
|
||||
"/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]:
|
||||
echo $(%* temp[1])
|
||||
ctx &= initCookie("user", $(%* temp[1]))
|
||||
ctx.redirect("/")
|
||||
ctx.response.headers.add("HX-Redirect", "/")
|
||||
else:
|
||||
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>
|
||||
"""
|
|
@ -8,7 +8,11 @@
|
|||
<div class="col">
|
||||
<h1 class="mt-5">Login</h1>
|
||||
|
||||
<form id="input_form" method="post" class="" novalidate>
|
||||
<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">
|
||||
|
|
Loading…
Reference in a new issue