diff --git a/src/quotesite.nim b/src/quotesite.nim index 2f9867a..f43371c 100644 --- a/src/quotesite.nim +++ b/src/quotesite.nim @@ -6,6 +6,7 @@ const browseTemplate*: string = staticRead "./templates/browse.mustache" errorTemplate*: string = staticRead "./templates/error.mustache" channelTemplate*: string = staticRead "./templates/channel.mustache" + submitTemplate*: string = staticRead "./templates/submit.mustache" testTemplate*: string = """
hi!
""" @@ -26,6 +27,18 @@ except: echo getCurrentExceptionMsg() raise +proc validItem(s: string, channel: bool = false) = + if channel: + if s.startsWith "#": + echo "fuck" + else: + raise newException(ValueError, "invalid layout of channel name") + else: discard + + if s.contains " ": + raise newException(ValueError, "invalid layout of quote") + else: discard + template renderMustache*(title: string, templ: string, ctx: Context): expr = var layoutCtx = moustachu.newContext() @@ -95,6 +108,31 @@ routes: except: fail() + get "/submit": + renderMustache "submit", submitTemplate, newContext() + + post "/submit": + try: + var + channel = $(request.formData.mget "channel").body + nick = $(request.formData.mget "nick").body + adder = $(request.formData.mget "adder").body + quote = $(request.formData.mget "quote").body + + channel.validItem() + nick.validItem() + adder.validItem() + + let + now = $(getTime().toSeconds()) + data = now.split(".")[0].parseInt() + + db.exec(sql"INSERT INTO quotes VALUES(null, ?, ?, ?, ?, ?, 0);", channel, nick, adder, quote, data) + + redirect (channel.replace("#", "hashtag-") & "/0") + except: + fail() + get "/@kind/@id": var title: string = "" @@ -127,6 +165,8 @@ routes: else: halt Http404, "not found" + echo request.headers.getOrDefault "X-Forwarded-For" + ctx = newContext() var quoteSeq = newSeq[Context]() diff --git a/src/quotesite.nims b/src/quotesite.nims index fe8e8aa..e69de29 100644 --- a/src/quotesite.nims +++ b/src/quotesite.nims @@ -1,3 +0,0 @@ ---opt:size ---define:release ---deadCodeElim:on diff --git a/src/templates/layout.mustache b/src/templates/layout.mustache index 572f96d..a6418e5 100644 --- a/src/templates/layout.mustache +++ b/src/templates/layout.mustache @@ -7,7 +7,7 @@