get rid of most deprecation warnings
This commit is contained in:
parent
9d8afecc5c
commit
a6fdd16893
4 changed files with 50 additions and 50 deletions
|
|
@ -16,13 +16,13 @@ proc newCacheHolder*(): CacheHolder =
|
||||||
result.caches = initTable[string, CacheInfo]()
|
result.caches = initTable[string, CacheInfo]()
|
||||||
|
|
||||||
proc invalidate*(cache: CacheHolder, name: string) =
|
proc invalidate*(cache: CacheHolder, name: string) =
|
||||||
cache.caches.mget(name.normalizePath()).valid = false
|
cache.caches[name.normalizePath()].valid = false
|
||||||
|
|
||||||
proc invalidateAll*(cache: CacheHolder) =
|
proc invalidateAll*(cache: CacheHolder) =
|
||||||
for key, val in mpairs(cache.caches):
|
for key, val in mpairs(cache.caches):
|
||||||
val.valid = false
|
val.valid = false
|
||||||
|
|
||||||
template get*(cache: CacheHolder, name: string, grabValue: expr): expr =
|
template get*(cache: CacheHolder, name: string, grabValue: untyped): untyped =
|
||||||
## Check to see if the cache contains value for ``name``. If it does and the
|
## Check to see if the cache contains value for ``name``. If it does and the
|
||||||
## cache is valid then doesn't recalculate it but returns the cached version.
|
## cache is valid then doesn't recalculate it but returns the cached version.
|
||||||
mixin normalizePath
|
mixin normalizePath
|
||||||
|
|
|
||||||
|
|
@ -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: PRequest, i: int): string =
|
proc getCaptchaUrl*(req: Request, 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) =
|
||||||
|
|
@ -23,7 +23,7 @@ proc createCaptcha*(file, text: string) =
|
||||||
|
|
||||||
setSourceRgb(cr, 1.0, 0.5, 0.0)
|
setSourceRgb(cr, 1.0, 0.5, 0.0)
|
||||||
moveTo(cr, 0.0, 10.0)
|
moveTo(cr, 0.0, 10.0)
|
||||||
showText(cr, repeatChar(text.len, 'O'))
|
showText(cr, repeat('O', text.len))
|
||||||
|
|
||||||
setSourceRgb(cr, 0.0, 0.0, 1.0)
|
setSourceRgb(cr, 0.0, 0.0, 1.0)
|
||||||
moveTo(cr, 0.0, 10.0)
|
moveTo(cr, 0.0, 10.0)
|
||||||
|
|
@ -35,5 +35,3 @@ proc createCaptcha*(file, text: string) =
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
createCaptcha("test.png", "1+33")
|
createCaptcha("test.png", "1+33")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#? stdtmpl | standard
|
#? stdtmpl | standard
|
||||||
#
|
#
|
||||||
#template `%`(idx: expr): expr {.immediate.} =
|
#template `%`(idx: untyped): untyped =
|
||||||
# row[idx]
|
# row[idx]
|
||||||
#end template
|
#end template
|
||||||
#
|
#
|
||||||
|
|
@ -288,7 +288,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#proc genSearchResults(c: var TForumData,
|
#proc genSearchResults(c: var TForumData,
|
||||||
# results: iterator: db_sqlite.TRow {.closure, tags: [FReadDB].},
|
# results: iterator: db_sqlite.Row {.closure, tags: [FReadDB].},
|
||||||
# count: var int): string =
|
# count: var int): string =
|
||||||
# const threadId = 0
|
# const threadId = 0
|
||||||
# const threadName = 1
|
# const threadName = 1
|
||||||
|
|
|
||||||
38
forum.nim
38
forum.nim
|
|
@ -40,7 +40,7 @@ type
|
||||||
TPost = tuple[subject, content: string]
|
TPost = tuple[subject, content: string]
|
||||||
|
|
||||||
TForumData = object of TSession
|
TForumData = object of TSession
|
||||||
req: PRequest
|
req: Request
|
||||||
userid: string
|
userid: string
|
||||||
actionContent: string
|
actionContent: string
|
||||||
errorMsg, loginErrorMsg: string
|
errorMsg, loginErrorMsg: string
|
||||||
|
|
@ -74,7 +74,7 @@ type
|
||||||
ForumError = object of Exception
|
ForumError = object of Exception
|
||||||
|
|
||||||
var
|
var
|
||||||
db: TDbConn
|
db: DbConn
|
||||||
isFTSAvailable: bool
|
isFTSAvailable: bool
|
||||||
config: Config
|
config: Config
|
||||||
|
|
||||||
|
|
@ -202,7 +202,7 @@ proc formatTimestamp(t: int): string =
|
||||||
return "just now"
|
return "just now"
|
||||||
|
|
||||||
proc getGravatarUrl(email: string, size = 80): string =
|
proc getGravatarUrl(email: string, size = 80): string =
|
||||||
let emailMD5 = email.toLower.toMD5
|
let emailMD5 = email.toLowerAscii.toMD5
|
||||||
return ("http://www.gravatar.com/avatar/" & $emailMD5 & "?s=" & $size &
|
return ("http://www.gravatar.com/avatar/" & $emailMD5 & "?s=" & $size &
|
||||||
"&d=identicon")
|
"&d=identicon")
|
||||||
|
|
||||||
|
|
@ -268,7 +268,7 @@ proc makeIdentHash(user, password, epoch, secret: string,
|
||||||
result = hash(user & password & epoch & secret, bcryptSalt)
|
result = hash(user & password & epoch & secret, bcryptSalt)
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
template `||`(x: expr): expr = (if not isNil(x): x else: "")
|
template `||`(x: untyped): untyped = (if not isNil(x): x else: "")
|
||||||
|
|
||||||
proc validThreadId(c: TForumData): bool =
|
proc validThreadId(c: TForumData): bool =
|
||||||
result = getValue(db, sql"select id from thread where id = ?",
|
result = getValue(db, sql"select id from thread where id = ?",
|
||||||
|
|
@ -442,7 +442,7 @@ proc validateRst(c: var TForumData, content: string): bool =
|
||||||
except EParseError:
|
except EParseError:
|
||||||
result = setError(c, "", getCurrentExceptionMsg())
|
result = setError(c, "", getCurrentExceptionMsg())
|
||||||
|
|
||||||
proc crud(c: TCrud, table: string, data: varargs[string]): TSqlQuery =
|
proc crud(c: TCrud, table: string, data: varargs[string]): SqlQuery =
|
||||||
case c
|
case c
|
||||||
of crCreate:
|
of crCreate:
|
||||||
var fields = "insert into " & table & "("
|
var fields = "insert into " & table & "("
|
||||||
|
|
@ -470,14 +470,14 @@ proc crud(c: TCrud, table: string, data: varargs[string]): TSqlQuery =
|
||||||
of crDelete:
|
of crDelete:
|
||||||
result = sql("delete from " & table & " where id = ?")
|
result = sql("delete from " & table & " where id = ?")
|
||||||
|
|
||||||
template retrSubject(c: expr) =
|
template retrSubject(c: untyped) =
|
||||||
if not c.req.params.hasKey("subject"):
|
if not c.req.params.hasKey("subject"):
|
||||||
raise newException(ForumError, "Subject empty")
|
raise newException(ForumError, "Subject empty")
|
||||||
let subject {.inject.} = c.req.params["subject"]
|
let subject {.inject.} = c.req.params["subject"]
|
||||||
if subject.strip.len < 3:
|
if subject.strip.len < 3:
|
||||||
return setError(c, "subject", "Subject not long enough")
|
return setError(c, "subject", "Subject not long enough")
|
||||||
|
|
||||||
template retrContent(c: expr) =
|
template retrContent(c: untyped) =
|
||||||
if not c.req.params.hasKey("content"):
|
if not c.req.params.hasKey("content"):
|
||||||
raise newException(ForumError, "Content empty")
|
raise newException(ForumError, "Content empty")
|
||||||
let content {.inject.} = c.req.params["content"]
|
let content {.inject.} = c.req.params["content"]
|
||||||
|
|
@ -486,25 +486,25 @@ template retrContent(c: expr) =
|
||||||
|
|
||||||
if not validateRst(c, content): return false
|
if not validateRst(c, content): return false
|
||||||
|
|
||||||
template retrPost(c: expr) =
|
template retrPost(c: untyped) =
|
||||||
retrSubject(c)
|
retrSubject(c)
|
||||||
retrContent(c)
|
retrContent(c)
|
||||||
|
|
||||||
template checkLogin(c: expr) =
|
template checkLogin(c: untyped) =
|
||||||
if not loggedIn(c): return setError(c, "", "User is not logged in")
|
if not loggedIn(c): return setError(c, "", "User is not logged in")
|
||||||
|
|
||||||
template checkOwnership(c, postId: expr) =
|
template checkOwnership(c, postId: untyped) =
|
||||||
if not c.isAdmin:
|
if not c.isAdmin:
|
||||||
let x = getValue(db, sql"select author from post where id = ?",
|
let x = getValue(db, sql"select author from post where id = ?",
|
||||||
postId)
|
postId)
|
||||||
if x != c.userId:
|
if x != c.userId:
|
||||||
return setError(c, "", "You are not the owner of this post")
|
return setError(c, "", "You are not the owner of this post")
|
||||||
|
|
||||||
template setPreviewData(c: expr) {.immediate, dirty.} =
|
template setPreviewData(c: untyped) {.dirty.} =
|
||||||
c.currentPost.subject = subject
|
c.currentPost.subject = subject
|
||||||
c.currentPost.content = content
|
c.currentPost.content = content
|
||||||
|
|
||||||
template writeToDb(c, cr, setPostId: expr) =
|
template writeToDb(c, cr, setPostId: untyped) =
|
||||||
# insert a comment in the DB
|
# insert a comment in the DB
|
||||||
let retID = insertID(db, crud(cr, "post", "author", "ip", "header", "content", "thread"),
|
let retID = insertID(db, crud(cr, "post", "author", "ip", "header", "content", "thread"),
|
||||||
c.userId, c.req.ip, subject, content, $c.threadId, "")
|
c.userId, c.req.ip, subject, content, $c.threadId, "")
|
||||||
|
|
@ -591,7 +591,8 @@ proc spamCheck(c: var TForumData, subject, content: string): bool =
|
||||||
|
|
||||||
for word in ["appliance", "kitchen", "cheap", "sale", "relocating",
|
for word in ["appliance", "kitchen", "cheap", "sale", "relocating",
|
||||||
"packers", "lenders", "fifa", "coins"]:
|
"packers", "lenders", "fifa", "coins"]:
|
||||||
if word in subjAlphabet.toLower() or word in contentAlphabet.toLower():
|
if word in subjAlphabet.toLowerAscii() or
|
||||||
|
word in contentAlphabet.toLowerAscii():
|
||||||
return true
|
return true
|
||||||
|
|
||||||
proc rateLimitCheck(c: var TForumData): bool =
|
proc rateLimitCheck(c: var TForumData): bool =
|
||||||
|
|
@ -989,7 +990,7 @@ proc prependRe(s: string): string =
|
||||||
elif s.startswith("Re:"): s
|
elif s.startswith("Re:"): s
|
||||||
else: "Re: " & s
|
else: "Re: " & s
|
||||||
|
|
||||||
template createTFD(): stmt =
|
template createTFD() =
|
||||||
var c {.inject.}: TForumData
|
var c {.inject.}: TForumData
|
||||||
init(c)
|
init(c)
|
||||||
c.req = request
|
c.req = request
|
||||||
|
|
@ -1099,18 +1100,18 @@ routes:
|
||||||
createTFD()
|
createTFD()
|
||||||
resp genMain(c, genFormRegister(c), "Register - Nim Forum")
|
resp genMain(c, genFormRegister(c), "Register - Nim Forum")
|
||||||
|
|
||||||
template readIDs(): stmt =
|
template readIDs() =
|
||||||
# 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() =
|
||||||
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) =
|
||||||
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()))
|
||||||
|
|
@ -1208,6 +1209,7 @@ routes:
|
||||||
htmlgen.p("Are you sure you wish to activate ", htmlgen.b(@"nick"),
|
htmlgen.p("Are you sure you wish to activate ", htmlgen.b(@"nick"),
|
||||||
"?")
|
"?")
|
||||||
del = true
|
del = true
|
||||||
|
else: discard
|
||||||
formBody.add "<input type='hidden' name='del' value='" & $del & "'/>"
|
formBody.add "<input type='hidden' name='del' value='" & $del & "'/>"
|
||||||
content = content & htmlgen.form(action = c.req.makeUri("/dosetban"),
|
content = content & htmlgen.form(action = c.req.makeUri("/dosetban"),
|
||||||
`method` = "POST", formBody)
|
`method` = "POST", formBody)
|
||||||
|
|
@ -1373,7 +1375,7 @@ routes:
|
||||||
additionalHeaders = genRSSHeaders(c), showRssLinks = true)
|
additionalHeaders = genRSSHeaders(c), showRssLinks = true)
|
||||||
|
|
||||||
# tries first to read html, then to read rst, convert ot html, cache and return
|
# tries first to read html, then to read rst, convert ot html, cache and return
|
||||||
template textPage(path: string): stmt =
|
template textPage(path: string) =
|
||||||
createTFD()
|
createTFD()
|
||||||
#c.isThreadsList = true
|
#c.isThreadsList = true
|
||||||
var page = ""
|
var page = ""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue