From ecff4ac48ed07fea3e39f6f7cc62a6f8fff09b29 Mon Sep 17 00:00:00 2001 From: Al Beano Date: Tue, 18 Jul 2017 13:51:30 +0100 Subject: [PATCH] Check for duplicate email addresses --- lib/cyberman/Account.pm | 13 +++++++++++++ lib/cyberman/Auth.pm | 11 +++++++++++ views/account.tt | 4 ++++ views/register.tt | 3 +++ 4 files changed, 31 insertions(+) diff --git a/lib/cyberman/Account.pm b/lib/cyberman/Account.pm index abfef5c..b974028 100644 --- a/lib/cyberman/Account.pm +++ b/lib/cyberman/Account.pm @@ -36,6 +36,19 @@ post '/account' => sub { $errs{"e_no_email"} = 1; } + if (param("email") ne $user->{"email"}) { + my $result = database->quick_select ( + "user", + { + "email" => param("email"), + }, + ); + + if ($result) { + $errs{"e_email_exists"} = 1; + } + } + if (param("password") || param("npassword") || param("npassword2")) { $new_pass = 1; diff --git a/lib/cyberman/Auth.pm b/lib/cyberman/Auth.pm index f447858..797cad7 100644 --- a/lib/cyberman/Auth.pm +++ b/lib/cyberman/Auth.pm @@ -17,6 +17,17 @@ post '/register' => sub { } } + my $result = database->quick_select( + "user", + { + "email" => param("email"), + }, + ); + + if ($result) { + $errs{"e_email_exists"} = 1; + } + if (!exists $errs{"e_no_password"} || !exists $errs{"e_no_password2"}) { if (param("password") ne param("password2")) { $errs{"e_pass_match"} = 1; diff --git a/views/account.tt b/views/account.tt index 8442663..d3b523d 100644 --- a/views/account.tt +++ b/views/account.tt @@ -28,9 +28,13 @@ <% IF e_pass_len %>
  • Your password must be at least 8 characters long.
  • <% END %> + <% IF e_email_exists %> +
  • There is already an account with that email address.
  • + <% END %> +
    <% END %>
    diff --git a/views/register.tt b/views/register.tt index acddf3f..c77c744 100644 --- a/views/register.tt +++ b/views/register.tt @@ -25,6 +25,9 @@ <% IF e_pass_match %>
  • The two passwords you entered do not match!
  • <% END %> + <% IF e_email_exists %> +
  • There is already an account with that email address.
  • + <% END %>