Merge pull request '036' (#17) from ayushman into main
Reviewed-on: #17
This commit is contained in:
commit
7c7585b304
5 changed files with 56 additions and 9 deletions
|
@ -8,6 +8,7 @@ import
|
|||
|
||||
proc signup*(ctx: Context): string=
|
||||
if ctx.httpMethod == HttpGet:
|
||||
var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", ""))
|
||||
compileTemplateFile(getScriptDir() / "view" / "signup.nimja")
|
||||
elif ctx.httpMethod == HttpPost:
|
||||
var
|
||||
|
|
|
@ -37,6 +37,7 @@ 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(),
|
||||
|
@ -47,4 +48,5 @@ proc getUser*(conn: Turso, email: string, password: string): (bool, User)=
|
|||
)
|
||||
result = (true, user)
|
||||
else:
|
||||
echo "h3"
|
||||
result = (false, user)
|
23
src/hh1.nim
23
src/hh1.nim
|
@ -4,6 +4,7 @@ import
|
|||
strutils,
|
||||
json,
|
||||
strformat,
|
||||
cookies,
|
||||
./lib/[mics, htmx],
|
||||
./db/users,
|
||||
./model/[model, rand],
|
||||
|
@ -15,32 +16,42 @@ import
|
|||
|
||||
"/" -> [get, post]:
|
||||
var
|
||||
user = parseJson(ctx.cookies.getOrDefault("user", ""))
|
||||
user2 = to(user, User)
|
||||
user1 = ctx.cookies.getOrDefault("user1", "none")
|
||||
echo user1
|
||||
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", "")
|
||||
compileTemplateFile(getScriptDir() / "view" / "shop.nimja")
|
||||
|
||||
"/contact" -> get:
|
||||
var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", ""))
|
||||
compileTemplateFile(getScriptDir() / "view" / "contact.nimja")
|
||||
|
||||
"/cart" -> get:
|
||||
var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", ""))
|
||||
compileTemplateFile(getScriptDir() / "view" / "cart.nimja")
|
||||
|
||||
"/checkout" -> get:
|
||||
var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", ""))
|
||||
compileTemplateFile(getScriptDir() / "view" / "checkout.nimja")
|
||||
|
||||
"/shop/:id" -> get:
|
||||
var prodId = capitalizeAscii(ctx.pathParams["id"])
|
||||
var
|
||||
prodId = capitalizeAscii(ctx.pathParams["id"])
|
||||
user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", ""))
|
||||
compileTemplateFile(getScriptDir() / "view" / "shop-detail.nimja")
|
||||
|
||||
"/testimonial" -> get:
|
||||
var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", ""))
|
||||
compileTemplateFile(getScriptDir() / "view" / "testimonial.nimja")
|
||||
|
||||
"/signup" -> [get, post]: ctx.signup()
|
||||
|
||||
"/login" -> get:
|
||||
var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", ""))
|
||||
compileTemplateFile(getScriptDir() / "view" / "login.nimja")
|
||||
"/htmx/login" -> post:
|
||||
var
|
||||
|
@ -52,6 +63,7 @@ import
|
|||
val: Validity
|
||||
validity = initTable[string, Validity]()
|
||||
|
||||
ctx &= initCookie("user2", "$(%* temp[1])")
|
||||
if em.len==0 or ps.len==0:
|
||||
for a, b in form:
|
||||
if form[a] == "":
|
||||
|
@ -69,7 +81,9 @@ import
|
|||
let conn=newTurso()
|
||||
var temp=getUser(conn, em, ps)
|
||||
if temp[0] == true:
|
||||
ctx &= initCookie("user", $(%* temp[1]))
|
||||
ctx &= initCookie("user1", $(%* temp[1]))
|
||||
echo $(%* temp[1])
|
||||
echo ctx.cookies
|
||||
ctx.response.headers.add("HX-Redirect", "/")
|
||||
else:
|
||||
for a, b in form:
|
||||
|
@ -104,6 +118,7 @@ import
|
|||
ctx.send htmxPassword(pw, val)
|
||||
|
||||
"/:path" -> get:
|
||||
var user = ctx.getUserFromCookie(ctx.cookies.getOrDefault("user", ""))
|
||||
compileTemplateFile(getScriptDir() / "view" / "404.nimja")
|
||||
|
||||
servePublic("src/public", "/static")
|
||||
|
|
|
@ -2,10 +2,25 @@ import
|
|||
turso,
|
||||
dotenv,
|
||||
os,
|
||||
mike,
|
||||
json,
|
||||
../model/model
|
||||
|
||||
load()
|
||||
|
||||
proc newTurso*(): Turso =
|
||||
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 =
|
||||
if user == "":
|
||||
return User(
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
email: "",
|
||||
phone: "",
|
||||
password: "",
|
||||
accessLevel: 0
|
||||
)
|
||||
else:
|
||||
return to(parseJson(user), User)
|
|
@ -76,13 +76,27 @@
|
|||
</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>
|
||||
<a href="/cart" class="position-relative me-4 my-auto">
|
||||
{% 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">
|
||||
<a href="/cart" class="dropdown-item">Cart</a>
|
||||
<a href="/checkout" class="dropdown-item">Chackout</a>
|
||||
<a href="/testimonial" class="dropdown-item">Testimonial</a>
|
||||
<a href="404.html" class="dropdown-item">404 Page</a>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<a href="/login" class="me-4 my-auto">
|
||||
<i class="fas fa-user fa-2x"></i>
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<a href="/cart" class="position-relative my-auto">
|
||||
<i class="fa fa-shopping-bag fa-2x"></i>
|
||||
<span class="position-absolute bg-secondary rounded-circle d-flex align-items-center justify-content-center text-dark px-1" style="top: -5px; left: 15px; height: 20px; min-width: 20px;">3</span>
|
||||
</a>
|
||||
<a href="/login" class="my-auto">
|
||||
<i class="fas fa-user fa-2x"></i>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
Loading…
Reference in a new issue