main #23
3 changed files with 35 additions and 10 deletions
25
src/hh1.nim
25
src/hh1.nim
|
@ -6,7 +6,7 @@ import
|
|||
strformat,
|
||||
./lib/[mics, htmx],
|
||||
./db/users,
|
||||
./model/model,
|
||||
./model/[model, rand],
|
||||
./controller/signup
|
||||
|
||||
"/^path" -> before[post, get]:
|
||||
|
@ -43,11 +43,28 @@ import
|
|||
"/login" -> get:
|
||||
compileTemplateFile(getScriptDir() / "view" / "login.nimja")
|
||||
"/htmx/login" -> post:
|
||||
var em =ctx.urlForm["email"]
|
||||
var ps=ctx.urlForm["password"]
|
||||
var
|
||||
form = ctx.urlForm
|
||||
|
||||
em =form["email"]
|
||||
ps=form["password"]
|
||||
|
||||
val: Validity
|
||||
validity = initTable[string, Validity]()
|
||||
|
||||
if em.len==0 or ps.len==0:
|
||||
ctx.send(sendLogin(em, ps))
|
||||
for a, b in form:
|
||||
if form[a] == "":
|
||||
val.name = ""
|
||||
val.message = "Field is Required"
|
||||
val.mark = "is-invalid"
|
||||
validity[a] = val
|
||||
else:
|
||||
val.name = b
|
||||
val.message = ""
|
||||
val.mark = ""
|
||||
validity[a] = val
|
||||
ctx.send(sendLogin(validity))
|
||||
|
||||
let conn=newTurso()
|
||||
var temp=getUser(conn, em, ps)
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import strformat
|
||||
import
|
||||
strformat,
|
||||
tables,
|
||||
../model/rand
|
||||
|
||||
proc sendLogin*(em, pw: string): string =
|
||||
proc sendLogin*(val: Table[string, Validity]): string =
|
||||
result = fmt"""
|
||||
<form id="input_form" class="" novalidate
|
||||
hx-trigger="submit"
|
||||
|
@ -11,14 +14,14 @@ proc sendLogin*(em, pw: string): string =
|
|||
<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}">
|
||||
<label class="text-danger">{val["email"].message}</label>
|
||||
<input type="email" name="email" id="email" class="form-control {val["email"].mark}" required autocomplete="off" value="{val["email"].name}">
|
||||
</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}">
|
||||
<label class="text-danger">{val["password"].message}</label>
|
||||
<input type="password" name="password" id="password" class="form-control {val["password"].mark}" required autocomplete="off" value="{val["password"].name}">
|
||||
|
||||
</div>
|
||||
|
||||
|
|
5
src/model/rand.nim
Normal file
5
src/model/rand.nim
Normal file
|
@ -0,0 +1,5 @@
|
|||
type
|
||||
Validity* = object
|
||||
name*: string
|
||||
message*: string
|
||||
mark*: string
|
Loading…
Reference in a new issue