new version compiles; still unfinished
This commit is contained in:
parent
30ed9e2076
commit
ca06f4e988
2 changed files with 69 additions and 103 deletions
35
forms.tmpl
35
forms.tmpl
|
|
@ -6,9 +6,11 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#proc genThreadsList(c: var TForumData, count: var int): string =
|
#proc genThreadsList(c: var TForumData, count: var int): string =
|
||||||
|
# const queryAdmin = sql"""select id, name, views, modified from thread
|
||||||
|
# order by modified desc limit ?, ?"""
|
||||||
# const query = sql"""select id, name, views, modified from thread
|
# const query = sql"""select id, name, views, modified from thread
|
||||||
# where id in (select thread from post where author in
|
# where id in (select thread from post where author in
|
||||||
# (select id from person where ban <> 'MODERATED'))
|
# (select id from person where status <> 'MODERATED'))
|
||||||
# order by modified desc limit ?, ?"""
|
# order by modified desc limit ?, ?"""
|
||||||
# const threadId = 0
|
# const threadId = 0
|
||||||
# const name = 1
|
# const name = 1
|
||||||
|
|
@ -37,7 +39,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="talk-threads">
|
<div id="talk-threads">
|
||||||
# for row in rows(db, query, $((c.pageNum-1) * ThreadsPerPage), $ThreadsPerPage):
|
# for row in rows(db, if c.rank >= Moderator: queryAdmin else: query,
|
||||||
|
# $((c.pageNum-1) * ThreadsPerPage), $ThreadsPerPage):
|
||||||
# inc(count)
|
# inc(count)
|
||||||
<div>
|
<div>
|
||||||
<div class="topic">
|
<div class="topic">
|
||||||
|
|
@ -115,10 +118,11 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#proc genPostsList(c: var TForumData, threadId: string, count: var int): string =
|
#proc genPostsList(c: var TForumData, threadId: string, count: var int): string =
|
||||||
# const query = sql"""select p.id, u.name, p.header, p.content, p.creation, p.author, u.email from post p,
|
# let query = sql("""select p.id, u.name, p.header, p.content, p.creation, p.author, u.email from post p,
|
||||||
# person u
|
# person u
|
||||||
# where u.id = p.author and p.thread = ? and p.ban <> 'MODERATED'
|
# where u.id = p.author and p.thread = ? $#
|
||||||
# order by p.id limit ?, ?"""
|
# order by p.id limit ?, ?""" %
|
||||||
|
# (if c.rank >= Moderator: "" else: "and p.status <> 'MODERATED'"))
|
||||||
# const postId = 0
|
# const postId = 0
|
||||||
# const userName = 1
|
# const userName = 1
|
||||||
# const postHeader = 2
|
# const postHeader = 2
|
||||||
|
|
@ -256,6 +260,27 @@
|
||||||
</form>
|
</form>
|
||||||
#end proc
|
#end proc
|
||||||
#
|
#
|
||||||
|
#proc genFormSetRank(c: var TForumData; ui: TUserInfo): string =
|
||||||
|
# result = ""
|
||||||
|
<form action="${c.req.makeUri("/dosetrank/" & ui.nick, false)}" method="POST">
|
||||||
|
<table border="0">
|
||||||
|
<tr>
|
||||||
|
<th>Reason</th>
|
||||||
|
<td>${textWidget(c, "reason", ui.ban, maxlength=100)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Rank</th>
|
||||||
|
<td><select name = "rank">
|
||||||
|
# for i in low(Rank)..high(Rank):
|
||||||
|
<option ${if i == ui.rank: "selected" else: ""}>
|
||||||
|
$i
|
||||||
|
</option>
|
||||||
|
# end for
|
||||||
|
</td></select>
|
||||||
|
</tr>
|
||||||
|
</form>
|
||||||
|
#end proc
|
||||||
|
#
|
||||||
#proc genFormLogin(c: var TForumData): string =
|
#proc genFormLogin(c: var TForumData): string =
|
||||||
# result = ""
|
# result = ""
|
||||||
# if not c.loggedIn:
|
# if not c.loggedIn:
|
||||||
|
|
|
||||||
137
forum.nim
137
forum.nim
|
|
@ -345,7 +345,7 @@ proc register(c: var TForumData, name, pass, antibot,
|
||||||
sql("INSERT INTO person(name, password, email, salt, status, lastOnline) " &
|
sql("INSERT INTO person(name, password, email, salt, status, lastOnline) " &
|
||||||
"VALUES (?, ?, ?, ?, ?, DATETIME('now'))"), name,
|
"VALUES (?, ?, ?, ?, ?, DATETIME('now'))"), name,
|
||||||
password, email, salt,
|
password, email, salt,
|
||||||
when defined(dev): $User else: $EmailUnconfirmed)
|
when defined(dev): $Moderated else: $EmailUnconfirmed)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
@ -706,15 +706,11 @@ proc verifyIdentHash(c: var TForumData, name, epoch, ident: string): bool =
|
||||||
if row[2].parseInt > (epoch.parseInt + 60): return false
|
if row[2].parseInt > (epoch.parseInt + 60): return false
|
||||||
result = newIdent == ident
|
result = newIdent == ident
|
||||||
|
|
||||||
proc setBan(c: var TForumData, nick, reason: string): bool =
|
proc setStatus(c: var TForumData, nick: string, status: Rank;
|
||||||
|
reason: string): bool =
|
||||||
const query =
|
const query =
|
||||||
sql("update person set ban = ? where name = ?")
|
sql("update person set status = ?, ban = ? where name = ?")
|
||||||
return tryExec(db, query, reason, nick)
|
return tryExec(db, query, $status, reason, nick)
|
||||||
|
|
||||||
proc setStatus(c: var TForumData, nick: string, status: Rank): bool =
|
|
||||||
const query =
|
|
||||||
sql("update person set status = ? where name = ?")
|
|
||||||
return tryExec(db, query, $status, nick)
|
|
||||||
|
|
||||||
proc deleteAll(c: var TForumData, nick: string): bool =
|
proc deleteAll(c: var TForumData, nick: string): bool =
|
||||||
const query =
|
const query =
|
||||||
|
|
@ -758,9 +754,9 @@ proc getStats(c: var TForumData, simple: bool): TForumStats =
|
||||||
let lastOnlineSeconds = getTime() - Time(secs)
|
let lastOnlineSeconds = getTime() - Time(secs)
|
||||||
if lastOnlineSeconds < (60 * 5): # 5 minutes
|
if lastOnlineSeconds < (60 * 5): # 5 minutes
|
||||||
result.activeUsers.add((row[1], row[0].parseInt))
|
result.activeUsers.add((row[1], row[0].parseInt))
|
||||||
if row[4].parseInt > newestMemberCreation:
|
if row[3].parseInt > newestMemberCreation:
|
||||||
result.newestMember = (row[1], row[0].parseInt)
|
result.newestMember = (row[1], row[0].parseInt)
|
||||||
newestMemberCreation = row[4].parseInt
|
newestMemberCreation = row[3].parseInt
|
||||||
|
|
||||||
proc genPagenumNav(c: var TForumData, stats: TForumStats): string =
|
proc genPagenumNav(c: var TForumData, stats: TForumStats): string =
|
||||||
result = ""
|
result = ""
|
||||||
|
|
@ -895,14 +891,14 @@ proc gatherUserInfo(c: var TForumData, nick: string, ui: var TUserInfo): bool =
|
||||||
const lastOnlineQuery =
|
const lastOnlineQuery =
|
||||||
sql"""select strftime('%s', lastOnline), email, ban, status
|
sql"""select strftime('%s', lastOnline), email, ban, status
|
||||||
from person where id = ?"""
|
from person where id = ?"""
|
||||||
let row = db.getRow lastOnlineQuery
|
let row = db.getRow(lastOnlineQuery, $uid)
|
||||||
ui.lastOnline = if row[0].len > 0: row[0].parseInt else: -1
|
ui.lastOnline = if row[0].len > 0: row[0].parseInt else: -1
|
||||||
ui.email = row[1]
|
ui.email = row[1]
|
||||||
ui.ban = row[2]
|
ui.ban = row[2]
|
||||||
ui.rank = parseEnum[Rank](row[3])
|
ui.rank = parseEnum[Rank](row[3])
|
||||||
|
|
||||||
proc genSetUserStatusUrl(c: var TForumData, nick: string, typ: string): string =
|
include "forms.tmpl"
|
||||||
c.req.makeUri("/setUserStatus?nick=$1&type=$2" % [nick, typ])
|
include "main.tmpl"
|
||||||
|
|
||||||
proc genProfile(c: var TForumData, ui: TUserInfo): string =
|
proc genProfile(c: var TForumData, ui: TUserInfo): string =
|
||||||
result = ""
|
result = ""
|
||||||
|
|
@ -948,28 +944,7 @@ proc genProfile(c: var TForumData, ui: TUserInfo): string =
|
||||||
tr(
|
tr(
|
||||||
th(""),
|
th(""),
|
||||||
td(if c.rank >= Moderator and c.rank > ui.rank:
|
td(if c.rank >= Moderator and c.rank > ui.rank:
|
||||||
if ui.rank >= EmailUnconfirmed:
|
c.genFormSetRank(ui)
|
||||||
htmlgen.a(
|
|
||||||
href=c.genSetUserStatusUrl(ui.nick, "ban"),
|
|
||||||
"Ban user")
|
|
||||||
else:
|
|
||||||
htmlgen.a(href=c.genSetUserStatusUrl(ui.nick, "unban"),
|
|
||||||
"Unban user")
|
|
||||||
else: "")
|
|
||||||
),
|
|
||||||
tr(
|
|
||||||
th(""),
|
|
||||||
td(if c.rank >= Moderator and c.rank > ui.rank:
|
|
||||||
if ui.rank == EmailUnconfirmed:
|
|
||||||
htmlgen.a(href=c.genSetUserStatusUrl(ui.nick, "activate"),
|
|
||||||
"Confirm user's email")
|
|
||||||
elif ui.rank > Moderated:
|
|
||||||
htmlgen.a(href=c.genSetUserStatusUrl(ui.nick, "deactivate"),
|
|
||||||
"Deactivate user")
|
|
||||||
elif ui.rank <= Moderated:
|
|
||||||
htmlgen.a(href=c.genSetUserStatusUrl(ui.nick, "activate"),
|
|
||||||
"Activate user")
|
|
||||||
else: ""
|
|
||||||
else: "")
|
else: "")
|
||||||
),
|
),
|
||||||
tr(
|
tr(
|
||||||
|
|
@ -985,9 +960,6 @@ proc genProfile(c: var TForumData, ui: TUserInfo): string =
|
||||||
result = htmlgen.`div`(id = "profile",
|
result = htmlgen.`div`(id = "profile",
|
||||||
htmlgen.`div`(id = "left", result))
|
htmlgen.`div`(id = "left", result))
|
||||||
|
|
||||||
include "forms.tmpl"
|
|
||||||
include "main.tmpl"
|
|
||||||
|
|
||||||
proc prependRe(s: string): string =
|
proc prependRe(s: string): string =
|
||||||
result = if s.len == 0:
|
result = if s.len == 0:
|
||||||
""
|
""
|
||||||
|
|
@ -1179,64 +1151,6 @@ routes:
|
||||||
resp genMain(c, genFormPost(c, "donewthread", "New thread", "", "", false),
|
resp genMain(c, genFormPost(c, "donewthread", "New thread", "", "", false),
|
||||||
"New Thread - Nim Forum")
|
"New Thread - Nim Forum")
|
||||||
|
|
||||||
get "/setUserStatus/?":
|
|
||||||
createTFD()
|
|
||||||
cond(@"nick" != "")
|
|
||||||
cond(@"type" != "")
|
|
||||||
var formBody = "<input type=\"hidden\" name=\"nick\" value=\"" &
|
|
||||||
@"nick" & "\">"
|
|
||||||
var del = false
|
|
||||||
var content = ""
|
|
||||||
echo("Got type: ", @"type")
|
|
||||||
case @"type"
|
|
||||||
of "ban":
|
|
||||||
formBody.add "<input type='text' name='reason' />" &
|
|
||||||
"<input type='submit' name='banBtn' value='Ban' />"
|
|
||||||
content =
|
|
||||||
htmlgen.p("Please enter a reason for banning this user:")
|
|
||||||
of "unban":
|
|
||||||
formBody.add "<input type='submit' name='unbanBtn' value='Unban' />"
|
|
||||||
content =
|
|
||||||
htmlgen.p("Are you sure you wish to unban ", htmlgen.b(@"nick"),
|
|
||||||
"?")
|
|
||||||
del = true
|
|
||||||
of "deactivate":
|
|
||||||
formBody.add "<input type='submit' name='actBtn' value='Deactivate' />"
|
|
||||||
content =
|
|
||||||
htmlgen.p("Are you sure you wish to deactivate ", htmlgen.b(@"nick"),
|
|
||||||
"?")
|
|
||||||
of "activate":
|
|
||||||
formBody.add "<input type='submit' name='actBtn' value='Activate' />"
|
|
||||||
content =
|
|
||||||
htmlgen.p("Are you sure you wish to activate ", htmlgen.b(@"nick"),
|
|
||||||
"?")
|
|
||||||
del = true
|
|
||||||
else: discard
|
|
||||||
formBody.add "<input type='hidden' name='del' value='" & $del & "'/>"
|
|
||||||
content = content & htmlgen.form(action = c.req.makeUri("/dosetban"),
|
|
||||||
`method` = "POST", formBody)
|
|
||||||
resp genMain(c, content, "Set user status - Nim Forum")
|
|
||||||
|
|
||||||
post "/dosetban":
|
|
||||||
createTFD()
|
|
||||||
cond(@"nick" != "")
|
|
||||||
if c.rank < Moderator:
|
|
||||||
resp genMain(c, "You cannot ban this user.", "Error - Nim Forum")
|
|
||||||
if @"reason" == "" and @"del" != "true":
|
|
||||||
resp genMain(c, "Invalid ban reason.", "Error - Nim Forum")
|
|
||||||
|
|
||||||
let result =
|
|
||||||
if @"del" == "true":
|
|
||||||
# Remove the ban.
|
|
||||||
setBan(c, @"nick", "")
|
|
||||||
else:
|
|
||||||
setBan(c, @"nick", @"reason")
|
|
||||||
if result:
|
|
||||||
redirect(c.req.makeUri("/profile/" & @"nick"))
|
|
||||||
else:
|
|
||||||
resp genMain(c, "Failed to change the ban status of user.",
|
|
||||||
"Error - Nim Forum")
|
|
||||||
|
|
||||||
get "/deleteAll/?":
|
get "/deleteAll/?":
|
||||||
createTFD()
|
createTFD()
|
||||||
cond(@"nick" != "")
|
cond(@"nick" != "")
|
||||||
|
|
@ -1263,6 +1177,33 @@ routes:
|
||||||
resp genMain(c, "Failed to delete all user's posts and threads.",
|
resp genMain(c, "Failed to delete all user's posts and threads.",
|
||||||
"Error - NimForum")
|
"Error - NimForum")
|
||||||
|
|
||||||
|
post "/dosetrank/?":
|
||||||
|
createTFD()
|
||||||
|
cond(@"nick" != "")
|
||||||
|
|
||||||
|
if c.rank < Moderator:
|
||||||
|
resp genMain(c, "You cannot change this user's rank.", "Error - Nim Forum")
|
||||||
|
|
||||||
|
var ui: TUserInfo
|
||||||
|
if not gatherUserInfo(c, @"nick", ui):
|
||||||
|
resp genMain(c, "User " & @"nick" & " does not exist.", "Error - Nim Forum")
|
||||||
|
#elif ui.
|
||||||
|
# XXX check that moderator can make themselves admins
|
||||||
|
echo(@"rank")
|
||||||
|
echo(@"reason")
|
||||||
|
when false:
|
||||||
|
let result =
|
||||||
|
if @"del" == "true":
|
||||||
|
# Remove the ban.
|
||||||
|
setBan(c, @"nick", "")
|
||||||
|
else:
|
||||||
|
setBan(c, @"nick", @"reason")
|
||||||
|
if result:
|
||||||
|
redirect(c.req.makeUri("/profile/" & @"nick"))
|
||||||
|
else:
|
||||||
|
resp genMain(c, "Failed to change the ban status of user.",
|
||||||
|
"Error - Nim Forum")
|
||||||
|
|
||||||
get "/setpassword/?":
|
get "/setpassword/?":
|
||||||
createTFD()
|
createTFD()
|
||||||
cond(@"nick" != "")
|
cond(@"nick" != "")
|
||||||
|
|
@ -1286,7 +1227,7 @@ routes:
|
||||||
if verifyIdentHash(c, @"nick", $epoch, @"ident"):
|
if verifyIdentHash(c, @"nick", $epoch, @"ident"):
|
||||||
let ban = parseEnum[Rank](db.getValue(sql"select status from person where name = ?", @"nick"))
|
let ban = parseEnum[Rank](db.getValue(sql"select status from person where name = ?", @"nick"))
|
||||||
if ban == EmailUnconfirmed:
|
if ban == EmailUnconfirmed:
|
||||||
success = setStatus(c, @"nick", Moderated)
|
success = setStatus(c, @"nick", Moderated, "")
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
resp genMain(c, "Account activated", "Nim Forum")
|
resp genMain(c, "Account activated", "Nim Forum")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue