don't use admin field in db anymore

This commit is contained in:
Araq 2017-01-01 21:00:37 +01:00
commit 30ed9e2076
3 changed files with 8 additions and 8 deletions

View file

@ -37,7 +37,6 @@ create table if not exists person(
creation timestamp not null default (DATETIME('now')), creation timestamp not null default (DATETIME('now')),
salt varbin(128) not null, salt varbin(128) not null,
status varchar(30) not null, status varchar(30) not null,
admin bool default false,
lastOnline timestamp not null default (DATETIME('now')) lastOnline timestamp not null default (DATETIME('now'))
);""" % [TUserName, TPassword, TEmail]), []) );""" % [TUserName, TPassword, TEmail]), [])
# echo "person table already exists" # echo "person table already exists"

View file

@ -7,6 +7,7 @@ var db = open(connection="nimforum.db", user="postgres", password="",
db.exec(sql("update person set status = ?"), $User) 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 <> ''"), $Troll)
db.exec(sql("update person set status = ? where ban like '%spam%'"), $Spammer) db.exec(sql("update person set status = ? where ban like '%spam%'"), $Spammer)
db.exec(sql("update person set status = ? where admin"), $Admin) db.exec(sql("update person set status = ? where ban = 'DEACTIVATED' or ban = 'EMAILCONFIRMATION'"), $Inactive)
db.exec(sql("update person set status = ? where admin = 'true'"), $Admin)
close(db) close(db)

View file

@ -58,8 +58,8 @@ type
totalUsers: int totalUsers: int
totalPosts: int totalPosts: int
totalThreads: int totalThreads: int
newestMember: tuple[nick: string, id: int, isAdmin: bool] newestMember: tuple[nick: string, id: int]
activeUsers: seq[tuple[nick: string, id: int, isAdmin: bool]] activeUsers: seq[tuple[nick: string, id: int]]
TUserInfo = object TUserInfo = object
nick: string nick: string
@ -750,16 +750,16 @@ proc getStats(c: var TForumData, simple: bool): TForumStats =
if not simple: if not simple:
var newestMemberCreation = 0 var newestMemberCreation = 0
result.activeUsers = @[] result.activeUsers = @[]
result.newestMember = ("", -1, false) result.newestMember = ("", -1)
const getUsersQuery = const getUsersQuery =
sql"select id, name, admin, strftime('%s', lastOnline), strftime('%s', creation) from person" sql"select id, name, strftime('%s', lastOnline), strftime('%s', creation) from person"
for row in fastRows(db, getUsersQuery): for row in fastRows(db, getUsersQuery):
let secs = if row[3] == "": 0 else: row[3].parseint let secs = if row[3] == "": 0 else: row[3].parseint
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, row[2].parseBool)) result.activeUsers.add((row[1], row[0].parseInt))
if row[4].parseInt > newestMemberCreation: if row[4].parseInt > newestMemberCreation:
result.newestMember = (row[1], row[0].parseInt, row[2].parseBool) result.newestMember = (row[1], row[0].parseInt)
newestMemberCreation = row[4].parseInt newestMemberCreation = row[4].parseInt
proc genPagenumNav(c: var TForumData, stats: TForumStats): string = proc genPagenumNav(c: var TForumData, stats: TForumStats): string =