mirror of
https://github.com/friendica/friendica
synced 2024-11-09 16:22:56 +00:00
Refactor Delegation modules
- Remove dependency on DI - Group translation labels in template variables - Reformat tempate code
This commit is contained in:
parent
c98a0a99a6
commit
e6855d3125
6 changed files with 344 additions and 274 deletions
|
@ -1,152 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Notification;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Network\HTTPException\ForbiddenException;
|
||||
use Friendica\Util\Proxy;
|
||||
|
||||
/**
|
||||
* Switches current user between delegates/parent user
|
||||
*/
|
||||
class Delegation extends BaseModule
|
||||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$uid = DI::userSession()->getLocalUserId();
|
||||
$orig_record = User::getById(DI::app()->getLoggedInUserId());
|
||||
|
||||
if (DI::userSession()->getSubManagedUserId()) {
|
||||
$user = User::getById(DI::userSession()->getSubManagedUserId());
|
||||
if (DBA::isResult($user)) {
|
||||
$uid = intval($user['uid']);
|
||||
$orig_record = $user;
|
||||
}
|
||||
}
|
||||
|
||||
$identity = intval($request['identity'] ?? 0);
|
||||
if (!$identity) {
|
||||
return;
|
||||
}
|
||||
|
||||
$limited_id = 0;
|
||||
$original_id = $uid;
|
||||
|
||||
$manages = DBA::selectToArray('manage', ['mid'], ['uid' => $uid]);
|
||||
foreach ($manages as $manage) {
|
||||
if ($identity == $manage['mid']) {
|
||||
$limited_id = $manage['mid'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($limited_id) {
|
||||
$user = User::getById($limited_id);
|
||||
} else {
|
||||
// Check if the target user is one of our children
|
||||
$user = DBA::selectFirst('user', [], ['uid' => $identity, 'parent-uid' => $orig_record['uid']]);
|
||||
|
||||
// Check if the target user is one of our siblings
|
||||
if (!DBA::isResult($user) && $orig_record['parent-uid']) {
|
||||
$user = DBA::selectFirst('user', [], ['uid' => $identity, 'parent-uid' => $orig_record['parent-uid']]);
|
||||
}
|
||||
|
||||
// Check if it's our parent or our own user
|
||||
if (!DBA::isResult($user)
|
||||
&& (
|
||||
$orig_record['parent-uid'] && $orig_record['parent-uid'] === $identity
|
||||
||
|
||||
$orig_record['uid'] && $orig_record['uid'] === $identity
|
||||
)
|
||||
) {
|
||||
$user = User::getById($identity);
|
||||
}
|
||||
}
|
||||
|
||||
if (!DBA::isResult($user)) {
|
||||
return;
|
||||
}
|
||||
|
||||
DI::session()->clear();
|
||||
|
||||
DI::auth()->setForUser(DI::app(), $user, true, true);
|
||||
|
||||
if ($limited_id) {
|
||||
DI::userSession()->setSubManagedUserId($original_id);
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
Hook::callAll('home_init', $ret);
|
||||
|
||||
DI::sysmsg()->addNotice($this->t('You are now logged in as %s', $user['username']));
|
||||
|
||||
DI::baseUrl()->redirect('network');
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
throw new ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
}
|
||||
|
||||
$identities = User::identities(DI::userSession()->getSubManagedUserId() ?: DI::userSession()->getLocalUserId());
|
||||
|
||||
//getting additional information for each identity
|
||||
foreach ($identities as $key => $identity) {
|
||||
$identities[$key]['thumb'] = User::getAvatarUrl($identity, Proxy::SIZE_THUMB);
|
||||
|
||||
$identities[$key]['selected'] = ($identity['nickname'] === DI::app()->getLoggedInUserNickname());
|
||||
|
||||
$condition = ["`msg` != '' AND NOT (`type` IN (?, ?)) AND NOT `seen`", Notification\Type::INTRO, Notification\Type::MAIL];
|
||||
$params = ['distinct' => true, 'expression' => 'parent'];
|
||||
$notifications = DI::notify()->countForUser($identity['uid'], $condition, $params);
|
||||
|
||||
$params = ['distinct' => true, 'expression' => 'convid'];
|
||||
$notifications += DBA::count('mail', ['uid' => $identity['uid'], 'seen' => false], $params);
|
||||
|
||||
$notifications += DI::intro()->countActiveForUser($identity['uid']);
|
||||
|
||||
$identities[$key]['notifications'] = $notifications;
|
||||
}
|
||||
|
||||
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('delegation.tpl'), [
|
||||
'$title' => DI::l10n()->t('Switch between your accounts'),
|
||||
'$settings_label' => DI::l10n()->t('Manage your accounts'),
|
||||
'$desc' => DI::l10n()->t('Toggle between different identities or community/group pages which share your account details or which you have been granted "manage" permissions'),
|
||||
'$choose' => DI::l10n()->t('Select an identity to manage: '),
|
||||
'$identities' => $identities,
|
||||
'$submit' => DI::l10n()->t('Submit'),
|
||||
]);
|
||||
|
||||
return $o;
|
||||
}
|
||||
}
|
|
@ -21,29 +21,48 @@
|
|||
|
||||
namespace Friendica\Module\Settings;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\BaseSettings;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Navigation\SystemMessages;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Util\Profiler;
|
||||
use Friendica\Util\Strings;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Account delegation settings module
|
||||
*/
|
||||
class Delegation extends BaseSettings
|
||||
{
|
||||
/** @var SystemMessages */
|
||||
private $systemMessages;
|
||||
/** @var Database */
|
||||
private $db;
|
||||
|
||||
public function __construct(Database $db, SystemMessages $systemMessages, IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->systemMessages = $systemMessages;
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
if (!DI::app()->isLoggedIn()) {
|
||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
if (!$this->session->isAuthenticated()) {
|
||||
return;
|
||||
}
|
||||
|
||||
BaseModule::checkFormSecurityTokenRedirectOnError('settings/delegation', 'delegate');
|
||||
|
||||
$parent_uid = $request['parent_user'] ?? null;
|
||||
$parent_uid = $request['parent_user'] ?? null;
|
||||
$parent_password = $request['parent_password'] ?? '';
|
||||
|
||||
if ($parent_uid) {
|
||||
|
@ -51,66 +70,63 @@ class Delegation extends BaseSettings
|
|||
// An integer value will trigger the direct user query on uid in User::getAuthenticationInfo
|
||||
$parent_uid = (int)$parent_uid;
|
||||
User::getIdFromPasswordAuthentication($parent_uid, $parent_password);
|
||||
DI::sysmsg()->addInfo(DI::l10n()->t('Delegation successfully granted.'));
|
||||
$this->systemMessages->addInfo($this->t('Delegation successfully granted.'));
|
||||
} catch (\Exception $ex) {
|
||||
DI::sysmsg()->addNotice(DI::l10n()->t('Parent user not found, unavailable or password doesn\'t match.'));
|
||||
$this->systemMessages->addNotice($this->t('Parent user not found, unavailable or password doesn\'t match.'));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
DI::sysmsg()->addInfo(DI::l10n()->t('Delegation successfully revoked.'));
|
||||
$this->systemMessages->addInfo($this->t('Delegation successfully revoked.'));
|
||||
}
|
||||
|
||||
DBA::update('user', ['parent-uid' => $parent_uid], ['uid' => DI::userSession()->getLocalUserId()]);
|
||||
$this->db->update('user', ['parent-uid' => $parent_uid], ['uid' => $this->session->getLocalUserId()]);
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
parent::content();
|
||||
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
if (!$this->session->isAuthenticated()) {
|
||||
throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
|
||||
}
|
||||
|
||||
$args = DI::args();
|
||||
|
||||
// @TODO Replace with router-provided arguments
|
||||
$action = $args->get(2);
|
||||
$user_id = $args->get(3);
|
||||
$action = $this->parameters['action'] ?? '';
|
||||
$user_id = $this->parameters['user_id'] ?? 0;
|
||||
|
||||
if ($action === 'add' && $user_id) {
|
||||
if (DI::userSession()->getSubManagedUserId()) {
|
||||
DI::sysmsg()->addNotice(DI::l10n()->t('Delegated administrators can view but not change delegation permissions.'));
|
||||
DI::baseUrl()->redirect('settings/delegation');
|
||||
if ($this->session->getSubManagedUserId()) {
|
||||
$this->systemMessages->addNotice($this->t('Delegated administrators can view but not change delegation permissions.'));
|
||||
$this->baseUrl->redirect('settings/delegation');
|
||||
}
|
||||
|
||||
$user = User::getById($user_id, ['nickname']);
|
||||
if (DBA::isResult($user)) {
|
||||
if ($this->db->isResult($user)) {
|
||||
$condition = [
|
||||
'uid' => DI::userSession()->getLocalUserId(),
|
||||
'nurl' => Strings::normaliseLink(DI::baseUrl() . '/profile/' . $user['nickname'])
|
||||
'uid' => $this->session->getLocalUserId(),
|
||||
'nurl' => Strings::normaliseLink($this->baseUrl . '/profile/' . $user['nickname'])
|
||||
];
|
||||
if (DBA::exists('contact', $condition)) {
|
||||
DBA::insert('manage', ['uid' => $user_id, 'mid' => DI::userSession()->getLocalUserId()]);
|
||||
if ($this->db->exists('contact', $condition)) {
|
||||
$this->db->insert('manage', ['uid' => $user_id, 'mid' => $this->session->getLocalUserId()]);
|
||||
}
|
||||
} else {
|
||||
DI::sysmsg()->addNotice(DI::l10n()->t('Delegate user not found.'));
|
||||
$this->systemMessages->addNotice($this->t('Delegate user not found.'));
|
||||
}
|
||||
|
||||
DI::baseUrl()->redirect('settings/delegation');
|
||||
$this->baseUrl->redirect('settings/delegation');
|
||||
}
|
||||
|
||||
if ($action === 'remove' && $user_id) {
|
||||
if (DI::userSession()->getSubManagedUserId()) {
|
||||
DI::sysmsg()->addNotice(DI::l10n()->t('Delegated administrators can view but not change delegation permissions.'));
|
||||
DI::baseUrl()->redirect('settings/delegation');
|
||||
if ($this->session->getSubManagedUserId()) {
|
||||
$this->systemMessages->addNotice($this->t('Delegated administrators can view but not change delegation permissions.'));
|
||||
$this->baseUrl->redirect('settings/delegation');
|
||||
}
|
||||
|
||||
DBA::delete('manage', ['uid' => $user_id, 'mid' => DI::userSession()->getLocalUserId()]);
|
||||
DI::baseUrl()->redirect('settings/delegation');
|
||||
$this->db->delete('manage', ['uid' => $user_id, 'mid' => $this->session->getLocalUserId()]);
|
||||
$this->baseUrl->redirect('settings/delegation');
|
||||
}
|
||||
|
||||
// find everybody that currently has delegated management to this account/page
|
||||
$delegates = DBA::selectToArray('user', [], ['`uid` IN (SELECT `uid` FROM `manage` WHERE `mid` = ?)', DI::userSession()->getLocalUserId()]);
|
||||
$delegates = $this->db->selectToArray('user', [], ['`uid` IN (SELECT `uid` FROM `manage` WHERE `mid` = ?)', $this->session->getLocalUserId()]);
|
||||
|
||||
$uids = [];
|
||||
foreach ($delegates as $user) {
|
||||
|
@ -119,69 +135,76 @@ class Delegation extends BaseSettings
|
|||
|
||||
// find every contact who might be a candidate for delegation
|
||||
$potentials = [];
|
||||
$nicknames = [];
|
||||
$nicknames = [];
|
||||
|
||||
$condition = ['baseurl' => DI::baseUrl(), 'self' => false, 'uid' => DI::userSession()->getLocalUserId(), 'blocked' => false];
|
||||
$contacts = DBA::select('contact', ['nick'], $condition);
|
||||
while ($contact = DBA::fetch($contacts)) {
|
||||
$condition = ['baseurl' => $this->baseUrl, 'self' => false, 'uid' => $this->session->getLocalUserId(), 'blocked' => false];
|
||||
$contacts = $this->db->select('contact', ['nick'], $condition);
|
||||
while ($contact = $this->db->fetch($contacts)) {
|
||||
$nicknames[] = $contact['nick'];
|
||||
}
|
||||
DBA::close($contacts);
|
||||
$this->db->close($contacts);
|
||||
|
||||
// get user records for all potential page delegates who are not already delegates or managers
|
||||
$potentialDelegateUsers = DBA::selectToArray('user', ['uid', 'username', 'nickname'], ['nickname' => $nicknames]);
|
||||
$potentialDelegateUsers = $this->db->selectToArray(
|
||||
'user',
|
||||
['uid', 'username', 'nickname'],
|
||||
[
|
||||
'nickname' => $nicknames,
|
||||
'account_removed' => false,
|
||||
'account_expired' => false,
|
||||
'blocked' => false,
|
||||
]
|
||||
);
|
||||
foreach ($potentialDelegateUsers as $user) {
|
||||
if (!in_array($user['uid'], $uids)) {
|
||||
$potentials[] = $user;
|
||||
}
|
||||
}
|
||||
|
||||
$parent_user = null;
|
||||
$parent_user = null;
|
||||
$parent_password = null;
|
||||
$user = User::getById(DI::userSession()->getLocalUserId(), ['parent-uid', 'email']);
|
||||
if (DBA::isResult($user) && !DBA::exists('user', ['parent-uid' => DI::userSession()->getLocalUserId()])) {
|
||||
$user = User::getById($this->session->getLocalUserId(), ['parent-uid', 'email']);
|
||||
if ($this->db->isResult($user) && !$this->db->exists('user', ['parent-uid' => $this->session->getLocalUserId()])) {
|
||||
$parent_uid = $user['parent-uid'];
|
||||
$parents = [0 => DI::l10n()->t('No parent user')];
|
||||
$parents = [0 => $this->t('No parent user')];
|
||||
|
||||
$fields = ['uid', 'username', 'nickname'];
|
||||
$condition = ['email' => $user['email'], 'verified' => true, 'blocked' => false, 'parent-uid' => null];
|
||||
$parent_users = DBA::selectToArray('user', $fields, $condition);
|
||||
foreach($parent_users as $parent) {
|
||||
if ($parent['uid'] != DI::userSession()->getLocalUserId()) {
|
||||
$fields = ['uid', 'username', 'nickname'];
|
||||
$condition = ['email' => $user['email'], 'verified' => true, 'blocked' => false, 'parent-uid' => null];
|
||||
$parent_users = $this->db->selectToArray('user', $fields, $condition);
|
||||
foreach ($parent_users as $parent) {
|
||||
if ($parent['uid'] != $this->session->getLocalUserId()) {
|
||||
$parents[$parent['uid']] = sprintf('%s (%s)', $parent['username'], $parent['nickname']);
|
||||
}
|
||||
}
|
||||
|
||||
$parent_user = ['parent_user', DI::l10n()->t('Parent User'), $parent_uid, '', $parents];
|
||||
$parent_password = ['parent_password', DI::l10n()->t('Parent Password:'), '', DI::l10n()->t('Please enter the password of the parent account to legitimize your request.')];
|
||||
$parent_user = ['parent_user', $this->t('Parent User'), $parent_uid, '', $parents];
|
||||
$parent_password = ['parent_password', $this->t('Parent Password:'), '', $this->t('Please enter the password of the parent account to legitimize your request.')];
|
||||
}
|
||||
|
||||
$is_child_user = !empty($user['parent-uid']);
|
||||
|
||||
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/delegation.tpl'), [
|
||||
'$form_security_token' => BaseModule::getFormSecurityToken('delegate'),
|
||||
'$account_header' => DI::l10n()->t('Additional Accounts'),
|
||||
'$account_desc' => DI::l10n()->t('Register additional accounts that are automatically connected to your existing account so you can manage them from this account.'),
|
||||
'$add_account' => DI::l10n()->t('Register an additional account'),
|
||||
'$parent_header' => DI::l10n()->t('Parent User'),
|
||||
'$parent_user' => $parent_user,
|
||||
'$parent_password' => $parent_password,
|
||||
'$parent_desc' => DI::l10n()->t('Parent users have total control about this account, including the account settings. Please double check whom you give this access.'),
|
||||
'$is_child_user' => $is_child_user,
|
||||
'$submit' => DI::l10n()->t('Save Settings'),
|
||||
'$header' => DI::l10n()->t('Manage Accounts'),
|
||||
'$delegates_header' => DI::l10n()->t('Delegates'),
|
||||
'$base' => DI::baseUrl(),
|
||||
'$desc' => DI::l10n()->t('Delegates are able to manage all aspects of this account/page except for basic account settings. Please do not delegate your personal account to anybody that you do not trust completely.'),
|
||||
'$head_delegates' => DI::l10n()->t('Existing Page Delegates'),
|
||||
'$delegates' => $delegates,
|
||||
'$head_potentials' => DI::l10n()->t('Potential Delegates'),
|
||||
'$potentials' => $potentials,
|
||||
'$remove' => DI::l10n()->t('Remove'),
|
||||
'$add' => DI::l10n()->t('Add'),
|
||||
'$none' => DI::l10n()->t('No entries.')
|
||||
]);
|
||||
return Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/delegation.tpl'), [
|
||||
'$l10n' => [
|
||||
'account_header' => $this->t('Additional Accounts'),
|
||||
'account_desc' => $this->t('Register additional accounts that are automatically connected to your existing account so you can manage them from this account.'),
|
||||
'add_account' => $this->t('Register an additional account'),
|
||||
'parent_header' => $this->t('Parent User'),
|
||||
'parent_desc' => $this->t('Parent users have total control about this account, including the account settings. Please double check whom you give this access.'),
|
||||
'submit' => $this->t('Save Settings'),
|
||||
'header' => $this->t('Manage Accounts'),
|
||||
'delegates_header' => $this->t('Delegates'),
|
||||
'desc' => $this->t('Delegates are able to manage all aspects of this account/page except for basic account settings. Please do not delegate your personal account to anybody that you do not trust completely.'),
|
||||
'head_delegates' => $this->t('Existing Page Delegates'),
|
||||
'head_potentials' => $this->t('Potential Delegates'),
|
||||
'none' => $this->t('No entries.'),
|
||||
],
|
||||
|
||||
return $o;
|
||||
'$form_security_token' => BaseModule::getFormSecurityToken('delegate'),
|
||||
'$parent_user' => $parent_user,
|
||||
'$parent_password' => $parent_password,
|
||||
'$is_child_user' => $is_child_user,
|
||||
'$delegates' => $delegates,
|
||||
'$potentials' => $potentials,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
195
src/Module/User/Delegation.php
Normal file
195
src/Module/User/Delegation.php
Normal file
|
@ -0,0 +1,195 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\User;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Contact\Introduction\Repository\Introduction;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\Notification;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Navigation\Notifications\Repository\Notify;
|
||||
use Friendica\Navigation\SystemMessages;
|
||||
use Friendica\Network\HTTPException\ForbiddenException;
|
||||
use Friendica\Security\Authentication;
|
||||
use Friendica\Util;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Switches current user between delegates/parent user
|
||||
*/
|
||||
class Delegation extends BaseModule
|
||||
{
|
||||
/** @var IHandleUserSessions */
|
||||
private $session;
|
||||
/** @var Database */
|
||||
private $db;
|
||||
/** @var Authentication */
|
||||
private $auth;
|
||||
/** @var SystemMessages */
|
||||
private $systemMessages;
|
||||
/** @var Notify */
|
||||
private $notify;
|
||||
/** @var Introduction */
|
||||
private $intro;
|
||||
/** @var App */
|
||||
private $app;
|
||||
|
||||
public function __construct(App $app, Introduction $intro, Notify $notify, SystemMessages $systemMessages, Authentication $auth, Database $db, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Util\Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->session = $session;
|
||||
$this->db = $db;
|
||||
$this->auth = $auth;
|
||||
$this->systemMessages = $systemMessages;
|
||||
$this->notify = $notify;
|
||||
$this->intro = $intro;
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
if (!$this->session->getLocalUserId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$uid = $this->session->getLocalUserId();
|
||||
$orig_record = User::getById($this->session->getLocalUserId());
|
||||
|
||||
if ($this->session->getSubManagedUserId()) {
|
||||
$user = User::getById($this->session->getSubManagedUserId());
|
||||
if ($this->db->isResult($user)) {
|
||||
$uid = intval($user['uid']);
|
||||
$orig_record = $user;
|
||||
}
|
||||
}
|
||||
|
||||
$identity = intval($request['identity'] ?? 0);
|
||||
if (!$identity) {
|
||||
return;
|
||||
}
|
||||
|
||||
$limited_id = 0;
|
||||
$original_id = $uid;
|
||||
|
||||
$manages = $this->db->selectToArray('manage', ['mid'], ['uid' => $uid]);
|
||||
foreach ($manages as $manage) {
|
||||
if ($identity == $manage['mid']) {
|
||||
$limited_id = $manage['mid'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($limited_id) {
|
||||
$user = User::getById($limited_id);
|
||||
} else {
|
||||
// Check if the target user is one of our children
|
||||
$user = $this->db->selectFirst('user', [], ['uid' => $identity, 'parent-uid' => $orig_record['uid']]);
|
||||
|
||||
// Check if the target user is one of our siblings
|
||||
if (!$this->db->isResult($user) && $orig_record['parent-uid']) {
|
||||
$user = $this->db->selectFirst('user', [], ['uid' => $identity, 'parent-uid' => $orig_record['parent-uid']]);
|
||||
}
|
||||
|
||||
// Check if it's our parent or our own user
|
||||
if (!$this->db->isResult($user)
|
||||
&& (
|
||||
$orig_record['parent-uid'] && $orig_record['parent-uid'] === $identity
|
||||
||
|
||||
$orig_record['uid'] && $orig_record['uid'] === $identity
|
||||
)
|
||||
) {
|
||||
$user = User::getById($identity);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->db->isResult($user)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->session->clear();
|
||||
|
||||
$this->auth->setForUser($this->app, $user, true, true);
|
||||
|
||||
if ($limited_id) {
|
||||
$this->session->setSubManagedUserId($original_id);
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
Hook::callAll('home_init', $ret);
|
||||
|
||||
$this->systemMessages->addNotice($this->t('You are now logged in as %s', $user['username']));
|
||||
|
||||
$this->baseUrl->redirect('network');
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
if (!$this->session->getLocalUserId()) {
|
||||
throw new ForbiddenException($this->t('Permission denied.'));
|
||||
}
|
||||
|
||||
$identities = User::identities($this->session->getSubManagedUserId() ?: $this->session->getLocalUserId());
|
||||
|
||||
//getting additional information for each identity
|
||||
foreach ($identities as $key => $identity) {
|
||||
$identities[$key]['thumb'] = User::getAvatarUrl($identity, Util\Proxy::SIZE_THUMB);
|
||||
|
||||
$identities[$key]['selected'] = ($identity['nickname'] === $this->session->getLocalUserNickname());
|
||||
|
||||
$notifications = $this->notify->countForUser(
|
||||
$identity['uid'],
|
||||
["`msg` != '' AND NOT (`type` IN (?, ?)) AND NOT `seen`", Notification\Type::INTRO, Notification\Type::MAIL],
|
||||
['distinct' => true, 'expression' => 'parent']
|
||||
);
|
||||
|
||||
$notifications += $this->db->count(
|
||||
'mail',
|
||||
['uid' => $identity['uid'], 'seen' => false],
|
||||
['distinct' => true, 'expression' => 'convid']
|
||||
);
|
||||
|
||||
$notifications += $this->intro->countActiveForUser($identity['uid']);
|
||||
|
||||
$identities[$key]['notifications'] = $notifications;
|
||||
}
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('delegation.tpl');
|
||||
return Renderer::replaceMacros($tpl, [
|
||||
'$l10n' => [
|
||||
'title' => $this->t('Switch between your accounts'),
|
||||
'settings_label' => $this->t('Manage your accounts'),
|
||||
'desc' => $this->t('Toggle between different identities or community/group pages which share your account details or which you have been granted "manage" permissions'),
|
||||
'choose' => $this->t('Select an identity to manage: '),
|
||||
'submit' => $this->t('Submit'),
|
||||
],
|
||||
|
||||
'$identities' => $identities,
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -423,8 +423,8 @@ return [
|
|||
],
|
||||
|
||||
'/credits' => [Module\Credits::class, [R::GET]],
|
||||
'/delegation' => [Module\Delegation::class, [R::GET, R::POST]],
|
||||
'/dfrn_notify[/{nickname}]' => [Module\DFRN\Notify::class, [R::POST]],
|
||||
'/delegation' => [Module\User\Delegation::class, [R::GET, R::POST]],
|
||||
'/dfrn_notify[/{nickname}]' => [Module\DFRN\Notify::class, [ R::POST]],
|
||||
'/dfrn_poll/{nickname}' => [Module\DFRN\Poll::class, [R::GET]],
|
||||
'/dirfind' => [Module\Search\Directory::class, [R::GET]],
|
||||
'/directory' => [Module\Directory::class, [R::GET]],
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
<h1>{{$title}}</h1>
|
||||
<p id="identity-delegation-desc">{{$desc nofilter}}</p>
|
||||
<p id="identity-delegation-choose">{{$choose}}</p>
|
||||
<div id="delegation" class="generic-page-wrapper">
|
||||
<h2>{{$l10n.title}}</h2>
|
||||
<p id="identity-delegation-desc">{{$l10n.desc}}</p>
|
||||
<p id="identity-delegation-choose">{{$l10n.choose}}</p>
|
||||
|
||||
<div id="identity-selector-wrapper" role="menu">
|
||||
<form action="delegation" method="post">
|
||||
<div id="identity-selector-wrapper" role="menu">
|
||||
<form action="delegation" method="post">
|
||||
|
||||
{{foreach $identities as $identity}}
|
||||
{{foreach $identities as $identity}}
|
||||
<div class="identity-match-wrapper {{if $identity.selected}}selected-identity{{/if}}" id="identity-match-{{$identity.uid}}">
|
||||
<div class="identity-match-photo" id="identity-match-photo-{{$identity.uid}}">
|
||||
<button type="submit" name="identity" value="{{$identity.uid}}" title="{{$identity.username}}">
|
||||
|
@ -28,13 +29,14 @@
|
|||
</div>
|
||||
<div class="identity-match-end"></div>
|
||||
</div>
|
||||
{{/foreach}}
|
||||
{{/foreach}}
|
||||
|
||||
<div class="identity-match-break"></div>
|
||||
<div class="identity-match-break"></div>
|
||||
|
||||
</form>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<a href="settings/delegation" class="btn btn-primary"><i class="fa fa-cog"></i> {{$l10n.settings_label}}</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<a href="settings/delegation" class="btn btn-primary"><i class="fa fa-cog"></i> {{$settings_label}}</a>
|
||||
</p>
|
||||
|
|
|
@ -1,54 +1,56 @@
|
|||
<div id="delegation" class="generic-page-wrapper">
|
||||
<h1>{{$header}}</h1>
|
||||
<h2>{{$l10n.header}}</h2>
|
||||
|
||||
{{if !$is_child_user}}
|
||||
<h2>{{$account_header}}</h2>
|
||||
<div id="add-account-desc" class="add-account-desc"><p>{{$account_desc}}</p></div>
|
||||
<p><a href='register'>{{$add_account}}</a></p>
|
||||
<h3>{{$l10n.account_header}}</h3>
|
||||
<div id="add-account-desc" class="add-account-desc"><p>{{$l10n.account_desc}}</p></div>
|
||||
<p><a href="register">{{$l10n.add_account}}</a></p>
|
||||
{{/if}}
|
||||
|
||||
{{if $parent_user}}
|
||||
<h2>{{$parent_header}}</h2>
|
||||
<div id="delegate-parent-desc" class="delegate-parent-desc"><p>{{$parent_desc}}</p></div>
|
||||
<div id="delegate-parent" class="delegate-parent">
|
||||
<form action="settings/delegation" method="post">
|
||||
<input type='hidden' name='form_security_token' value='{{$form_security_token}}'>
|
||||
{{include file="field_select.tpl" field=$parent_user}}
|
||||
{{include file="field_password.tpl" field=$parent_password}}
|
||||
<div class="submit"><input type="submit" name="delegate" value="{{$submit}}"/></div>
|
||||
</form>
|
||||
</div>
|
||||
<h3>{{$l10n.parent_header}}</h3>
|
||||
<div id="delegate-parent-desc" class="delegate-parent-desc"><p>{{$l10n.parent_desc}}</p></div>
|
||||
<div id="delegate-parent" class="delegate-parent">
|
||||
<form action="settings/delegation" method="post">
|
||||
<input type="hidden" name='form_security_token' value="{{$form_security_token}}">
|
||||
{{include file="field_select.tpl" field=$parent_user}}
|
||||
{{include file="field_password.tpl" field=$parent_password}}
|
||||
<div class="submit">
|
||||
<button type="submit" name="delegate" value="{{$l10n.submit}}">{{$l10n.submit}}</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
<h2>{{$delegates_header}}</h2>
|
||||
<h3>{{$l10n.delegates_header}}</h3>
|
||||
|
||||
<div id="delegate-desc" class="delegate-desc"><p>{{$desc nofilter}}</p></div>
|
||||
<div id="delegate-desc" class="delegate-desc"><p>{{$l10n.desc}}</p></div>
|
||||
|
||||
<h3>{{$head_delegates}}</h3>
|
||||
<h4>{{$l10n.head_delegates}}</h4>
|
||||
{{if $delegates}}
|
||||
{{foreach $delegates as $x}}
|
||||
<div class="contact-block-div">
|
||||
<a class="contact-block-link" href="settings/delegation/remove/{{$x.uid}}">
|
||||
<img class="contact-block-img" src="photo/thumb/{{$x.uid}}" title="{{$x.username}} ({{$x.nickname}})">
|
||||
</a>
|
||||
</div>
|
||||
{{foreach $delegates as $delegate}}
|
||||
<div class="contact-block-div">
|
||||
<a class="contact-block-link" href="settings/delegation/remove/{{$delegate.uid}}">
|
||||
<img class="contact-block-img" src="photo/thumb/{{$delegate.uid}}" title="{{$delegate.username}} ({{$delegate.nickname}})">
|
||||
</a>
|
||||
</div>
|
||||
{{/foreach}}
|
||||
<div class="clear"></div>
|
||||
<div class="clear"></div>
|
||||
{{else}}
|
||||
<p>{{$none}}</p>
|
||||
<p>{{$l10n.none}}</p>
|
||||
{{/if}}
|
||||
|
||||
<h3>{{$head_potentials}}</h3>
|
||||
<h4>{{$l10n.head_potentials}}</h4>
|
||||
{{if $potentials}}
|
||||
{{foreach $potentials as $x}}
|
||||
<div class="contact-block-div">
|
||||
<a class="contact-block-link" href="settings/delegation/add/{{$x.uid}}">
|
||||
<img class="contact-block-img" src="photo/thumb/{{$x.uid}}" title="{{$x.username}} ({{$x.nickname}})">
|
||||
</a>
|
||||
</div>
|
||||
{{foreach $potentials as $potential}}
|
||||
<div class="contact-block-div">
|
||||
<a class="contact-block-link" href="settings/delegation/add/{{$potential.uid}}">
|
||||
<img class="contact-block-img" src="photo/thumb/{{$potential.uid}}" title="{{$potential.username}} ({{$potential.nickname}})">
|
||||
</a>
|
||||
</div>
|
||||
{{/foreach}}
|
||||
<div class="clear"></div>
|
||||
<div class="clear"></div>
|
||||
{{else}}
|
||||
<p>{{$none}}</p>
|
||||
<p>{{$l10n.none}}</p>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue