streams/Zotlabs/Module/Changeaddr.php

113 lines
2.5 KiB
PHP
Raw Normal View History

2017-08-05 02:02:41 +00:00
<?php
2019-04-17 06:31:36 +00:00
2017-08-05 02:02:41 +00:00
namespace Zotlabs\Module;
2021-03-17 03:06:35 +00:00
use App;
2019-04-17 06:31:36 +00:00
use Zotlabs\Web\Controller;
/*
* Change channel nickname
* Provided for those situations which require it.
* Must be manually configured by the admin before use.
*/
2017-08-05 02:02:41 +00:00
2019-04-17 06:31:36 +00:00
class Changeaddr extends Controller {
2017-08-05 02:02:41 +00:00
function post() {
2019-04-17 06:31:36 +00:00
if (! get_config('system','allow_nick_change')) {
return;
}
2021-03-17 03:06:35 +00:00
if (! local_channel()) {
2017-08-05 02:02:41 +00:00
return;
2021-03-17 03:06:35 +00:00
}
2017-08-05 02:02:41 +00:00
2021-03-17 03:06:35 +00:00
if (isset($_SESSION['delegate']) && $_SESSION['delegate']) {
2017-08-05 02:02:41 +00:00
return;
2021-03-17 03:06:35 +00:00
}
2017-08-05 02:02:41 +00:00
2019-04-17 06:31:36 +00:00
if ((! x($_POST,'qxz_password')) || (! strlen(trim($_POST['qxz_password']))))
2017-08-05 02:02:41 +00:00
return;
2019-04-17 06:31:36 +00:00
if ((! x($_POST,'verify')) || (! strlen(trim($_POST['verify']))))
2017-08-05 02:02:41 +00:00
return;
2019-04-17 06:31:36 +00:00
if ($_POST['verify'] !== $_SESSION['remove_account_verify'])
2017-08-05 02:02:41 +00:00
return;
2021-03-17 03:06:35 +00:00
$account = App::get_account();
$channel = App::get_channel();
2017-08-05 02:02:41 +00:00
$x = account_verify_password($account['account_email'],$_POST['qxz_password']);
2021-03-17 03:06:35 +00:00
if (! ($x && $x['account'])) {
2017-08-05 02:02:41 +00:00
return;
2021-03-17 03:06:35 +00:00
}
2017-08-05 02:02:41 +00:00
2019-04-17 06:31:36 +00:00
if ($account['account_password_changed'] > NULL_DATE) {
2017-08-05 02:02:41 +00:00
$d1 = datetime_convert('UTC','UTC','now - 48 hours');
2019-04-17 06:31:36 +00:00
if ($account['account_password_changed'] > $d1) {
2017-08-05 02:02:41 +00:00
notice( t('Channel name changes are not allowed within 48 hours of changing the account password.') . EOL);
return;
}
}
$new_address = trim($_POST['newname']);
2019-04-17 06:31:36 +00:00
if ($new_address === $channel['channel_address'])
2017-08-05 02:02:41 +00:00
return;
2019-04-17 06:31:36 +00:00
if ($new_address === 'sys') {
2017-08-05 02:02:41 +00:00
notice( t('Reserved nickname. Please choose another.') . EOL);
return;
}
2019-04-17 06:31:36 +00:00
if (check_webbie(array($new_address)) !== $new_address) {
2017-08-05 02:02:41 +00:00
notice( t('Nickname has unsupported characters or is already being used on this site.') . EOL);
return $ret;
}
channel_change_address($channel,$new_address);
goaway(z_root() . '/changeaddr');
}
function get() {
2019-04-17 06:31:36 +00:00
if (! get_config('system','allow_nick_change')) {
notice(t('Feature has been disabled') . EOL);
return;
}
2021-03-17 03:06:35 +00:00
if (! local_channel()) {
2017-08-05 02:02:41 +00:00
goaway(z_root());
2021-03-17 03:06:35 +00:00
}
2017-08-05 02:02:41 +00:00
2021-03-17 03:06:35 +00:00
$channel = App::get_channel();
2017-08-05 02:02:41 +00:00
$hash = random_string();
$_SESSION['remove_account_verify'] = $hash;
$tpl = get_markup_template('channel_rename.tpl');
2019-04-17 06:31:36 +00:00
$o .= replace_macros($tpl, [
2017-08-05 02:02:41 +00:00
'$basedir' => z_root(),
'$hash' => $hash,
'$title' => t('Change channel nickname/address'),
'$desc' => array(t('WARNING: '), t('Any/all connections on other networks will be lost!')),
'$passwd' => t('Please enter your password for verification:'),
2019-04-17 06:31:36 +00:00
'$newname' => [ 'newname', t('New channel address'),$channel['channel_address'], ''],
2017-08-05 02:02:41 +00:00
'$submit' => t('Rename Channel')
2019-04-17 06:31:36 +00:00
]);
2017-08-05 02:02:41 +00:00
return $o;
}
}