quote submission

This commit is contained in:
Christine Dodrill 2016-02-06 00:01:23 -08:00
parent 427c7f5858
commit 38bb2c3ac0
4 changed files with 57 additions and 4 deletions

View File

@ -6,6 +6,7 @@ const
browseTemplate*: string = staticRead "./templates/browse.mustache" browseTemplate*: string = staticRead "./templates/browse.mustache"
errorTemplate*: string = staticRead "./templates/error.mustache" errorTemplate*: string = staticRead "./templates/error.mustache"
channelTemplate*: string = staticRead "./templates/channel.mustache" channelTemplate*: string = staticRead "./templates/channel.mustache"
submitTemplate*: string = staticRead "./templates/submit.mustache"
testTemplate*: string = """<p>hi!</p>""" testTemplate*: string = """<p>hi!</p>"""
@ -26,6 +27,18 @@ except:
echo getCurrentExceptionMsg() echo getCurrentExceptionMsg()
raise 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 = template renderMustache*(title: string, templ: string, ctx: Context): expr =
var var
layoutCtx = moustachu.newContext() layoutCtx = moustachu.newContext()
@ -95,6 +108,31 @@ routes:
except: except:
fail() 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": get "/@kind/@id":
var var
title: string = "" title: string = ""
@ -127,6 +165,8 @@ routes:
else: else:
halt Http404, "not found" halt Http404, "not found"
echo request.headers.getOrDefault "X-Forwarded-For"
ctx = newContext() ctx = newContext()
var quoteSeq = newSeq[Context]() var quoteSeq = newSeq[Context]()

View File

@ -1,3 +0,0 @@
--opt:size
--define:release
--deadCodeElim:on

View File

@ -7,7 +7,7 @@
<div class=metanav> <div class=metanav>
<a href="/">home</a> <a href="/">home</a>
<a href="/channel">channel</a> <a href="/channel">channel</a>
<!-- <a href="/submit">submit</a> --> <a href="/submit">submit</a>
</div> </div>
<h2>{{ title }}</h2> <h2>{{ title }}</h2>

View File

@ -0,0 +1,16 @@
<form method="POST" action="/submit" enctype="multipart/form-data">
<dl>
<dt>channel</dt>
<dd><input type="text" name="channel" /></dd>
<dt>nickname</dt>
<dd><input type="text" name="nick" /></dd>
<dt>your nick</dd>
<dd><input type="text" name="adder" /></dd>
<dt>quote</dt>
<dd><input type="text" name="quote" /></dd>
<dd><input type=submit value="submit"></dd>
</form>