From 8aad9db65f60aade655f6136929e7b4b8edb0e21 Mon Sep 17 00:00:00 2001 From: cereci5049 Date: Sun, 18 Aug 2024 16:17:43 +0530 Subject: [PATCH 1/2] 050 --- src/controller/htmx.nim | 10 +++++----- src/lib/htmx.nim | 4 ++-- src/view/signup.html | 30 +++++++++++++++++++++--------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/controller/htmx.nim b/src/controller/htmx.nim index ce1ee6c..3b5bdbc 100644 --- a/src/controller/htmx.nim +++ b/src/controller/htmx.nim @@ -8,7 +8,7 @@ proc htmxEmail*(ctx:Context)= em = ctx.urlForm["em"] val: Validity if em == "": - val.message = "Last Name is Required" + val.message = "Email is Required" val.mark = "is-invalid" else: val.message = "" @@ -20,7 +20,7 @@ proc htmxPassword*(ctx:Context)= pw = ctx.urlForm["pw"] val: Validity if pw == "": - val.message = "Last Name is Required" + val.message = "Password is Required" val.mark = "is-invalid" else: val.message = "" @@ -44,7 +44,7 @@ proc htmxLastName*(ctx:Context)= ln = ctx.urlForm["ln"] val: Validity if ln == "": - val.message = "First Name is Required" + val.message = "Last Name is Required" val.mark = "is-invalid" else: val.message = "" @@ -56,9 +56,9 @@ proc htmxPhone*(ctx:Context)= ph = ctx.urlForm["ph"] val: Validity if ph == "": - val.message = "First Name is Required" + val.message = "Phone Number is Required" val.mark = "is-invalid" else: val.message = "" val.mark = "" - ctx.send htmxPhone(ph,val) \ No newline at end of file + ctx.send htmxPhone(ph,val) diff --git a/src/lib/htmx.nim b/src/lib/htmx.nim index 0c4e05d..b5f5b47 100644 --- a/src/lib/htmx.nim +++ b/src/lib/htmx.nim @@ -143,7 +143,7 @@ proc htmxFirstName*(firstName: string, input: Validity): string = proc htmxLastName*(lastName: string, input: Validity): string = result = fmt""" -
@@ -158,7 +158,7 @@ proc htmxLastName*(lastName: string, input: Validity): string = proc htmxPhone*(phone: string, input: Validity): string = result = fmt""" -
diff --git a/src/view/signup.html b/src/view/signup.html index 628ac5a..afa3bd2 100644 --- a/src/view/signup.html +++ b/src/view/signup.html @@ -31,27 +31,39 @@
-
+
- +
-
- - + + + - + -
+ -
+
- +
From dbe4e2a6d66fbcf0fdfa9baae75723ee67398e78 Mon Sep 17 00:00:00 2001 From: cereci5049 Date: Sun, 18 Aug 2024 17:10:06 +0530 Subject: [PATCH 2/2] 051 --- src/controller/login.nim | 8 ++++---- src/controller/signup.nim | 8 ++++---- src/db/users.nim | 16 +++++++--------- src/lib/htmx.nim | 9 --------- src/view/login.html | 10 ++++++---- src/view/signup.html | 8 ++++++++ 6 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/controller/login.nim b/src/controller/login.nim index d264be7..c1157ac 100644 --- a/src/controller/login.nim +++ b/src/controller/login.nim @@ -10,13 +10,13 @@ proc htmxLogin*(ctx: Context) = var form = ctx.urlForm - em =form["em"] + ph =form["ph"] ps=form["pw"] val: Validity validity = initTable[string, Validity]() - if em.len==0 or ps.len==0: + if ph.len==0 or ps.len==0: for a, b in form: if form[a] == "": val.name = "" @@ -31,7 +31,7 @@ proc htmxLogin*(ctx: Context) = ctx.send(htmxLogin(validity, "")) let conn=newTurso() - var temp=getUser(conn, em, ps) + var temp=getUser(conn, ph, ps) if temp[0] == true: ctx &= initCookie("user1", $(%* temp[1])) echo $(%* temp[1]) @@ -43,4 +43,4 @@ proc htmxLogin*(ctx: Context) = val.message = "" val.mark = "" validity[a] = val - ctx.send(htmxLogin(validity, "Invalid Email or Password")) \ No newline at end of file + ctx.send(htmxLogin(validity, "Invalid Email or Password")) diff --git a/src/controller/signup.nim b/src/controller/signup.nim index 6448931..9e885cc 100644 --- a/src/controller/signup.nim +++ b/src/controller/signup.nim @@ -17,18 +17,19 @@ proc signup*(ctx: Context): string= form = ctx.urlForm firstName = form["fn"] lastName = form["ln"] - email = form["em"] phone = form["ph"] password = form["pw"] + userType = form["ut"] conn = newTurso() val: Validity validity = initTable[string, Validity]() - echo firstName, lastName, email, password + echo firstName, lastName, password, userType, phone - if firstName.len == 0 or lastName.len == 0 or email.len == 0 or phone.len == 0 or password.len == 0: + if firstName.len == 0 or lastName.len == 0 or phone.len == 0 or password.len == 0: + echo "lllo" for a, b in form: if form[a] == "": val.name = "" @@ -45,7 +46,6 @@ proc signup*(ctx: Context): string= var user = User( firstName: firstName, lastName: lastName, - email: email, phone: phone, password: password, accessLevel: 1 diff --git a/src/db/users.nim b/src/db/users.nim index 9997c87..a1e94ec 100644 --- a/src/db/users.nim +++ b/src/db/users.nim @@ -12,7 +12,7 @@ proc setupUsers*(conn: Turso) = id INTEGER PRIMARY KEY AUTOINCREMENT, firstName VARCHAR(255) NOT NULL, lastName VARCHAR(255) NOT NULL, - email VARCHAR(255) NOT NULL, + email VARCHAR(255), phone VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, createdAt TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL, @@ -23,13 +23,14 @@ proc setupUsers*(conn: Turso) = proc createPost*(conn: Turso, user: User)= ## createPost inserts a new user into the Users table - conn.execute(fmt"""INSERT INTO users (firstName, lastName, email, phone, password, accessLevel) VALUES ("{user.firstName}", "{user.lastName}", "{user.email}", "{user.phone}", "{user.password}", {user.accessLevel});""") + echo "lllo1" + conn.execute(fmt"""INSERT INTO Users (firstName, lastName, phone, password, accessLevel) VALUES ("{user.firstName}", "{user.lastName}", "{user.phone}", "{user.password}", {user.accessLevel});""") -proc getUser*(conn: Turso, email: string, password: string): (bool, User)= +proc getUser*(conn: Turso, phone: string, password: string): (bool, User)= ## getUser retrieves a user from the Users table - echo "h1" + echo phone, password var - data = conn.getData(fmt"""SELECT * FROM users WHERE email = "{email}" and password = "{password}";""") + data = conn.getData(fmt"""SELECT * FROM Users WHERE phone = "{phone}" and password = "{password}";""") user = User( firstName: "", lastName: "", @@ -40,16 +41,13 @@ proc getUser*(conn: Turso, email: string, password: string): (bool, User)= ) if data["rows"].len > 0: - echo "h2" 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: - echo "h3" - result = (false, user) \ No newline at end of file + result = (false, user) diff --git a/src/lib/htmx.nim b/src/lib/htmx.nim index b5f5b47..298166a 100644 --- a/src/lib/htmx.nim +++ b/src/lib/htmx.nim @@ -89,15 +89,6 @@ proc htmxSignup*(val: Table[string, Validity], message: string): string =
- -
- - - - - -
-
diff --git a/src/view/login.html b/src/view/login.html index 799d6a8..ac67c54 100644 --- a/src/view/login.html +++ b/src/view/login.html @@ -19,11 +19,13 @@ hx-target="this" hx-swap="outerHTML" > - + + -
@@ -50,4 +52,4 @@
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/src/view/signup.html b/src/view/signup.html index afa3bd2..b60130e 100644 --- a/src/view/signup.html +++ b/src/view/signup.html @@ -80,6 +80,14 @@ +
+ + +
+