8/src/hh1.nim

119 lines
3.3 KiB
Nim
Raw Normal View History

2024-07-19 17:51:48 +02:00
import
2024-08-15 22:19:10 +02:00
mike,
2024-07-19 19:58:22 +02:00
nimja,
2024-07-20 16:31:35 +02:00
strutils,
json,
2024-07-20 18:16:38 +02:00
strformat,
2024-08-14 20:04:43 +02:00
httpClient,
dotenv,
2024-08-07 22:29:42 +02:00
./lib/[mics, htmx],
2024-07-20 16:31:35 +02:00
./db/users,
2024-08-07 22:50:33 +02:00
./model/[model, rand],
./controller/[signup, login, htmx]
2024-08-14 20:04:43 +02:00
load()
2024-07-19 17:36:17 +02:00
2024-07-20 18:16:38 +02:00
"/^path" -> before[post, get]:
var path2 = ctx.pathParams["path"]
echo(fmt"[mike] before request: {ctx.httpMethod} {path2}")
2024-07-20 16:31:35 +02:00
"/" -> [get, post]:
2024-08-07 20:32:25 +02:00
var
2024-08-10 22:53:25 +02:00
user1 = ctx.cookies.getOrDefault("user1", "")
user = getUserFromCookie(user1)
echo user.firstName
2024-08-15 22:19:10 +02:00
compileTemplateFile("view" / "index.html", baseDir = getScriptDir())
2024-07-19 17:36:17 +02:00
2024-07-19 18:39:21 +02:00
"/shop" -> get:
2024-08-10 11:32:40 +02:00
var
2024-08-14 20:04:43 +02:00
user1 = ctx.cookies.getOrDefault("user1", "")
2024-08-10 22:53:25 +02:00
user = getUserFromCookie(user1)
2024-08-15 22:19:10 +02:00
compileTemplateFile("view" / "shop.html", baseDir = getScriptDir())
2024-07-19 18:39:21 +02:00
"/contact" -> get:
2024-08-10 11:32:40 +02:00
var
2024-08-14 20:04:43 +02:00
user1 = ctx.cookies.getOrDefault("user1", "")
2024-08-10 22:53:25 +02:00
user = getUserFromCookie(user1)
2024-08-15 22:19:10 +02:00
compileTemplateFile("view" / "contact.html", baseDir = getScriptDir())
2024-07-19 18:39:21 +02:00
"/cart" -> get:
2024-08-10 11:32:40 +02:00
var
2024-08-14 20:04:43 +02:00
user1 = ctx.cookies.getOrDefault("user1", "")
2024-08-10 22:53:25 +02:00
user = getUserFromCookie(user1)
2024-08-15 22:19:10 +02:00
compileTemplateFile("view" / "cart.html", baseDir = getScriptDir())
2024-07-19 18:39:21 +02:00
2024-07-19 19:25:49 +02:00
"/checkout" -> get:
2024-08-10 11:32:40 +02:00
var
2024-08-14 20:04:43 +02:00
user1 = ctx.cookies.getOrDefault("user1", "")
2024-08-10 22:53:25 +02:00
user = getUserFromCookie(user1)
2024-08-15 22:19:10 +02:00
compileTemplateFile("view" / "checkout.html", baseDir = getScriptDir())
2024-07-19 19:25:49 +02:00
2024-07-19 19:58:22 +02:00
"/shop/:id" -> get:
2024-08-09 12:00:15 +02:00
var
prodId = capitalizeAscii(ctx.pathParams["id"])
2024-08-14 20:04:43 +02:00
user1 = ctx.cookies.getOrDefault("user1", "")
2024-08-10 22:53:25 +02:00
user = getUserFromCookie(user1)
2024-08-15 22:19:10 +02:00
compileTemplateFile("view" / "shop-detail.html", baseDir = getScriptDir())
2024-07-19 19:25:49 +02:00
"/testimonial" -> get:
2024-08-10 11:32:40 +02:00
var
2024-08-14 20:04:43 +02:00
user1 = ctx.cookies.getOrDefault("user1", "")
2024-08-10 22:53:25 +02:00
user = getUserFromCookie(user1)
2024-08-15 22:19:10 +02:00
compileTemplateFile("view" / "testimonial.html", baseDir = getScriptDir())
2024-07-19 19:25:49 +02:00
2024-08-10 22:53:25 +02:00
"/signup" -> [get, post]: ctx.signup()
2024-07-20 14:26:19 +02:00
"/login" -> get:
2024-08-10 11:32:40 +02:00
var
2024-08-14 20:04:43 +02:00
user1 = ctx.cookies.getOrDefault("user1", "")
2024-08-10 22:53:25 +02:00
user = getUserFromCookie(user1)
2024-08-15 22:19:10 +02:00
compileTemplateFile("view" / "login.html", baseDir = getScriptDir())
2024-08-07 22:29:42 +02:00
2024-08-14 20:04:43 +02:00
"/htmx/login" -> post: ctx.htmxLogin()
2024-08-08 19:19:24 +02:00
"/htmx/email" -> post: htmxEmail(ctx)
2024-08-08 19:19:24 +02:00
"/htmx/password" -> post: htmxPassword(ctx)
2024-07-23 22:53:43 +02:00
"/htmx/fname" -> post: htmxFirstName(ctx)
"/htmx/lname" -> post: htmxLastName(ctx)
"/htmx/phone" -> post: htmxPhone(ctx)
2024-08-05 20:54:09 +02:00
"/:path" -> get:
2024-08-10 11:32:40 +02:00
var
2024-08-14 20:04:43 +02:00
user1 = ctx.cookies.getOrDefault("user1", "")
2024-08-10 22:53:25 +02:00
user = getUserFromCookie(user1)
2024-08-15 22:19:10 +02:00
compileTemplateFile("view" / "404.html", baseDir = getScriptDir())
2024-08-05 20:54:09 +02:00
2024-08-15 21:57:47 +02:00
# Experimental
# "/hi" -> get:
# var
# user1 = ctx.cookies.getOrDefault("user1", "")
# user = getUserFromCookie(user1)
# uploadcare_pub_key = getEnv("UPLOAD_CARE_PUBLIC_KEY")
# compileTemplateFile("view" / "hi.html", baseDir = getScriptDir())
# "/delete-hi" -> post:
# var
# client = newHttpClient()
# uploadcare_pub_key = getEnv("UPLOAD_CARE_PUBLIC_KEY")
# uploadcare_secret_key = getEnv("UPLOAD_CARE_SECRET_KEY")
# client.headers = newHttpHeaders({"Authorization": fmt"Uploadcare.Simple {uploadcare_pub_key}:{uploadcare_secret_key}"})
# var form = ctx.urlForm
# echo form
# var img_uuid = form["img1"]
# echo img_uuid
# echo fmt"https://api.uploadcare.com/files/{img_uuid}/storage/"
# try:
# let response = client.request(fmt"https://api.uploadcare.com/files/{img_uuid}/storage/", httpMethod = HttpDelete)
# echo response.status
# finally:
# client.close()
# var js = parseJson("""{"status": "success"}""")
# ctx.send(js)
2024-08-14 20:04:43 +02:00
2024-07-19 17:51:48 +02:00
servePublic("src/public", "/static")
run()