This commit is contained in:
cereci5049 2024-08-08 03:27:30 +05:30
parent ae19c460cd
commit 755c9bd506
4 changed files with 29 additions and 15 deletions

Binary file not shown.

View file

@ -24,18 +24,27 @@ proc createPost*(conn: Turso, user: User)=
conn.execute(fmt"""INSERT INTO users (first_name, last_name, email, phone, password, access_level) VALUES ("{user.firstName}", "{user.lastName}", "{user.email}", "{user.phone}", "{user.password}", {user.accessLevel});""")
proc getUser*(conn: Turso, email: string, password: string): (bool, User)=
echo "h1"
var
data = conn.getData(fmt"""SELECT * FROM users WHERE email = "{email}" and password = "{password}";""")
user = User(
firstName: data["rows"][0][1]["value"].getStr(),
lastName: data["rows"][0][2]["value"].getStr(),
email: data["rows"][0][3]["value"].getStr(),
phone: data["rows"][0][4]["value"].getStr(),
password: data["rows"][0][5]["value"].getStr(),
accessLevel: parseInt(data["rows"][0][8]["value"].getStr())
firstName: "",
lastName: "",
email: "",
phone: "",
password: "",
accessLevel: 0
)
if user.firstName.len == 0 or user.lastName.len == 0 or user.email.len == 0 or user.password.len == 0:
result = (false, user)
if data["rows"].len > 0:
user = User(
firstName: data["rows"][0][1]["value"].getStr(),
lastName: data["rows"][0][2]["value"].getStr(),
email: data["rows"][0][3]["value"].getStr(),
phone: data["rows"][0][4]["value"].getStr(),
password: data["rows"][0][5]["value"].getStr(),
accessLevel: parseInt(data["rows"][0][8]["value"].getStr())
)
result = (true, user)
else:
result = (true, user)
result = (false, user)

View file

@ -64,15 +64,20 @@ import
val.message = ""
val.mark = ""
validity[a] = val
ctx.send(sendLogin(validity))
ctx.send(sendLogin(validity, ""))
let conn=newTurso()
var temp=getUser(conn, em, ps)
if temp[0]:
if temp[0] == true:
ctx &= initCookie("user", $(%* temp[1]))
ctx.response.headers.add("HX-Redirect", "/")
else:
echo "user not found"
for a, b in form:
val.name = b
val.message = ""
val.mark = ""
validity[a] = val
ctx.send(sendLogin(validity, "Invalid Email or Password"))
"/:path" -> get:
compileTemplateFile(getScriptDir() / "view" / "404.nimja")

View file

@ -3,7 +3,7 @@ import
tables,
../model/rand
proc sendLogin*(val: Table[string, Validity]): string =
proc sendLogin*(val: Table[string, Validity], message: string): string =
result = fmt"""
<form id="input_form" class="" novalidate
hx-trigger="submit"
@ -11,7 +11,7 @@ proc sendLogin*(val: Table[string, Validity]): string =
hx-target="#input_form"
>
<label class="text-danger"></label>
<label class="text-danger">{message}</label>
<div class="form-group mt-5">
<label for="email">Email:</label>
<label class="text-danger">{val["email"].message}</label>