diff --git a/createdb.nim b/createdb.nim index 2d34099..13ef072 100644 --- a/createdb.nim +++ b/createdb.nim @@ -36,7 +36,7 @@ create table if not exists person( email $# not null, creation timestamp not null default (DATETIME('now')), salt varbin(128) not null, - status integer not null, + status varchar(30) not null, admin bool default false, lastOnline timestamp not null default (DATETIME('now')) );""" % [TUserName, TPassword, TEmail]), []) diff --git a/editdb.nim b/editdb.nim index ea28f93..13f77de 100644 --- a/editdb.nim +++ b/editdb.nim @@ -1,11 +1,12 @@ -import strutils, db_sqlite +import strutils, db_sqlite, ranks -var db = Open(connection="nimforum.db", user="postgres", password="", +var db = open(connection="nimforum.db", user="postgres", password="", database="nimforum") -db.exec(sql"""ALTER TABLE person add column - lastOnline timestamp -""", []) +db.exec(sql("update person set status = ?"), $User) +db.exec(sql("update person set status = ? where ban <> ''"), $Troll) +db.exec(sql("update person set status = ? where ban like '%spam%'"), $Spammer) +db.exec(sql("update person set status = ? where admin"), $Admin) -close(db) \ No newline at end of file +close(db) diff --git a/forms.tmpl b/forms.tmpl index 70bf163..862aff1 100644 --- a/forms.tmpl +++ b/forms.tmpl @@ -6,7 +6,10 @@ # # #proc genThreadsList(c: var TForumData, count: var int): string = -# const query = sql"select id, name, views, modified from thread order by modified desc limit ?, ?" +# const query = sql"""select id, name, views, modified from thread +# where id in (select thread from post where author in +# (select id from person where ban <> 'MODERATED')) +# order by modified desc limit ?, ?""" # const threadId = 0 # const name = 1 # const views = 2 @@ -113,7 +116,9 @@ # #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, -# person u where u.id = p.author and p.thread = ? order by p.id limit ?, ?""" +# person u +# where u.id = p.author and p.thread = ? and p.ban <> 'MODERATED' +# order by p.id limit ?, ?""" # const postId = 0 # const userName = 1 # const postHeader = 2 @@ -146,7 +151,7 @@ ${xmlEncode(%userName)} #if c.userId == %postAuthor and c.currentPost.subject.len == 0: