mirror of https://github.com/BOINC/boinc.git
web: Implement delete_account_request_action.php (verify password,
create token and send email)
This commit is contained in:
parent
2e857deefe
commit
3cac897723
|
@ -783,10 +783,11 @@ class BoincToken {
|
|||
return $db->lookup('token', 'BoincToken', $clause);
|
||||
}
|
||||
|
||||
static function lookup_valid_token($userid, $token) {
|
||||
static function lookup_valid_token($userid, $token, $type) {
|
||||
$db = BoincDb::get();
|
||||
$token = BoincDb::escape_string($token);
|
||||
return self::lookup("userid=$userid and token='$token' and expire_time > unix_timestamp()");
|
||||
$type = BoincDb::escape_string($type);
|
||||
return self::lookup("userid=$userid and token='$token' and expire_time > unix_timestamp() and type = '$type'");
|
||||
}
|
||||
|
||||
static function enum($where_clause) {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
// Don't put specific message text here.
|
||||
|
||||
require_once("../inc/util.inc");
|
||||
require_once("../inc/token.inc");
|
||||
require_once("../project/project.inc");
|
||||
|
||||
// send an email, using PHPMailer or not.
|
||||
|
@ -109,6 +110,27 @@ function is_valid_email_addr($addr) {
|
|||
return (bool) $match;
|
||||
}
|
||||
|
||||
function send_confirm_delete_email($user) {
|
||||
$token = create_confirm_delete_account_token($user);
|
||||
if ( $token == null ) {
|
||||
error_page("Error creating token. Please try again later.");
|
||||
}
|
||||
|
||||
$subject = "Confirm your request to delete your account at ".PROJECT;
|
||||
$body = "This email was sent in response to a request on the ".PROJECT." web site.
|
||||
|
||||
You have requested to delete your account at ".PROJECT.". In order to do this, use the following link to confirm your intent to delete your account. ".
|
||||
"The link will take you to a web page where you will be asked to enter your password and complete the process of deleting your account.
|
||||
|
||||
".secure_url_base()."delete_account_confirm.php?id=$user->id&token=$token
|
||||
|
||||
This link is valid for 1 day.
|
||||
|
||||
For further information and assistance with ".PROJECT.", visit ".secure_url_base();
|
||||
|
||||
return send_email($user, $subject, $body);
|
||||
}
|
||||
|
||||
function salted_key($key) {
|
||||
return md5($key.'oogabooga');
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
// This file is part of BOINC.
|
||||
// http://boinc.berkeley.edu
|
||||
// Copyright (C) 2018 University of California
|
||||
//
|
||||
// BOINC is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License
|
||||
// as published by the Free Software Foundation,
|
||||
// either version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// BOINC is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// express a time difference in readable form, e.g. "7 days ago".
|
||||
// If it's more than 30 days, just show the date
|
||||
//
|
||||
|
||||
require_once("../inc/boinc_db.inc");
|
||||
require_once("../inc/util.inc");
|
||||
|
||||
// Constants for valid token types
|
||||
define("TOKEN_TYPE_DELETE_ACCOUNT", "D");
|
||||
|
||||
// Constants for token durations
|
||||
define("TOKEN_DURATION_ONE_DAY", "86400");
|
||||
|
||||
function create_confirm_delete_account_token($user) {
|
||||
$token = random_string();
|
||||
$ret = BoincToken::insert("(token,userid,type,expire_time) values ('$token', $user->id, '".TOKEN_TYPE_DELETE_ACCOUNT."', unix_timestamp()+".TOKEN_DURATION_ONE_DAY.")");
|
||||
if ( !$ret ) {
|
||||
return null;
|
||||
}
|
||||
return $token;
|
||||
}
|
||||
|
||||
function is_valid_delete_account_token($user, $token) {
|
||||
$boincToken = BoincToken::lookup_valid_token($user->id, $token, TOKEN_TYPE_DELETE_ACCOUNT);
|
||||
if ( $boincToken == null ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -30,6 +30,23 @@ function do_passwd_rehash($user, $passwd_hash) {
|
|||
$result = $user->update(" passwd_hash='$database_passwd_hash' ");
|
||||
}
|
||||
|
||||
function check_passwd($user, $passwd) {
|
||||
$passwd_hash = md5($passwd.$user->email_addr);
|
||||
|
||||
if ( password_verify($passwd_hash, $user->passwd_hash) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($passwd_hash == $user->passwd_hash) {
|
||||
// if password is the legacy md5 hash, then rehash to update to
|
||||
// a more secure hash
|
||||
do_passwd_rehash($user, $passwd_hash);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function is_banned_email_addr($email_addr) {
|
||||
global $banned_email_domains;
|
||||
if (isset($banned_email_domains)) {
|
||||
|
|
|
@ -24,5 +24,16 @@ echo $boincToken->type . "\n";
|
|||
echo $boincToken->create_time . "\n";
|
||||
echo $boincToken->expire_time . "\n";
|
||||
|
||||
echo "---------------\n";
|
||||
$boincToken = BoincToken::lookup_valid_token(0, $token, 'T');
|
||||
if ( $boincToken != null ) {
|
||||
echo "Found valid token\n";
|
||||
}
|
||||
|
||||
echo "---------------\n";
|
||||
$boincToken = BoincToken::lookup_valid_token(0, 'notrealtoken', 'T');
|
||||
if ( $boincToken == null ) {
|
||||
echo "Successfully didn't find invalid token\n";
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -24,11 +24,11 @@ $user = get_logged_in_user();
|
|||
$config = get_config();
|
||||
if ( !parse_bool($config, "enable_delete_account") ) {
|
||||
error_page(
|
||||
tra("These feature is disabled. Please contact the project administrator.")
|
||||
tra("This feature is disabled. Please contact the project administrator.")
|
||||
);
|
||||
}
|
||||
|
||||
page_head(tra("Remove Account"));
|
||||
page_head(tra("Delete Account"));
|
||||
|
||||
echo "<p>".tra("You have the ability to delete your account. Please note that this <b>cannot be undone</b> once it is completed.")."</p>"
|
||||
."<p>".tra("The process works as follows:")."</p>"
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
// This file is part of BOINC.
|
||||
// http://boinc.berkeley.edu
|
||||
// Copyright (C) 2018 University of California
|
||||
//
|
||||
// BOINC is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License
|
||||
// as published by the Free Software Foundation,
|
||||
// either version 3 of the License, or (at your option) any later version.
|
||||
//
|
||||
// BOINC is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require_once("../inc/util.inc");
|
||||
require_once("../inc/account.inc");
|
||||
require_once("../inc/user_util.inc");
|
||||
require_once("../inc/email.inc");
|
||||
require_once("../inc/password_compat/password.inc");
|
||||
|
||||
$user = get_logged_in_user();
|
||||
|
||||
$config = get_config();
|
||||
if ( !parse_bool($config, "enable_delete_account") ) {
|
||||
error_page(
|
||||
tra("This feature is disabled. Please contact the project administrator.")
|
||||
);
|
||||
}
|
||||
|
||||
//Verify password
|
||||
$user = get_logged_in_user();
|
||||
$passwd = post_str("passwd");
|
||||
|
||||
if( !check_passwd($user, $passwd) ) {
|
||||
sleep(LOGIN_FAIL_SLEEP_SEC);
|
||||
page_head("Password incorrect");
|
||||
echo "The password you entered is incorrect. Please go back and try again.\n";
|
||||
page_tail();
|
||||
exit;
|
||||
}
|
||||
|
||||
send_confirm_delete_email($user);
|
||||
|
||||
|
||||
page_head(tra("Confirmation Email Sent"));
|
||||
|
||||
echo "<p>".tra("The email to confirm your request to delete your account has been sent.")."</p>";
|
||||
|
||||
page_tail();
|
||||
?>
|
Loading…
Reference in New Issue