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=
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

View file

@ -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")

View file

@ -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)
# proc getUserFromCookie*(ctx: Context, user: string): User =
# if user == "":
# return User(
# firstName: "",
# lastName: "",
# email: "",
# phone: "",
# password: "",
# accessLevel: 0
# )
# else:
# return to(parseJson(user), User)

View file

@ -76,7 +76,7 @@
</div>
<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>
{% if user.firstName != "" %}
{# {% if user.firstName != "" %}
<div class="nav-item dropdown">
<a href="#" class="fas fa-user fa-2x" data-bs-toggle="dropdown"></a>
<div class="dropdown-menu m-0 bg-secondary rounded-0">
@ -86,11 +86,11 @@
<a href="404.html" class="dropdown-item">404 Page</a>
</div>
</div>
{% else %}
{% else %} #}
<a href="/login" class="me-4 my-auto">
<i class="fas fa-user fa-2x"></i>
</a>
{% endif %}
{# {% endif %} #}
<a href="/cart" class="position-relative my-auto">
<i class="fa fa-shopping-bag fa-2x"></i>