Completed
Pull Request — master (#2472)
by Kevin
23:34 queued 05:01
created

delete_account_confirm.php ➔ delete_account_confirm_form()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 19
nc 2
nop 0
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
1
<?php
2
// This file is part of BOINC.
3
// https://boinc.berkeley.edu
4
// Copyright (C) 2018 University of California
5
//
6
// BOINC is free software; you can redistribute it and/or modify it
7
// under the terms of the GNU Lesser General Public License
8
// as published by the Free Software Foundation,
9
// either version 3 of the License, or (at your option) any later version.
10
//
11
// BOINC is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
// See the GNU Lesser General Public License for more details.
15
//
16
// You should have received a copy of the GNU Lesser General Public License
17
// along with BOINC.  If not, see <https://www.gnu.org/licenses/>.
18
19
require_once("../inc/util.inc");
20
require_once("../inc/account.inc");
21
require_once("../inc/delete_account.inc");
22
require_once("../inc/token.inc");
23
require_once("../inc/boinc_db.inc");
24
require_once("../inc/user_util.inc");
25
26
$config = get_config();
27
if (!parse_bool($config, "enable_delete_account")) {
28
    error_page(
29
        tra("This feature is disabled.  Please contact the project administrator.")
30
    );
31
}
32
33
function delete_account_confirm_form() {
34
    //Make sure the token is still valid
35
    $userid = get_int("id");
36
    $token = get_str("token");
37
    $retval = check_delete_account_token($userid, $token);
38
    if (!$retval) {
39
        error_page(
40
            tra("The token you used has expired or is otherwise not valid.  Please request a new one <a href=\"delete_account_request.php\">here</a>")
41
        );
42
    }
43
    
44
    page_head(tra("Delete Account"));
45
    
46
    echo "<p>".tra("Thank you for verifying ownership of your account.")."</p>"
47
         ."<p>".tra("You can now delete your account by entering in your password below and clicking the \"Delete Account\" button.")."</p>"
48
         ."<p>".tra("As a reminder, your account <b>cannot be recovered</b> once you delete it.")."</p>"
49
         ."<br/>";
50
    
51
    form_start(secure_url_base()."delete_account_confirm.php", "post");
52
    form_input_hidden("token", $token);
53
    form_input_hidden("id", $userid);
54
    form_input_text(tra("Password"), "passwd", "", "password", 'id="passwd"', passwd_visible_checkbox("passwd"));
55
    form_submit(tra("Delete Account"));
56
    form_end();
57
    
58
    page_tail();
59
}
60
61
function delete_account_confirm_action() {
62
    //Make sure the token is still valid
63
    $userid = post_int("id");
64
    $token = post_str("token");
65
    $retval = check_delete_account_token($userid, $token);
66
    if (!$retval) {
67
        error_page(
68
            tra("The token you used has expired or is otherwise not valid.  Please request a new one <a href=\"delete_account_request.php\">here</a>")
69
        );
70
    }
71
    
72
    //Verify password
73
    $user = BoincUser::lookup_id($userid);
74
    $passwd = post_str("passwd");
75
    check_passwd_ui($user, $passwd);
76
    
77
    if (!delete_account($user)) {
78
        error_page(
79
            tra("Failed to delete your account.  Please contact the project administrator.")
80
        );    
81
    }
82
    
83
    page_head(tra("Account Deleted"));
84
    
85
    echo "<p>".tra("Your account has been deleted.  If you want to contribute to ".PROJECT." in the future you will need to create a new account.")."</p>";
86
    
87
    page_tail();
88
}
89
90
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
91
    delete_account_confirm_action();
92
} else {
93
    delete_account_confirm_form();
94
}
95
96
?>