From c6b42c5979f32397f6ab1eadc89385749df487d9 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Wed, 16 May 2018 14:49:59 +0100 Subject: [PATCH] Prevent registration with duplicate emails. --- forum.nim | 14 +++++++++----- redesign/nimforum.scss | 5 +++++ redesign/threadlist.nim | 13 +++++++++---- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/forum.nim b/forum.nim index c55f074..85fd345 100644 --- a/forum.nim +++ b/forum.nim @@ -1099,6 +1099,14 @@ proc executeRegister(c: TForumData, name, pass, antibot, userIp, ## Registers a new user and returns a new session key for that user's ## session if registration was successful. Exceptions are raised otherwise. + # email validation + if not ('@' in email and '.' in email): + raise newForumError("Invalid email", @["email"]) + if getValue( + db, sql"select email from person where email = ?", email + ).len > 0: + raise newForumError("Email already exists", @["email"]) + # Username validation: if name.len == 0 or not allCharsInSet(name, UsernameIdent): raise newForumError("Invalid username", @["username"]) @@ -1118,10 +1126,6 @@ proc executeRegister(c: TForumData, name, pass, antibot, userIp, "Invalid recaptcha answer", @[] ) - # email validation - if not ('@' in email and '.' in email): - raise newForumError("Invalid email", @["email"]) - # perform registration: var salt = makeSalt() let password = makePassword(pass, salt) @@ -1142,7 +1146,7 @@ proc executeRegister(c: TForumData, name, pass, antibot, userIp, exec(db, sql("INSERT INTO person(name, password, email, salt, status, lastOnline) " & "VALUES (?, ?, ?, ?, ?, DATETIME('now'))"), name, - password, email, salt, $Moderated) + password, email, salt, $EmailUnconfirmed) return password diff --git a/redesign/nimforum.scss b/redesign/nimforum.scss index cc823b5..45b8018 100644 --- a/redesign/nimforum.scss +++ b/redesign/nimforum.scss @@ -144,6 +144,11 @@ $logo-height: $navbar-height - 20px; a.visited { color: lighten($body-font-color, 40%); } + + i { + // Icon + margin-right: $control-padding-x-sm; + } } $super-popular-color: #f86713; diff --git a/redesign/threadlist.nim b/redesign/threadlist.nim index 7036fe6..dbc1dac 100644 --- a/redesign/threadlist.nim +++ b/redesign/threadlist.nim @@ -100,12 +100,17 @@ when defined(js): tr(class=class({"no-border": noBorder})): td(class="thread-title"): if thread.isLocked: - italic(class="fas fa-lock fa-xs") + italic(class="fas fa-lock fa-xs", + title="Thread cannot be replied to") if thread.isInvisible: - italic(class="fas fa-eye-slash fa-xs") + italic(class="fas fa-eye-slash fa-xs", + title="Thread is moderated") if thread.isSolved: - italic(class="fas fa-check-square fa-xs") - a(href=makeUri("/t/" & $thread.id), onClick=anchorCB): text thread.topic + italic(class="fas fa-check-square fa-xs", + title="Thread has a solution") + a(href=makeUri("/t/" & $thread.id), + onClick=anchorCB): + text thread.topic td(): render(thread.category) genUserAvatars(thread.users)