This commit is contained in:
cereci5049 2024-08-10 15:02:40 +05:30
parent 5c8e94a9a6
commit 0e14a71732
4 changed files with 47 additions and 27 deletions

View file

@ -8,7 +8,9 @@ import
proc signup*(ctx: Context): string= proc signup*(ctx: Context): string=
if ctx.httpMethod == HttpGet: 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") compileTemplateFile(getScriptDir() / "view" / "signup.nimja")
elif ctx.httpMethod == HttpPost: elif ctx.httpMethod == HttpPost:
var var

View file

@ -16,42 +16,57 @@ import
"/" -> [get, post]: "/" -> [get, post]:
var var
user1 = ctx.cookies.getOrDefault("user1", "none") user1 = ctx.cookies.getOrDefault("user1", """{"none": "none"}""")
echo user1 echo user1
var user = to(parseJson(user1), User) # var user = to(parseJson(user1), User)
compileTemplateFile(getScriptDir() / "view" / "index.nimja") compileTemplateFile(getScriptDir() / "view" / "index.nimja")
"/shop" -> get: "/shop" -> get:
var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", "")) # var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", ""))
echo 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") compileTemplateFile(getScriptDir() / "view" / "shop.nimja")
"/contact" -> get: "/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") compileTemplateFile(getScriptDir() / "view" / "contact.nimja")
"/cart" -> get: "/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") compileTemplateFile(getScriptDir() / "view" / "cart.nimja")
"/checkout" -> get: "/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") compileTemplateFile(getScriptDir() / "view" / "checkout.nimja")
"/shop/:id" -> get: "/shop/:id" -> get:
var var
prodId = capitalizeAscii(ctx.pathParams["id"]) 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") compileTemplateFile(getScriptDir() / "view" / "shop-detail.nimja")
"/testimonial" -> get: "/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") compileTemplateFile(getScriptDir() / "view" / "testimonial.nimja")
"/signup" -> [get, post]: ctx.signup() "/signup" -> [get, post]: ctx.signup()
"/login" -> get: "/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") compileTemplateFile(getScriptDir() / "view" / "login.nimja")
"/htmx/login" -> post: "/htmx/login" -> post:
var var
@ -85,6 +100,7 @@ import
echo $(%* temp[1]) echo $(%* temp[1])
echo ctx.cookies echo ctx.cookies
ctx.response.headers.add("HX-Redirect", "/") ctx.response.headers.add("HX-Redirect", "/")
# ctx.send("hello")
else: else:
for a, b in form: for a, b in form:
val.name = b val.name = b
@ -118,7 +134,9 @@ import
ctx.send htmxPassword(pw, val) ctx.send htmxPassword(pw, val)
"/:path" -> get: "/: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") compileTemplateFile(getScriptDir() / "view" / "404.nimja")
servePublic("src/public", "/static") servePublic("src/public", "/static")

View file

@ -12,15 +12,15 @@ proc newTurso*(): Turso =
echo getEnv("DATABASE_URL") echo getEnv("DATABASE_URL")
result = connect(getEnv("DATABASE_URL"), getEnv("AUTH_TOKEN")) result = connect(getEnv("DATABASE_URL"), getEnv("AUTH_TOKEN"))
proc getUserFromCookie*(ctx: Context, user: string): User = # proc getUserFromCookie*(ctx: Context, user: string): User =
if user == "": # if user == "":
return User( # return User(
firstName: "", # firstName: "",
lastName: "", # lastName: "",
email: "", # email: "",
phone: "", # phone: "",
password: "", # password: "",
accessLevel: 0 # accessLevel: 0
) # )
else: # else:
return to(parseJson(user), User) # return to(parseJson(user), User)

View file

@ -76,7 +76,7 @@
</div> </div>
<div class="d-flex m-3 me-0"> <div class="d-flex m-3 me-0">
<button class="btn-search btn border border-secondary btn-md-square rounded-circle bg-white me-4" data-bs-toggle="modal" data-bs-target="#searchModal"><i class="fas fa-search text-primary"></i></button> <button class="btn-search btn border border-secondary btn-md-square rounded-circle bg-white me-4" data-bs-toggle="modal" data-bs-target="#searchModal"><i class="fas fa-search text-primary"></i></button>
{% if user.firstName != "" %} {# {% if user.firstName != "" %}
<div class="nav-item dropdown"> <div class="nav-item dropdown">
<a href="#" class="fas fa-user fa-2x" data-bs-toggle="dropdown"></a> <a href="#" class="fas fa-user fa-2x" data-bs-toggle="dropdown"></a>
<div class="dropdown-menu m-0 bg-secondary rounded-0"> <div class="dropdown-menu m-0 bg-secondary rounded-0">
@ -86,11 +86,11 @@
<a href="404.html" class="dropdown-item">404 Page</a> <a href="404.html" class="dropdown-item">404 Page</a>
</div> </div>
</div> </div>
{% else %} {% else %} #}
<a href="/login" class="me-4 my-auto"> <a href="/login" class="me-4 my-auto">
<i class="fas fa-user fa-2x"></i> <i class="fas fa-user fa-2x"></i>
</a> </a>
{% endif %} {# {% endif %} #}
<a href="/cart" class="position-relative my-auto"> <a href="/cart" class="position-relative my-auto">
<i class="fa fa-shopping-bag fa-2x"></i> <i class="fa fa-shopping-bag fa-2x"></i>