2016-04-19 03:38:38 +00:00
< ? php
namespace Zotlabs\Module ;
2019-06-05 06:27:11 +00:00
use App ;
use Zotlabs\Web\Controller ;
2016-04-19 03:38:38 +00:00
2019-06-05 06:27:11 +00:00
class Removeaccount extends Controller {
2016-04-19 03:38:38 +00:00
function post () {
2019-06-05 06:27:11 +00:00
if ( ! local_channel ()) {
2016-04-19 03:38:38 +00:00
return ;
2019-06-05 06:27:11 +00:00
}
2016-04-19 03:38:38 +00:00
2019-06-05 06:27:11 +00:00
if ( $_SESSION [ 'delegate' ]) {
2016-04-19 03:38:38 +00:00
return ;
2019-06-05 06:27:11 +00:00
}
2016-04-19 03:38:38 +00:00
2019-06-05 06:27:11 +00:00
if (( ! x ( $_POST , 'qxz_password' )) || ( ! strlen ( trim ( $_POST [ 'qxz_password' ])))) {
2016-04-19 03:38:38 +00:00
return ;
2019-06-05 06:27:11 +00:00
}
2016-04-19 03:38:38 +00:00
2019-06-05 06:27:11 +00:00
if (( ! x ( $_POST , 'verify' )) || ( ! strlen ( trim ( $_POST [ 'verify' ])))) {
2016-04-19 03:38:38 +00:00
return ;
2019-06-05 06:27:11 +00:00
}
2016-04-19 03:38:38 +00:00
2019-06-05 06:27:11 +00:00
if ( $_POST [ 'verify' ] !== $_SESSION [ 'remove_account_verify' ]) {
2016-04-19 03:38:38 +00:00
return ;
2019-06-05 06:27:11 +00:00
}
2016-04-19 03:38:38 +00:00
2019-06-05 06:27:11 +00:00
$account = App :: get_account ();
2016-04-19 03:38:38 +00:00
$account_id = get_account_id ();
2019-06-05 00:53:21 +00:00
2019-06-05 06:27:11 +00:00
if ( ! ( $account && $account_id )) {
2019-06-05 00:53:21 +00:00
return ;
}
2016-07-21 00:55:40 +00:00
$x = account_verify_password ( $account [ 'account_email' ], $_POST [ 'qxz_password' ]);
2019-06-05 06:27:11 +00:00
if ( ! ( $x && $x [ 'account' ])) {
2016-04-19 03:38:38 +00:00
return ;
2019-06-05 06:27:11 +00:00
}
2016-04-19 03:38:38 +00:00
2019-06-05 06:27:11 +00:00
if ( $account [ 'account_password_changed' ] > NULL_DATE ) {
2016-04-19 03:38:38 +00:00
$d1 = datetime_convert ( 'UTC' , 'UTC' , 'now - 48 hours' );
2019-06-05 06:27:11 +00:00
if ( $account [ 'account_password_changed' ] > d1 ) {
2016-04-19 03:38:38 +00:00
notice ( t ( 'Account removals are not allowed within 48 hours of changing the account password.' ) . EOL );
return ;
}
}
2019-06-05 06:27:11 +00:00
account_remove ( $account_id );
2016-04-19 03:38:38 +00:00
}
2016-05-22 23:54:30 +00:00
function get () {
2016-04-19 03:38:38 +00:00
2019-06-05 06:27:11 +00:00
if ( ! local_channel ()) {
2016-04-19 03:38:38 +00:00
goaway ( z_root ());
2019-06-05 06:27:11 +00:00
}
2016-04-19 03:38:38 +00:00
$hash = random_string ();
$_SESSION [ 'remove_account_verify' ] = $hash ;
2019-06-05 06:27:11 +00:00
$o .= replace_macros ( get_markup_template ( 'removeaccount.tpl' ), [
2016-04-19 03:38:38 +00:00
'$basedir' => z_root (),
2019-06-05 06:27:11 +00:00
'$hash' => $hash ,
'$title' => t ( 'Remove This Account' ),
'$desc' => [ t ( 'WARNING: ' ), t ( 'This account and all its channels will be completely removed from this server. ' ), t ( 'This action is permanent and can not be undone!' ) ],
'$passwd' => t ( 'Please enter your password for verification:' ),
'$submit' => t ( 'Remove Account' )
]);
return $o ;
2016-04-19 03:38:38 +00:00
}
}