streams/Zotlabs/Module/Admin/Account_edit.php

84 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace Zotlabs\Module\Admin;
2021-12-02 23:02:31 +00:00
class Account_edit
{
2021-12-02 23:02:31 +00:00
public function post()
{
2021-12-02 23:02:31 +00:00
$account_id = $_REQUEST['aid'];
2021-12-03 03:01:39 +00:00
if (!$account_id) {
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
$pass1 = trim($_REQUEST['pass1']);
$pass2 = trim($_REQUEST['pass2']);
if ($pass1 && $pass2 && ($pass1 === $pass2)) {
$salt = random_string(32);
$password_encoded = hash('whirlpool', $salt . $pass1);
2021-12-03 03:01:39 +00:00
$r = q(
"update account set account_salt = '%s', account_password = '%s',
account_password_changed = '%s' where account_id = %d",
2021-12-02 23:02:31 +00:00
dbesc($salt),
dbesc($password_encoded),
dbesc(datetime_convert()),
intval($account_id)
);
2021-12-03 03:01:39 +00:00
if ($r) {
2021-12-02 23:02:31 +00:00
info(sprintf(t('Password changed for account %d.'), $account_id) . EOL);
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
}
2021-12-02 23:02:31 +00:00
$service_class = trim($_REQUEST['service_class']);
$account_language = trim($_REQUEST['account_language']);
2021-12-03 03:01:39 +00:00
$r = q(
"update account set account_service_class = '%s', account_language = '%s'
where account_id = %d",
2021-12-02 23:02:31 +00:00
dbesc($service_class),
dbesc($account_language),
intval($account_id)
);
2021-12-03 03:01:39 +00:00
if ($r) {
2021-12-02 23:02:31 +00:00
info(t('Account settings updated.') . EOL);
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
goaway(z_root() . '/admin/accounts');
}
2021-12-02 23:02:31 +00:00
public function get()
{
2021-12-03 03:01:39 +00:00
if (argc() > 2) {
2021-12-02 23:02:31 +00:00
$account_id = argv(2);
2021-12-03 03:01:39 +00:00
}
2021-12-03 03:01:39 +00:00
$x = q(
"select * from account where account_id = %d limit 1",
2021-12-02 23:02:31 +00:00
intval($account_id)
);
2021-12-02 23:02:31 +00:00
if (!$x) {
notice(t('Account not found.') . EOL);
return '';
}
2021-12-02 23:02:31 +00:00
$a = replace_macros(get_markup_template('admin_account_edit.tpl'), [
'$account' => $x[0],
'$title' => t('Account Edit'),
'$pass1' => ['pass1', t('New Password'), ' ', ''],
'$pass2' => ['pass2', t('New Password again'), ' ', ''],
'$account_language' => ['account_language', t('Account language (for emails)'), $x[0]['account_language'], '', language_list()],
'$service_class' => ['service_class', t('Service class'), $x[0]['account_service_class'], ''],
'$submit' => t('Submit'),
2021-12-03 03:01:39 +00:00
]);
2021-12-02 23:02:31 +00:00
return $a;
}
2021-12-03 03:01:39 +00:00
}