get rid of most deprecation warnings

This commit is contained in:
Araq 2016-12-31 11:59:03 +01:00
commit a6fdd16893
4 changed files with 50 additions and 50 deletions

View file

@ -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

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: 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")

View file

@ -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

View file

@ -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
@ -1031,7 +1032,7 @@ routes:
parseInt(@"page", c.pageNum, 0..1000_000) parseInt(@"page", c.pageNum, 0..1000_000)
if @"postid".len > 0: if @"postid".len > 0:
parseInt(@"postid", c.postId, 0..1000_000) parseInt(@"postid", c.postId, 0..1000_000)
cond (c.pageNum > 0) cond(c.pageNum > 0)
var count = 0 var count = 0
var pSubject = getThreadTitle(c.threadid, c.pageNum) var pSubject = getThreadTitle(c.threadid, c.pageNum)
cond validThreadId(c) cond validThreadId(c)
@ -1066,9 +1067,9 @@ routes:
get "/page/?@page?/?": get "/page/?@page?/?":
createTFD() createTFD()
c.isThreadsList = true c.isThreadsList = true
cond (@"page" != "") cond(@"page" != "")
parseInt(@"page", c.pageNum, 0..1000_000) parseInt(@"page", c.pageNum, 0..1000_000)
cond (c.pageNum > 0) cond(c.pageNum > 0)
var count = 0 var count = 0
let list = genThreadsList(c, count) let list = genThreadsList(c, count)
if count == 0: if count == 0:
@ -1078,7 +1079,7 @@ routes:
get "/profile/@nick/?": get "/profile/@nick/?":
createTFD() createTFD()
cond (@"nick" != "") cond(@"nick" != "")
var userinfo: TUserInfo var userinfo: TUserInfo
if gatherUserInfo(c, @"nick", userinfo): if gatherUserInfo(c, @"nick", userinfo):
resp genMain(c, c.genProfile(userinfo), resp genMain(c, c.genProfile(userinfo),
@ -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()))
@ -1176,8 +1177,8 @@ routes:
get "/setUserStatus/?": get "/setUserStatus/?":
createTFD() createTFD()
cond (@"nick" != "") cond(@"nick" != "")
cond (@"type" != "") cond(@"type" != "")
var formBody = "<input type=\"hidden\" name=\"nick\" value=\"" & var formBody = "<input type=\"hidden\" name=\"nick\" value=\"" &
@"nick" & "\">" @"nick" & "\">"
var del = false var del = false
@ -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)
@ -1215,7 +1217,7 @@ routes:
post "/dosetban": post "/dosetban":
createTFD() createTFD()
cond (@"nick" != "") cond(@"nick" != "")
if not c.isAdmin and @"nick" != c.userName: if not c.isAdmin and @"nick" != c.userName:
resp genMain(c, "You cannot ban this user.", "Error - Nim Forum") resp genMain(c, "You cannot ban this user.", "Error - Nim Forum")
if @"reason" == "" and @"del" != "true": if @"reason" == "" and @"del" != "true":
@ -1234,7 +1236,7 @@ routes:
get "/deleteAll/?": get "/deleteAll/?":
createTFD() createTFD()
cond (@"nick" != "") cond(@"nick" != "")
var formBody = "<input type=\"hidden\" name=\"nick\" value=\"" & var formBody = "<input type=\"hidden\" name=\"nick\" value=\"" &
@"nick" & "\">" @"nick" & "\">"
var del = false var del = false
@ -1248,7 +1250,7 @@ routes:
post "/dodeleteall/?": post "/dodeleteall/?":
createTFD() createTFD()
cond (@"nick" != "") cond(@"nick" != "")
if not c.isAdmin: if not c.isAdmin:
resp genMain(c, "You cannot delete this user's data.", "Error - Nim Forum") resp genMain(c, "You cannot delete this user's data.", "Error - Nim Forum")
let result = deleteAll(c, @"nick") let result = deleteAll(c, @"nick")
@ -1260,8 +1262,8 @@ routes:
get "/setpassword/?": get "/setpassword/?":
createTFD() createTFD()
cond (@"nick" != "") cond(@"nick" != "")
cond (@"pass" != "") cond(@"pass" != "")
if not c.isAdmin: if not c.isAdmin:
resp genMain(c, "You cannot change this user's pass.", "Error - Nim Forum") resp genMain(c, "You cannot change this user's pass.", "Error - Nim Forum")
let res = setPassword(c, @"nick", @"pass") let res = setPassword(c, @"nick", @"pass")
@ -1272,9 +1274,9 @@ routes:
get "/activateEmail/?": get "/activateEmail/?":
createTFD() createTFD()
cond (@"nick" != "") cond(@"nick" != "")
cond (@"epoch" != "") cond(@"epoch" != "")
cond (@"ident" != "") cond(@"ident" != "")
var epoch: BiggestInt = 0 var epoch: BiggestInt = 0
cond(parseBiggestInt(@"epoch", epoch) > 0) cond(parseBiggestInt(@"epoch", epoch) > 0)
var success = false var success = false
@ -1290,9 +1292,9 @@ routes:
get "/emailResetPassword/?": get "/emailResetPassword/?":
createTFD() createTFD()
cond (@"nick" != "") cond(@"nick" != "")
cond (@"epoch" != "") cond(@"epoch" != "")
cond (@"ident" != "") cond(@"ident" != "")
var epoch: BiggestInt = 0 var epoch: BiggestInt = 0
cond(parseBiggestInt(@"epoch", epoch) > 0) cond(parseBiggestInt(@"epoch", epoch) > 0)
if verifyIdentHash(c, @"nick", $epoch, @"ident"): if verifyIdentHash(c, @"nick", $epoch, @"ident"):
@ -1314,10 +1316,10 @@ routes:
post "/doemailresetpassword": post "/doemailresetpassword":
createTFD() createTFD()
cond (@"nick" != "") cond(@"nick" != "")
cond (@"epoch" != "") cond(@"epoch" != "")
cond (@"ident" != "") cond(@"ident" != "")
cond (@"password" != "") cond(@"password" != "")
var epoch: BiggestInt = 0 var epoch: BiggestInt = 0
cond(parseBiggestInt(@"epoch", epoch) > 0) cond(parseBiggestInt(@"epoch", epoch) > 0)
if verifyIdentHash(c, @"nick", $epoch, @"ident"): if verifyIdentHash(c, @"nick", $epoch, @"ident"):
@ -1337,7 +1339,7 @@ routes:
post "/doresetpassword": post "/doresetpassword":
createTFD() createTFD()
echo(request.params) echo(request.params)
cond (@"nick" != "") cond(@"nick" != "")
if resetPassword(c, @"nick", @"antibot"): if resetPassword(c, @"nick", @"antibot"):
resp genMain(c, "Email sent!", "Reset Password - Nim Forum") resp genMain(c, "Email sent!", "Reset Password - Nim Forum")
@ -1362,7 +1364,7 @@ routes:
c.search = q.replace("\"","&quot;"); c.search = q.replace("\"","&quot;");
if @"page".len > 0: if @"page".len > 0:
parseInt(@"page", c.pageNum, 0..1000_000) parseInt(@"page", c.pageNum, 0..1000_000)
cond (c.pageNum > 0) cond(c.pageNum > 0)
iterator searchResults(): db_sqlite.TRow {.closure, tags: [FReadDB].} = iterator searchResults(): db_sqlite.TRow {.closure, tags: [FReadDB].} =
const queryFT = "fts.sql".slurp.sql const queryFT = "fts.sql".slurp.sql
for rowFT in fastRows(db, queryFT, for rowFT in fastRows(db, queryFT,
@ -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 = ""