diff --git a/src/db/db_up.exe b/src/db/db_up.exe deleted file mode 100644 index ca4de91..0000000 Binary files a/src/db/db_up.exe and /dev/null differ diff --git a/src/db/users.nim b/src/db/users.nim index 42b52e1..45c772c 100644 --- a/src/db/users.nim +++ b/src/db/users.nim @@ -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) \ No newline at end of file + result = (false, user) \ No newline at end of file diff --git a/src/hh1.nim b/src/hh1.nim index 954a070..60956e1 100644 --- a/src/hh1.nim +++ b/src/hh1.nim @@ -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") diff --git a/src/lib/htmx.nim b/src/lib/htmx.nim index c3a096b..451b822 100644 --- a/src/lib/htmx.nim +++ b/src/lib/htmx.nim @@ -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"""
- +