Fixes for new_async version of Jester.

This commit is contained in:
Dominik Picheta 2014-07-13 10:45:26 +01:00
commit fbd8f057bb
4 changed files with 172 additions and 156 deletions

View file

@ -11,7 +11,7 @@ import cairo, os, strutils, jester
proc getCaptchaFilename*(i: int): string {.inline.} = proc getCaptchaFilename*(i: int): string {.inline.} =
result = "public/captchas/capture_" & $i & ".png" result = "public/captchas/capture_" & $i & ".png"
proc getCaptchaUrl*(req: var TRequest, i: int): string = proc getCaptchaUrl*(req: PRequest, i: int): string =
result = req.makeUri("/captchas/capture_" & $i & ".png", absolute = false) result = req.makeUri("/captchas/capture_" & $i & ".png", absolute = false)
proc createCaptcha*(file, text: string) = proc createCaptcha*(file, text: string) =

View file

@ -8,7 +8,7 @@
import import
os, strutils, times, md5, strtabs, cgi, math, db_sqlite, matchers, os, strutils, times, md5, strtabs, cgi, math, db_sqlite, matchers,
rst, rstgen, captchas, sockets, scgi, jester rst, rstgen, captchas, scgi, jester, asyncdispatch, asyncnet
from htmlgen import tr, th, td, span from htmlgen import tr, th, td, span
@ -33,7 +33,7 @@ type
TPost = tuple[subject, content: string] TPost = tuple[subject, content: string]
TForumData = object of TSession TForumData = object of TSession
req: TRequest req: PRequest
userid: string userid: string
actionContent: string actionContent: string
errorMsg, loginErrorMsg: string errorMsg, loginErrorMsg: string
@ -651,23 +651,24 @@ template createTFD(): stmt =
if request.cookies.len > 0: if request.cookies.len > 0:
checkLoggedIn(c) checkLoggedIn(c)
get "/": routes:
get "/":
createTFD() createTFD()
c.isThreadsList = true c.isThreadsList = true
var count = 0 var count = 0
resp genMain(c, genThreadsList(c, count), resp genMain(c, genThreadsList(c, count),
additionalHeaders = genRSSHeaders(c), showRssLinks = true) additionalHeaders = genRSSHeaders(c), showRssLinks = true)
get "/threadActivity.xml": get "/threadActivity.xml":
createTFD() createTFD()
c.isThreadsList = true c.isThreadsList = true
resp genThreadsRSS(c), "application/atom+xml" resp genThreadsRSS(c), "application/atom+xml"
get "/postActivity.xml": get "/postActivity.xml":
createTFD() createTFD()
resp genPostsRSS(c), "application/atom+xml" resp genPostsRSS(c), "application/atom+xml"
get "/t/@threadid/?@page?/?": get "/t/@threadid/?@page?/?":
createTFD() createTFD()
parseInt(@"threadid", c.threadId, -1..1000_000) parseInt(@"threadid", c.threadId, -1..1000_000)
if @"page".len > 0: if @"page".len > 0:
@ -705,7 +706,7 @@ get "/t/@threadid/?@page?/?":
cond count != 0 cond count != 0
resp genMain(c, posts, pSubject & " - Nimrod Forum") resp genMain(c, posts, pSubject & " - Nimrod Forum")
get "/page/@page/?": get "/page/@page/?":
createTFD() createTFD()
c.isThreadsList = true c.isThreadsList = true
cond (@"page" != "") cond (@"page" != "")
@ -718,7 +719,7 @@ get "/page/@page/?":
resp genMain(c, list, "Page " & $c.pageNum & " - Nimrod Forum", resp genMain(c, list, "Page " & $c.pageNum & " - Nimrod Forum",
genRSSHeaders(c), showRssLinks = true) genRSSHeaders(c), showRssLinks = true)
get "/profile/@nick/?": get "/profile/@nick/?":
createTFD() createTFD()
cond (@"nick" != "") cond (@"nick" != "")
var userinfo: TUserInfo var userinfo: TUserInfo
@ -728,45 +729,45 @@ get "/profile/@nick/?":
else: else:
halt() halt()
get "/login/?": get "/login/?":
createTFD() createTFD()
resp genMain(c, genFormLogin(c), "Log in - Nimrod Forum") resp genMain(c, genFormLogin(c), "Log in - Nimrod Forum")
get "/logout/?": get "/logout/?":
createTFD() createTFD()
logout(c) logout(c)
redirect(uri("/")) redirect(uri("/"))
get "/register/?": get "/register/?":
createTFD() createTFD()
resp genMain(c, genFormRegister(c), "Register - Nimrod Forum") resp genMain(c, genFormRegister(c), "Register - Nimrod Forum")
template readIDs(): stmt = template readIDs(): stmt =
# Retrieve the threadid, postid and pagenum # Retrieve the threadid, postid and pagenum
if (@"threadid").len > 0: if (@"threadid").len > 0:
parseInt(@"threadid", c.threadId, -1..1000_000) parseInt(@"threadid", c.threadId, -1..1000_000)
if (@"postid").len > 0: if (@"postid").len > 0:
parseInt(@"postid", c.postId, -1..1000_000) parseInt(@"postid", c.postId, -1..1000_000)
template finishLogin(): stmt = template finishLogin(): stmt =
setCookie("sid", c.userpass, daysForward(7)) setCookie("sid", c.userpass, daysForward(7))
redirect(uri("/")) redirect(uri("/"))
template handleError(action: string, topText: string, isEdit: bool): stmt = template handleError(action: string, topText: string, isEdit: bool): stmt =
if c.isPreview: if c.isPreview:
body.add genPostPreview(c, @"subject", @"content", body.add genPostPreview(c, @"subject", @"content",
c.userName, $getGMTime(getTime())) c.userName, $getGMTime(getTime()))
body.add genFormPost(c, action, topText, reuseText, reuseText, isEdit) body.add genFormPost(c, action, topText, reuseText, reuseText, isEdit)
resp genMain(c, body(), "Nimrod Forum - Error") resp genMain(c, body(), "Nimrod Forum - Error")
post "/dologin": post "/dologin":
createTFD() createTFD()
if login(c, @"name", @"password"): if login(c, @"name", @"password"):
finishLogin() finishLogin()
else: else:
resp c.genMain(genFormLogin(c)) resp c.genMain(genFormLogin(c))
post "/doregister": post "/doregister":
createTFD() createTFD()
if c.register(@"name", @"new_password", @"antibot", @"email"): if c.register(@"name", @"new_password", @"antibot", @"email"):
discard c.login(@"name", @"new_password") discard c.login(@"name", @"new_password")
@ -774,7 +775,7 @@ post "/doregister":
else: else:
resp c.genMain(genFormRegister(c)) resp c.genMain(genFormRegister(c))
post "/donewthread": post "/donewthread":
createTFD() createTFD()
if newThread(c): if newThread(c):
redirect(uri("/")) redirect(uri("/"))
@ -782,7 +783,7 @@ post "/donewthread":
body = "" body = ""
handleError("donewthread", "New thread", false) handleError("donewthread", "New thread", false)
post "/doreply": post "/doreply":
createTFD() createTFD()
readIDs() readIDs()
if reply(c): if reply(c):
@ -794,7 +795,7 @@ post "/doreply":
body = genPostsList(c, $c.threadId, count) body = genPostsList(c, $c.threadId, count)
handleError("doreply", "Reply", false) handleError("doreply", "Reply", false)
post "/doedit": post "/doedit":
createTFD() createTFD()
readIDs() readIDs()
if edit(c, c.postId): if edit(c, c.postId):
@ -803,13 +804,13 @@ post "/doedit":
body = "" body = ""
handleError("doedit", "Edit", true) handleError("doedit", "Edit", true)
get "/newthread/?": get "/newthread/?":
createTFD() createTFD()
resp genMain(c, genFormPost(c, "donewthread", "New thread", "", "", false), resp genMain(c, genFormPost(c, "donewthread", "New thread", "", "", false),
"New Thread - Nimrod Forum") "New Thread - Nimrod Forum")
const licenseRst = slurp("static/license.rst") const licenseRst = slurp("static/license.rst")
get "/license": get "/license":
createTFD() createTFD()
resp genMain(c, rstToHtml(licenseRst), "Content license - Nimrod Forum") resp genMain(c, rstToHtml(licenseRst), "Content license - Nimrod Forum")
@ -822,6 +823,11 @@ when isMainModule:
if paramCount() > 0: if paramCount() > 0:
if paramStr(1) == "scgi": if paramStr(1) == "scgi":
http = false http = false
run("", port = TPort(9000), http = http)
#run("", port = TPort(9000), http = http)
var settings = newSettings()
settings.port = TPort(8080)
jester.serve(settings, match)
runForever()
db.close() db.close()

11
nimforum.babel Normal file
View file

@ -0,0 +1,11 @@
[Package]
name = "nimforum"
version = "0.1.0"
author = "Dominik Picheta"
description = "Nimrod forum"
license = "MIT"
bin = "forum"
[Deps]
Requires: "nimrod >= 0.9.2, cairo#head, jester#head"

View file

@ -3,4 +3,3 @@
--path:"$nimrod/lib/packages/docutils" --path:"$nimrod/lib/packages/docutils"
--path:"$nimrod" --path:"$nimrod"
--path:"../jester"