forked from .cyb/cyberman
Send confirmation emails for account updates
This commit is contained in:
parent
8f5937baa5
commit
c247218613
|
@ -0,0 +1,7 @@
|
||||||
|
create table cyberman (
|
||||||
|
id integer primary key,
|
||||||
|
dbrev integer not null
|
||||||
|
);
|
||||||
|
insert into cyberman (dbrev) values (2);
|
||||||
|
|
||||||
|
alter table user add column newemail text;
|
|
@ -1,6 +1,7 @@
|
||||||
package cyberman::Account;
|
package cyberman::Account;
|
||||||
use Dancer2 appname => "cyberman";
|
use Dancer2 appname => "cyberman";
|
||||||
use Dancer2::Plugin::Database;
|
use Dancer2::Plugin::Database;
|
||||||
|
use URI::Escape;
|
||||||
|
|
||||||
use cyberman::Helper;
|
use cyberman::Helper;
|
||||||
|
|
||||||
|
@ -73,8 +74,7 @@ post '/account' => sub {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param("email") ne $user->{"email"}) {
|
if (param("email") ne $user->{"email"}) {
|
||||||
|
my $conftoken = randstring(16);
|
||||||
# TODO: verify email address here
|
|
||||||
|
|
||||||
database->quick_update (
|
database->quick_update (
|
||||||
"user",
|
"user",
|
||||||
|
@ -82,9 +82,18 @@ post '/account' => sub {
|
||||||
"id" => vars->{"auth"},
|
"id" => vars->{"auth"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"email" => param "email",
|
"newemail" => param("email"),
|
||||||
|
"conftoken" => $conftoken,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
my $email = template 'email/update' => {
|
||||||
|
"link" => config->{"mail"}->{"baseurl"} . "/confirm_update?o=" . uri_escape($user->{"email"}) . "&n=" . uri_escape(param "email") . "&t=$conftoken",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"layout" => undef,
|
||||||
|
};
|
||||||
|
send_email(param("email"), $email);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($new_pass) {
|
if ($new_pass) {
|
||||||
|
@ -125,4 +134,31 @@ post '/account' => sub {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
get '/confirm_update' => sub {
|
||||||
|
my $user = database->quick_select(
|
||||||
|
"user",
|
||||||
|
{
|
||||||
|
"email" => param("o"),
|
||||||
|
"newemail" => param("n"),
|
||||||
|
"conftoken" => param("t"),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$user) {
|
||||||
|
return "No such user/token!";
|
||||||
|
}
|
||||||
|
|
||||||
|
database->quick_update(
|
||||||
|
"user",
|
||||||
|
{
|
||||||
|
"id" => $user->{"id"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"email" => param("n"),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
template 'confirmed';
|
||||||
|
};
|
||||||
|
|
||||||
true;
|
true;
|
||||||
|
|
10
schema.sql
10
schema.sql
|
@ -1,3 +1,10 @@
|
||||||
|
drop table if exists cyberman;
|
||||||
|
create table cyberman (
|
||||||
|
id integer primary key,
|
||||||
|
dbrev integer not null
|
||||||
|
);
|
||||||
|
insert into cyberman (dbrev) values (2);
|
||||||
|
|
||||||
drop table if exists user;
|
drop table if exists user;
|
||||||
create table user (
|
create table user (
|
||||||
id integer primary key,
|
id integer primary key,
|
||||||
|
@ -5,7 +12,8 @@ create table user (
|
||||||
password text not null,
|
password text not null,
|
||||||
salt text not null,
|
salt text not null,
|
||||||
active integer not null default 0,
|
active integer not null default 0,
|
||||||
conftoken text not null
|
conftoken text not null,
|
||||||
|
newemail text
|
||||||
);
|
);
|
||||||
|
|
||||||
drop table if exists session;
|
drop table if exists session;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<br />
|
<br />
|
||||||
<% IF updated %>
|
<% IF updated %>
|
||||||
<div class="msgBox">
|
<div class="msgBox">
|
||||||
Your account details were updated successfully.
|
Your account details were updated successfully. If you updated your email address, you need to click the link sent to you before the changes can be applied.
|
||||||
</div>
|
</div>
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<% END %>
|
<% END %>
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
Hello!
|
||||||
|
|
||||||
|
You're receiving this email because someone entered your email address into cybNIC.
|
||||||
|
|
||||||
|
If this was you and you'd like to use this address, please click this link:
|
||||||
|
<% link %>
|
||||||
|
|
||||||
|
Otherwise, feel free to ignore this email.
|
Loading…
Reference in New Issue