Merge pull request '053' (#38) from ayushman into main

Reviewed-on: #38
This commit is contained in:
cereci5049 2024-08-19 21:20:44 +02:00
commit 13e8c6f57c
3 changed files with 16 additions and 18 deletions

View file

@ -33,9 +33,7 @@ proc htmxLogin*(ctx: Context) =
let conn=newTurso()
var temp=getUser(conn, ph, ps)
if temp[0] == true:
ctx &= initCookie("user1", $(%* temp[1]))
echo $(%* temp[1])
echo ctx.cookies
ctx &= initCookie("user", $(%* temp[1]))
ctx.response.headers.add("HX-Redirect", "/")
else:
for a, b in form:

View file

@ -9,7 +9,7 @@ import
proc signup*(ctx: Context): string=
if ctx.httpMethod == HttpGet:
var
user1 = ctx.cookies.getOrDefault("user1", "")
user1 = ctx.cookies.getOrDefault("user", "")
user = getUserFromCookie(user1)
compileTemplateFile(".." / "view" / "signup.html", baseDir = getScriptDir())
elif ctx.httpMethod == HttpPost:
@ -26,10 +26,7 @@ proc signup*(ctx: Context): string=
val: Validity
validity = initTable[string, Validity]()
echo firstName, lastName, password, userType, phone
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 = ""
@ -51,6 +48,9 @@ proc signup*(ctx: Context): string=
accessLevel: 1
)
if userType == "2":
user.accessLevel = 2
conn.createPost(user)
ctx &= initCookie("user", $(%* user))
ctx.response.headers.add("HX-Redirect", "/")

View file

@ -19,45 +19,45 @@ load()
"/" -> [get, post]:
var
user1 = ctx.cookies.getOrDefault("user1", "")
user1 = ctx.cookies.getOrDefault("user", "")
user = getUserFromCookie(user1)
echo user.firstName
compileTemplateFile("view" / "index.html", baseDir = getScriptDir())
"/shop" -> get:
var
user1 = ctx.cookies.getOrDefault("user1", "")
user1 = ctx.cookies.getOrDefault("user", "")
user = getUserFromCookie(user1)
compileTemplateFile("view" / "shop.html", baseDir = getScriptDir())
"/contact" -> get:
var
user1 = ctx.cookies.getOrDefault("user1", "")
user1 = ctx.cookies.getOrDefault("user", "")
user = getUserFromCookie(user1)
compileTemplateFile("view" / "contact.html", baseDir = getScriptDir())
"/cart" -> get:
var
user1 = ctx.cookies.getOrDefault("user1", "")
user1 = ctx.cookies.getOrDefault("user", "")
user = getUserFromCookie(user1)
compileTemplateFile("view" / "cart.html", baseDir = getScriptDir())
"/checkout" -> get:
var
user1 = ctx.cookies.getOrDefault("user1", "")
user1 = ctx.cookies.getOrDefault("user", "")
user = getUserFromCookie(user1)
compileTemplateFile("view" / "checkout.html", baseDir = getScriptDir())
"/shop/:id" -> get:
var
prodId = capitalizeAscii(ctx.pathParams["id"])
user1 = ctx.cookies.getOrDefault("user1", "")
user1 = ctx.cookies.getOrDefault("user", "")
user = getUserFromCookie(user1)
compileTemplateFile("view" / "shop-detail.html", baseDir = getScriptDir())
"/testimonial" -> get:
var
user1 = ctx.cookies.getOrDefault("user1", "")
user1 = ctx.cookies.getOrDefault("user", "")
user = getUserFromCookie(user1)
compileTemplateFile("view" / "testimonial.html", baseDir = getScriptDir())
@ -65,7 +65,7 @@ load()
"/login" -> get:
var
user1 = ctx.cookies.getOrDefault("user1", "")
user1 = ctx.cookies.getOrDefault("user", "")
user = getUserFromCookie(user1)
compileTemplateFile("view" / "login.html", baseDir = getScriptDir())
@ -83,14 +83,14 @@ load()
"/:path" -> get:
var
user1 = ctx.cookies.getOrDefault("user1", "")
user1 = ctx.cookies.getOrDefault("user", "")
user = getUserFromCookie(user1)
compileTemplateFile("view" / "404.html", baseDir = getScriptDir())
# Experimental
# "/hi" -> get:
# var
# user1 = ctx.cookies.getOrDefault("user1", "")
# user1 = ctx.cookies.getOrDefault("user", "")
# user = getUserFromCookie(user1)
# uploadcare_pub_key = getEnv("UPLOAD_CARE_PUBLIC_KEY")
# compileTemplateFile("view" / "hi.html", baseDir = getScriptDir())
@ -116,4 +116,4 @@ load()
servePublic("src/public", "/static")
run()
run()