streams/Code/Module/Changeaddr.php

118 lines
3 KiB
PHP
Raw Normal View History

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