Commit 59431940 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Allow users to delete their own accounts (bug 2319)


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 6337de86
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'settings/preferences');
require(dirname(dirname(__FILE__)) . '/init.php');
define('TITLE', get_string('deleteaccount', 'account'));
require_once('pieforms/pieform.php');
if (!$USER->can_delete_self()) {
throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
$deleteform = pieform(array(
'name' => 'account_delete',
'plugintype' => 'core',
'pluginname' => 'account',
'elements' => array(
'submit' => array(
'type' => 'submit',
'value' => get_string('delete'),
),
),
));
function account_delete_submit(Pieform $form, $values) {
global $SESSION, $USER;
$userid = $USER->get('id');
$USER->logout();
delete_user($userid);
$SESSION->add_ok_msg(get_string('accountdeleted', 'account'));
redirect('/');
}
$smarty = smarty();
$smarty->assign('form', $deleteform);
$smarty->display('account/delete.tpl');
?>
......@@ -239,6 +239,7 @@ $prefsform = pieform($prefsform);
$smarty = smarty();
$smarty->assign('form', $prefsform);
$smarty->assign('candeleteself', $USER->can_delete_self());
$smarty->assign('INLINEJAVASCRIPT', "
function clearPasswords(form, data) {
formSuccess(form, data);
......
......@@ -728,6 +728,14 @@ class User {
return false;
}
public function can_delete_self() {
if (!$this->get('admin')) {
return true; // institution setting?
}
// The last admin user should not be deleted.
return count_records('usr', 'admin', 1, 'deleted', 0) > 1;
}
/**
* Makes a literal copy of a list of views for this user.
*
......
......@@ -61,4 +61,7 @@ $string['tagssideblockmaxtagsdescription'] = 'Maximum number of tags to display
$string['prefssaved'] = 'Preferences saved';
$string['prefsnotsaved'] = 'Failed to save your Preferences!';
$string['deleteaccount'] = 'Delete Account';
$string['deleteaccountdescription'] = 'If you delete your account, your profile information and your Views will no longer be visible to other users. The content of any forum posts you have written will still be visible, but the author\'s name will no longer be displayed.';
$string['accountdeleted'] = 'Your account has been deleted.';
?>
......@@ -1358,6 +1358,19 @@ form#search input.text {
#accountprefs table h3 {
border-bottom: 1px dotted #d1d1d1;
}
#deleteaccount {
border: 1px solid #e98a88;
background: #fbeceb;
padding: 1em;
margin: 0 1em 1em;
}
#deleteaccount h1 {
color: #ca0000;
}
#deleteaccount input.submit {
border: 1px solid #e98a88;
background-color: #ca0000;
}
/* Settings > Notifications */
#activitylist th {
......
{include file="header.tpl"}
<div id="deleteaccount">
<h1>{str tag=deleteaccount section=account}</h1>
<p>{str tag=deleteaccountdescription section=account}</p>
{$form}
</div>
{include file="footer.tpl"}
{include file="header.tpl"}
{if $candeleteself}<div class="rbuttons"><a href="{$WWWROOT}account/delete.php">{str tag=deleteaccount section=account}</a></div>{/if}
{$form}
{include file="footer.tpl"}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment