From 0e14a717324432f16f216544086f96b5cc2bdc5a Mon Sep 17 00:00:00 2001 From: cereci5049 Date: Sat, 10 Aug 2024 15:02:40 +0530 Subject: [PATCH] 037 --- src/controller/signup.nim | 4 +++- src/hh1.nim | 40 ++++++++++++++++++++++++--------- src/lib/mics.nim | 24 ++++++++++---------- src/view/partials/_master.nimja | 6 ++--- 4 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/controller/signup.nim b/src/controller/signup.nim index e05f695..f69d270 100644 --- a/src/controller/signup.nim +++ b/src/controller/signup.nim @@ -8,7 +8,9 @@ import proc signup*(ctx: Context): string= if ctx.httpMethod == HttpGet: - var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", "")) + var + user1 = ctx.cookies.getOrDefault("user1", "none") + user = to(parseJson(user1), User) compileTemplateFile(getScriptDir() / "view" / "signup.nimja") elif ctx.httpMethod == HttpPost: var diff --git a/src/hh1.nim b/src/hh1.nim index 88d2f75..f8b7546 100644 --- a/src/hh1.nim +++ b/src/hh1.nim @@ -16,42 +16,57 @@ import "/" -> [get, post]: var - user1 = ctx.cookies.getOrDefault("user1", "none") + user1 = ctx.cookies.getOrDefault("user1", """{"none": "none"}""") echo user1 - var user = to(parseJson(user1), User) + # var user = to(parseJson(user1), User) compileTemplateFile(getScriptDir() / "view" / "index.nimja") "/shop" -> get: - var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", "")) - echo ctx.cookies.getOrDefault("user", "") + # var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", "")) + # echo ctx.cookies.getOrDefault("user", "") + var + user1 = ctx.cookies.getOrDefault("user1", "none") + user = to(parseJson(user1), User) compileTemplateFile(getScriptDir() / "view" / "shop.nimja") "/contact" -> get: - var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", "")) + var + user1 = ctx.cookies.getOrDefault("user1", "none") + user = to(parseJson(user1), User) compileTemplateFile(getScriptDir() / "view" / "contact.nimja") "/cart" -> get: - var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", "")) + # var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", "")) + var + user1 = ctx.cookies.getOrDefault("user1", "none") + user = to(parseJson(user1), User) compileTemplateFile(getScriptDir() / "view" / "cart.nimja") "/checkout" -> get: - var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", "")) + var + user1 = ctx.cookies.getOrDefault("user1", "none") + user = to(parseJson(user1), User) compileTemplateFile(getScriptDir() / "view" / "checkout.nimja") "/shop/:id" -> get: var prodId = capitalizeAscii(ctx.pathParams["id"]) - user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", "")) + user1 = ctx.cookies.getOrDefault("user1", "none") + user = to(parseJson(user1), User) compileTemplateFile(getScriptDir() / "view" / "shop-detail.nimja") "/testimonial" -> get: - var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", "")) + var + user1 = ctx.cookies.getOrDefault("user1", "none") + user = to(parseJson(user1), User) compileTemplateFile(getScriptDir() / "view" / "testimonial.nimja") "/signup" -> [get, post]: ctx.signup() "/login" -> get: - var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", "")) + var + user1 = ctx.cookies.getOrDefault("user1", "none") + # user = to(parseJson(user1), User) compileTemplateFile(getScriptDir() / "view" / "login.nimja") "/htmx/login" -> post: var @@ -85,6 +100,7 @@ import echo $(%* temp[1]) echo ctx.cookies ctx.response.headers.add("HX-Redirect", "/") + # ctx.send("hello") else: for a, b in form: val.name = b @@ -118,7 +134,9 @@ import ctx.send htmxPassword(pw, val) "/:path" -> get: - var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", "")) + var + user1 = ctx.cookies.getOrDefault("user1", "none") + user = to(parseJson(user1), User) compileTemplateFile(getScriptDir() / "view" / "404.nimja") servePublic("src/public", "/static") diff --git a/src/lib/mics.nim b/src/lib/mics.nim index 82e7326..d366f43 100644 --- a/src/lib/mics.nim +++ b/src/lib/mics.nim @@ -12,15 +12,15 @@ proc newTurso*(): Turso = echo getEnv("DATABASE_URL") result = connect(getEnv("DATABASE_URL"), getEnv("AUTH_TOKEN")) -proc getUserFromCookie*(ctx: Context, user: string): User = - if user == "": - return User( - firstName: "", - lastName: "", - email: "", - phone: "", - password: "", - accessLevel: 0 - ) - else: - return to(parseJson(user), User) \ No newline at end of file +# proc getUserFromCookie*(ctx: Context, user: string): User = +# if user == "": +# return User( +# firstName: "", +# lastName: "", +# email: "", +# phone: "", +# password: "", +# accessLevel: 0 +# ) +# else: +# return to(parseJson(user), User) \ No newline at end of file diff --git a/src/view/partials/_master.nimja b/src/view/partials/_master.nimja index 526c59e..d6f9989 100644 --- a/src/view/partials/_master.nimja +++ b/src/view/partials/_master.nimja @@ -76,7 +76,7 @@
- {% if user.firstName != "" %} + {# {% if user.firstName != "" %} - {% else %} + {% else %} #} - {% endif %} + {# {% endif %} #}