diff --git a/createdb.nim b/createdb.nim index 3b601ec..1566089 100644 --- a/createdb.nim +++ b/createdb.nim @@ -42,6 +42,11 @@ create table if not exists person( );""" % [TUserName, TPassword, TEmail]), []) # echo "person table already exists" +db.exec(sql(""" +alter table person +add ban varchar(128) not null default '' +""")) + db.exec(sql""" create unique index if not exists UserNameIx on person (name); """, []) diff --git a/forum.nim b/forum.nim index 839e76e..1ce63f9 100644 --- a/forum.nim +++ b/forum.nim @@ -24,6 +24,7 @@ const MaxPagesFromCurrent = 8 noPageNums = ["/login", "/register", "/dologin", "/doregister", "/profile"] noHomeBtn = ["/", "/login", "/register", "/dologin", "/doregister", "/profile"] + banReasonDeactivated = "DEACTIVATED" type TCrud = enum crCreate, crRead, crUpdate, crDelete @@ -65,6 +66,7 @@ type threads: int lastOnline: int email: string + ban: string var db: TDbConn @@ -223,11 +225,19 @@ proc devRandomSalt(): string = proc makeSalt(): string = ## Creates a salt using a cryptographically secure random number generator. + ## + ## Ensures that the resulting salt contains no ``\0``. try: result = devRandomSalt() except IOError: result = randomSalt() + var newResult = "" + for i in 0 .. " + var del = false + var content = "" + echo("Got type: ", @"type") + case @"type" + of "ban": + formBody.add "" & + "" + content = + htmlgen.p("Please enter a reason for banning this user:") + of "unban": + formBody.add "" + content = + htmlgen.p("Are you sure you wish to unban ", htmlgen.b(@"nick"), + "?") + del = true + of "deactivate": + formBody.add "" & + "" + content = + htmlgen.p("Are you sure you wish to deactivate ", htmlgen.b(@"nick"), + "?") + of "activate": + formBody.add "" + content = + htmlgen.p("Are you sure you wish to activate ", htmlgen.b(@"nick"), + "?") + del = true + formBody.add "" + content = htmlgen.form(action = c.req.makeUri("/dosetban"), + `method` = "POST", formBody) & content + resp genMain(c, content, "Set user status - Nim Forum") + + post "/dosetban": + createTFD() + cond (@"nick" != "") + if not c.isAdmin and @"nick" != c.userName: + 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") + const licenseRst = slurp("static/license.rst") get "/license": createTFD()