old boot.php functions replaced in src/module (3)

This commit is contained in:
Michael 2022-10-19 04:40:06 +00:00 committed by Hypolite Petovan
parent 83390d4b00
commit ae6d67ed1f
22 changed files with 158 additions and 147 deletions

View file

@ -59,14 +59,14 @@ class Delegation extends BaseSettings
DI::sysmsg()->addInfo(DI::l10n()->t('Delegation successfully revoked.'));
}
DBA::update('user', ['parent-uid' => $parent_uid], ['uid' => local_user()]);
DBA::update('user', ['parent-uid' => $parent_uid], ['uid' => Session::getLocalUser()]);
}
protected function content(array $request = []): string
{
parent::content();
if (!local_user()) {
if (!Session::getLocalUser()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
@ -85,11 +85,11 @@ class Delegation extends BaseSettings
$user = User::getById($user_id, ['nickname']);
if (DBA::isResult($user)) {
$condition = [
'uid' => local_user(),
'uid' => Session::getLocalUser(),
'nurl' => Strings::normaliseLink(DI::baseUrl() . '/profile/' . $user['nickname'])
];
if (DBA::exists('contact', $condition)) {
DBA::insert('manage', ['uid' => $user_id, 'mid' => local_user()]);
DBA::insert('manage', ['uid' => $user_id, 'mid' => Session::getLocalUser()]);
}
} else {
DI::sysmsg()->addNotice(DI::l10n()->t('Delegate user not found.'));
@ -104,12 +104,12 @@ class Delegation extends BaseSettings
DI::baseUrl()->redirect('settings/delegation');
}
DBA::delete('manage', ['uid' => $user_id, 'mid' => local_user()]);
DBA::delete('manage', ['uid' => $user_id, 'mid' => Session::getLocalUser()]);
DI::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` = ?)', local_user()]);
$delegates = DBA::selectToArray('user', [], ['`uid` IN (SELECT `uid` FROM `manage` WHERE `mid` = ?)', Session::getLocalUser()]);
$uids = [];
foreach ($delegates as $user) {
@ -120,7 +120,7 @@ class Delegation extends BaseSettings
$potentials = [];
$nicknames = [];
$condition = ['baseurl' => DI::baseUrl(), 'self' => false, 'uid' => local_user(), 'blocked' => false];
$condition = ['baseurl' => DI::baseUrl(), 'self' => false, 'uid' => Session::getLocalUser(), 'blocked' => false];
$contacts = DBA::select('contact', ['nick'], $condition);
while ($contact = DBA::fetch($contacts)) {
$nicknames[] = $contact['nick'];
@ -137,8 +137,8 @@ class Delegation extends BaseSettings
$parent_user = null;
$parent_password = null;
$user = User::getById(local_user(), ['parent-uid', 'email']);
if (DBA::isResult($user) && !DBA::exists('user', ['parent-uid' => local_user()])) {
$user = User::getById(Session::getLocalUser(), ['parent-uid', 'email']);
if (DBA::isResult($user) && !DBA::exists('user', ['parent-uid' => Session::getLocalUser()])) {
$parent_uid = $user['parent-uid'];
$parents = [0 => DI::l10n()->t('No parent user')];
@ -146,7 +146,7 @@ class Delegation extends BaseSettings
$condition = ['email' => $user['email'], 'verified' => true, 'blocked' => false, 'parent-uid' => 0];
$parent_users = DBA::selectToArray('user', $fields, $condition);
foreach($parent_users as $parent) {
if ($parent['uid'] != local_user()) {
if ($parent['uid'] != Session::getLocalUser()) {
$parents[$parent['uid']] = sprintf('%s (%s)', $parent['username'], $parent['nickname']);
}
}

View file

@ -44,7 +44,7 @@ class Display extends BaseSettings
self::checkFormSecurityTokenRedirectOnError('/settings/display', 'settings_display');
$user = User::getById(local_user());
$user = User::getById(Session::getLocalUser());
$theme = !empty($_POST['theme']) ? trim($_POST['theme']) : $user['theme'];
$mobile_theme = !empty($_POST['mobile_theme']) ? trim($_POST['mobile_theme']) : '';
@ -78,20 +78,20 @@ class Display extends BaseSettings
}
if ($mobile_theme !== '') {
DI::pConfig()->set(local_user(), 'system', 'mobile_theme', $mobile_theme);
DI::pConfig()->set(Session::getLocalUser(), 'system', 'mobile_theme', $mobile_theme);
}
DI::pConfig()->set(local_user(), 'system', 'itemspage_network' , $itemspage_network);
DI::pConfig()->set(local_user(), 'system', 'itemspage_mobile_network', $itemspage_mobile_network);
DI::pConfig()->set(local_user(), 'system', 'update_interval' , $browser_update);
DI::pConfig()->set(local_user(), 'system', 'no_auto_update' , $no_auto_update);
DI::pConfig()->set(local_user(), 'system', 'no_smilies' , !$enable_smile);
DI::pConfig()->set(local_user(), 'system', 'infinite_scroll' , $infinite_scroll);
DI::pConfig()->set(local_user(), 'system', 'no_smart_threading' , !$enable_smart_threading);
DI::pConfig()->set(local_user(), 'system', 'hide_dislike' , !$enable_dislike);
DI::pConfig()->set(local_user(), 'system', 'display_resharer' , $display_resharer);
DI::pConfig()->set(local_user(), 'system', 'stay_local' , $stay_local);
DI::pConfig()->set(local_user(), 'system', 'first_day_of_week' , $first_day_of_week);
DI::pConfig()->set(Session::getLocalUser(), 'system', 'itemspage_network' , $itemspage_network);
DI::pConfig()->set(Session::getLocalUser(), 'system', 'itemspage_mobile_network', $itemspage_mobile_network);
DI::pConfig()->set(Session::getLocalUser(), 'system', 'update_interval' , $browser_update);
DI::pConfig()->set(Session::getLocalUser(), 'system', 'no_auto_update' , $no_auto_update);
DI::pConfig()->set(Session::getLocalUser(), 'system', 'no_smilies' , !$enable_smile);
DI::pConfig()->set(Session::getLocalUser(), 'system', 'infinite_scroll' , $infinite_scroll);
DI::pConfig()->set(Session::getLocalUser(), 'system', 'no_smart_threading' , !$enable_smart_threading);
DI::pConfig()->set(Session::getLocalUser(), 'system', 'hide_dislike' , !$enable_dislike);
DI::pConfig()->set(Session::getLocalUser(), 'system', 'display_resharer' , $display_resharer);
DI::pConfig()->set(Session::getLocalUser(), 'system', 'stay_local' , $stay_local);
DI::pConfig()->set(Session::getLocalUser(), 'system', 'first_day_of_week' , $first_day_of_week);
if (in_array($theme, Theme::getAllowedList())) {
if ($theme == $user['theme']) {
@ -101,7 +101,7 @@ class Display extends BaseSettings
theme_post(DI::app());
}
} else {
DBA::update('user', ['theme' => $theme], ['uid' => local_user()]);
DBA::update('user', ['theme' => $theme], ['uid' => Session::getLocalUser()]);
}
} else {
DI::sysmsg()->addNotice(DI::l10n()->t('The theme you chose isn\'t available.'));
@ -116,7 +116,7 @@ class Display extends BaseSettings
{
parent::content();
if (!local_user()) {
if (!Session::getLocalUser()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
@ -130,7 +130,7 @@ class Display extends BaseSettings
$default_mobile_theme = 'none';
}
$user = User::getById(local_user());
$user = User::getById(Session::getLocalUser());
$allowed_themes = Theme::getAllowedList();
@ -159,26 +159,26 @@ class Display extends BaseSettings
$theme_selected = $user['theme'] ?: $default_theme;
$mobile_theme_selected = DI::session()->get('mobile-theme', $default_mobile_theme);
$itemspage_network = intval(DI::pConfig()->get(local_user(), 'system', 'itemspage_network'));
$itemspage_network = intval(DI::pConfig()->get(Session::getLocalUser(), 'system', 'itemspage_network'));
$itemspage_network = (($itemspage_network > 0 && $itemspage_network < 101) ? $itemspage_network : DI::config()->get('system', 'itemspage_network'));
$itemspage_mobile_network = intval(DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network'));
$itemspage_mobile_network = intval(DI::pConfig()->get(Session::getLocalUser(), 'system', 'itemspage_mobile_network'));
$itemspage_mobile_network = (($itemspage_mobile_network > 0 && $itemspage_mobile_network < 101) ? $itemspage_mobile_network : DI::config()->get('system', 'itemspage_network_mobile'));
$browser_update = intval(DI::pConfig()->get(local_user(), 'system', 'update_interval'));
$browser_update = intval(DI::pConfig()->get(Session::getLocalUser(), 'system', 'update_interval'));
if (intval($browser_update) != -1) {
$browser_update = (($browser_update == 0) ? 40 : $browser_update / 1000); // default if not set: 40 seconds
}
$no_auto_update = DI::pConfig()->get(local_user(), 'system', 'no_auto_update', 0);
$enable_smile = !DI::pConfig()->get(local_user(), 'system', 'no_smilies', 0);
$infinite_scroll = DI::pConfig()->get(local_user(), 'system', 'infinite_scroll', 0);
$enable_smart_threading = !DI::pConfig()->get(local_user(), 'system', 'no_smart_threading', 0);
$enable_dislike = !DI::pConfig()->get(local_user(), 'system', 'hide_dislike', 0);
$display_resharer = DI::pConfig()->get(local_user(), 'system', 'display_resharer', 0);
$stay_local = DI::pConfig()->get(local_user(), 'system', 'stay_local', 0);
$no_auto_update = DI::pConfig()->get(Session::getLocalUser(), 'system', 'no_auto_update', 0);
$enable_smile = !DI::pConfig()->get(Session::getLocalUser(), 'system', 'no_smilies', 0);
$infinite_scroll = DI::pConfig()->get(Session::getLocalUser(), 'system', 'infinite_scroll', 0);
$enable_smart_threading = !DI::pConfig()->get(Session::getLocalUser(), 'system', 'no_smart_threading', 0);
$enable_dislike = !DI::pConfig()->get(Session::getLocalUser(), 'system', 'hide_dislike', 0);
$display_resharer = DI::pConfig()->get(Session::getLocalUser(), 'system', 'display_resharer', 0);
$stay_local = DI::pConfig()->get(Session::getLocalUser(), 'system', 'stay_local', 0);
$first_day_of_week = DI::pConfig()->get(local_user(), 'system', 'first_day_of_week', 0);
$first_day_of_week = DI::pConfig()->get(Session::getLocalUser(), 'system', 'first_day_of_week', 0);
$weekdays = [
0 => DI::l10n()->t("Sunday"),
1 => DI::l10n()->t("Monday"),
@ -207,7 +207,7 @@ class Display extends BaseSettings
'$form_security_token' => self::getFormSecurityToken('settings_display'),
'$baseurl' => DI::baseUrl()->get(true),
'$uid' => local_user(),
'$uid' => Session::getLocalUser(),
'$theme' => ['theme', DI::l10n()->t('Display Theme:'), $theme_selected, '', $themes, true],
'$mobile_theme' => ['mobile_theme', DI::l10n()->t('Mobile Theme:'), $mobile_theme_selected, '', $mobile_themes, false],

View file

@ -25,6 +25,7 @@ use Friendica\Core\ACL;
use Friendica\Core\Hook;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\Theme;
use Friendica\Database\DBA;
use Friendica\DI;
@ -43,11 +44,11 @@ class Index extends BaseSettings
{
protected function post(array $request = [])
{
if (!local_user()) {
if (!Session::getLocalUser()) {
return;
}
$profile = Profile::getByUID(local_user());
$profile = Profile::getByUID(Session::getLocalUser());
if (!DBA::isResult($profile)) {
return;
}
@ -101,12 +102,12 @@ class Index extends BaseSettings
}
$profileFieldsNew = self::getProfileFieldsFromInput(
local_user(),
Session::getLocalUser(),
$_REQUEST['profile_field'],
$_REQUEST['profile_field_order']
);
DI::profileField()->saveCollectionForUser(local_user(), $profileFieldsNew);
DI::profileField()->saveCollectionForUser(Session::getLocalUser(), $profileFieldsNew);
$result = Profile::update(
[
@ -124,7 +125,7 @@ class Index extends BaseSettings
'pub_keywords' => $pub_keywords,
'prv_keywords' => $prv_keywords,
],
local_user()
Session::getLocalUser()
);
if (!$result) {
@ -137,7 +138,7 @@ class Index extends BaseSettings
protected function content(array $request = []): string
{
if (!local_user()) {
if (!Session::getLocalUser()) {
DI::sysmsg()->addNotice(DI::l10n()->t('You must be logged in to use this module'));
return Login::form();
}
@ -146,7 +147,7 @@ class Index extends BaseSettings
$o = '';
$profile = User::getOwnerDataById(local_user());
$profile = User::getOwnerDataById(Session::getLocalUser());
if (!DBA::isResult($profile)) {
throw new HTTPException\NotFoundException();
}
@ -158,7 +159,7 @@ class Index extends BaseSettings
$custom_fields = [];
$profileFields = DI::profileField()->selectByUserId(local_user());
$profileFields = DI::profileField()->selectByUserId(Session::getLocalUser());
foreach ($profileFields as $profileField) {
/** @var ProfileField $profileField */
$defaultPermissions = $profileField->permissionSet->withAllowedContacts(

View file

@ -58,7 +58,7 @@ class Crop extends BaseSettings
$path = 'profile/' . DI::app()->getLoggedInUserNickname();
$base_image = Photo::selectFirst([], ['resource-id' => $resource_id, 'uid' => local_user(), 'scale' => $scale]);
$base_image = Photo::selectFirst([], ['resource-id' => $resource_id, 'uid' => Session::getLocalUser(), 'scale' => $scale]);
if (DBA::isResult($base_image)) {
$Image = Photo::getImageForPhoto($base_image);
if (empty($Image)) {
@ -67,7 +67,7 @@ class Crop extends BaseSettings
if ($Image->isValid()) {
// If setting for the default profile, unset the profile photo flag from any other photos I own
DBA::update('photo', ['profile' => 0], ['uid' => local_user()]);
DBA::update('photo', ['profile' => 0], ['uid' => Session::getLocalUser()]);
// Normalizing expected square crop parameters
$selectionW = $selectionH = min($selectionW, $selectionH);
@ -92,11 +92,11 @@ class Crop extends BaseSettings
$Image->scaleDown(300);
}
$condition = ['resource-id' => $resource_id, 'uid' => local_user(), 'contact-id' => 0];
$condition = ['resource-id' => $resource_id, 'uid' => Session::getLocalUser(), 'contact-id' => 0];
$r = Photo::store(
$Image,
local_user(),
Session::getLocalUser(),
0,
$resource_id,
$base_image['filename'],
@ -114,7 +114,7 @@ class Crop extends BaseSettings
$r = Photo::store(
$Image,
local_user(),
Session::getLocalUser(),
0,
$resource_id,
$base_image['filename'],
@ -132,7 +132,7 @@ class Crop extends BaseSettings
$r = Photo::store(
$Image,
local_user(),
Session::getLocalUser(),
0,
$resource_id,
$base_image['filename'],
@ -146,12 +146,12 @@ class Crop extends BaseSettings
Photo::update(['profile' => true], array_merge($condition, ['scale' => 6]));
}
Contact::updateSelfFromUserID(local_user(), true);
Contact::updateSelfFromUserID(Session::getLocalUser(), true);
DI::sysmsg()->addInfo(DI::l10n()->t('Shift-reload the page or clear browser cache if the new photo does not display immediately.'));
// Update global directory in background
Profile::publishUpdate(local_user());
Profile::publishUpdate(Session::getLocalUser());
} else {
DI::sysmsg()->addNotice(DI::l10n()->t('Unable to process image'));
}
@ -170,7 +170,7 @@ class Crop extends BaseSettings
$resource_id = $this->parameters['guid'];
$photos = Photo::selectToArray([], ['resource-id' => $resource_id, 'uid' => local_user()], ['order' => ['scale' => false]]);
$photos = Photo::selectToArray([], ['resource-id' => $resource_id, 'uid' => Session::getLocalUser()], ['order' => ['scale' => false]]);
if (!DBA::isResult($photos)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('Photo not found.'));
}
@ -185,14 +185,14 @@ class Crop extends BaseSettings
// set an already uloaded photo as profile photo
// if photo is in 'Profile Photos', change it in db
if ($photos[0]['photo-type'] == Photo::USER_AVATAR && $havescale) {
Photo::update(['profile' => false], ['uid' => local_user()]);
Photo::update(['profile' => false], ['uid' => Session::getLocalUser()]);
Photo::update(['profile' => true], ['resource-id' => $resource_id, 'uid' => local_user()]);
Photo::update(['profile' => true], ['resource-id' => $resource_id, 'uid' => Session::getLocalUser()]);
Contact::updateSelfFromUserID(local_user(), true);
Contact::updateSelfFromUserID(Session::getLocalUser(), true);
// Update global directory in background
Profile::publishUpdate(local_user());
Profile::publishUpdate(Session::getLocalUser());
DI::sysmsg()->addInfo(DI::l10n()->t('Profile picture successfully updated.'));

View file

@ -92,13 +92,13 @@ class Index extends BaseSettings
$filename = '';
if (!Photo::store($Image, local_user(), 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 0, Photo::USER_AVATAR)) {
if (!Photo::store($Image, Session::getLocalUser(), 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 0, Photo::USER_AVATAR)) {
DI::sysmsg()->addNotice(DI::l10n()->t('Image upload failed.'));
}
if ($width > 640 || $height > 640) {
$Image->scaleDown(640);
if (!Photo::store($Image, local_user(), 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 1, Photo::USER_AVATAR)) {
if (!Photo::store($Image, Session::getLocalUser(), 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 1, Photo::USER_AVATAR)) {
DI::sysmsg()->addNotice(DI::l10n()->t('Image size reduction [%s] failed.', '640'));
}
}
@ -118,7 +118,7 @@ class Index extends BaseSettings
$newuser = $args->get($args->getArgc() - 1) === 'new';
$contact = Contact::selectFirst(['avatar'], ['uid' => local_user(), 'self' => true]);
$contact = Contact::selectFirst(['avatar'], ['uid' => Session::getLocalUser(), 'self' => true]);
$tpl = Renderer::getMarkupTemplate('settings/profile/photo/index.tpl');
$o = Renderer::replaceMacros($tpl, [

View file

@ -25,6 +25,7 @@ use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Module\Response;
use Friendica\Security\TwoFactor\Model\AppSpecificPassword;
@ -51,11 +52,11 @@ class AppSpecific extends BaseSettings
$this->pConfig = $pConfig;
if (!local_user()) {
if (!Session::getLocalUser()) {
return;
}
$verified = $this->pConfig->get(local_user(), '2fa', 'verified');
$verified = $this->pConfig->get(Session::getLocalUser(), '2fa', 'verified');
if (!$verified) {
$this->baseUrl->redirect('settings/2fa');
@ -69,7 +70,7 @@ class AppSpecific extends BaseSettings
protected function post(array $request = [])
{
if (!local_user()) {
if (!Session::getLocalUser()) {
return;
}
@ -82,17 +83,17 @@ class AppSpecific extends BaseSettings
if (empty($description)) {
DI::sysmsg()->addNotice($this->t('App-specific password generation failed: The description is empty.'));
$this->baseUrl->redirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password'));
} elseif (AppSpecificPassword::checkDuplicateForUser(local_user(), $description)) {
} elseif (AppSpecificPassword::checkDuplicateForUser(Session::getLocalUser(), $description)) {
DI::sysmsg()->addNotice($this->t('App-specific password generation failed: This description already exists.'));
$this->baseUrl->redirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password'));
} else {
$this->appSpecificPassword = AppSpecificPassword::generateForUser(local_user(), $_POST['description'] ?? '');
$this->appSpecificPassword = AppSpecificPassword::generateForUser(Session::getLocalUser(), $_POST['description'] ?? '');
DI::sysmsg()->addInfo($this->t('New app-specific password generated.'));
}
break;
case 'revoke_all' :
AppSpecificPassword::deleteAllForUser(local_user());
AppSpecificPassword::deleteAllForUser(Session::getLocalUser());
DI::sysmsg()->addInfo($this->t('App-specific passwords successfully revoked.'));
$this->baseUrl->redirect('settings/2fa/app_specific?t=' . self::getFormSecurityToken('settings_2fa_password'));
break;
@ -102,7 +103,7 @@ class AppSpecific extends BaseSettings
if (!empty($_POST['revoke_id'])) {
self::checkFormSecurityTokenRedirectOnError('settings/2fa/app_specific', 'settings_2fa_app_specific');
if (AppSpecificPassword::deleteForUser(local_user(), $_POST['revoke_id'])) {
if (AppSpecificPassword::deleteForUser(Session::getLocalUser(), $_POST['revoke_id'])) {
DI::sysmsg()->addInfo($this->t('App-specific password successfully revoked.'));
}
@ -112,13 +113,13 @@ class AppSpecific extends BaseSettings
protected function content(array $request = []): string
{
if (!local_user()) {
if (!Session::getLocalUser()) {
return Login::form('settings/2fa/app_specific');
}
parent::content();
$appSpecificPasswords = AppSpecificPassword::getListForUser(local_user());
$appSpecificPasswords = AppSpecificPassword::getListForUser(Session::getLocalUser());
return Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/twofactor/app_specific.tpl'), [
'$form_security_token' => self::getFormSecurityToken('settings_2fa_app_specific'),

View file

@ -22,6 +22,7 @@
namespace Friendica\Module\Settings\TwoFactor;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Network\HTTPException\FoundException;
use Friendica\Security\TwoFactor\Model\AppSpecificPassword;
@ -35,24 +36,24 @@ class Index extends BaseSettings
{
protected function post(array $request = [])
{
if (!local_user()) {
if (!Session::getLocalUser()) {
return;
}
self::checkFormSecurityTokenRedirectOnError('settings/2fa', 'settings_2fa');
try {
User::getIdFromPasswordAuthentication(local_user(), $_POST['password'] ?? '');
User::getIdFromPasswordAuthentication(Session::getLocalUser(), $_POST['password'] ?? '');
$has_secret = (bool)DI::pConfig()->get(local_user(), '2fa', 'secret');
$verified = DI::pConfig()->get(local_user(), '2fa', 'verified');
$has_secret = (bool)DI::pConfig()->get(Session::getLocalUser(), '2fa', 'secret');
$verified = DI::pConfig()->get(Session::getLocalUser(), '2fa', 'verified');
switch ($_POST['action'] ?? '') {
case 'enable':
if (!$has_secret && !$verified) {
$Google2FA = new Google2FA();
DI::pConfig()->set(local_user(), '2fa', 'secret', $Google2FA->generateSecretKey(32));
DI::pConfig()->set(Session::getLocalUser(), '2fa', 'secret', $Google2FA->generateSecretKey(32));
DI::baseUrl()
->redirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password'));
@ -60,9 +61,9 @@ class Index extends BaseSettings
break;
case 'disable':
if ($has_secret) {
RecoveryCode::deleteForUser(local_user());
DI::pConfig()->delete(local_user(), '2fa', 'secret');
DI::pConfig()->delete(local_user(), '2fa', 'verified');
RecoveryCode::deleteForUser(Session::getLocalUser());
DI::pConfig()->delete(Session::getLocalUser(), '2fa', 'secret');
DI::pConfig()->delete(Session::getLocalUser(), '2fa', 'verified');
DI::session()->remove('2fa');
DI::sysmsg()->addInfo(DI::l10n()->t('Two-factor authentication successfully disabled.'));
@ -103,14 +104,14 @@ class Index extends BaseSettings
protected function content(array $request = []): string
{
if (!local_user()) {
if (!Session::getLocalUser()) {
return Login::form('settings/2fa');
}
parent::content();
$has_secret = (bool) DI::pConfig()->get(local_user(), '2fa', 'secret');
$verified = DI::pConfig()->get(local_user(), '2fa', 'verified');
$has_secret = (bool) DI::pConfig()->get(Session::getLocalUser(), '2fa', 'secret');
$verified = DI::pConfig()->get(Session::getLocalUser(), '2fa', 'verified');
return Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/twofactor/index.tpl'), [
'$form_security_token' => self::getFormSecurityToken('settings_2fa'),
@ -128,12 +129,12 @@ class Index extends BaseSettings
'$recovery_codes_title' => DI::l10n()->t('Recovery codes'),
'$recovery_codes_remaining' => DI::l10n()->t('Remaining valid codes'),
'$recovery_codes_count' => RecoveryCode::countValidForUser(local_user()),
'$recovery_codes_count' => RecoveryCode::countValidForUser(Session::getLocalUser()),
'$recovery_codes_message' => DI::l10n()->t('<p>These one-use codes can replace an authenticator app code in case you have lost access to it.</p>'),
'$app_specific_passwords_title' => DI::l10n()->t('App-specific passwords'),
'$app_specific_passwords_remaining' => DI::l10n()->t('Generated app-specific passwords'),
'$app_specific_passwords_count' => AppSpecificPassword::countForUser(local_user()),
'$app_specific_passwords_count' => AppSpecificPassword::countForUser(Session::getLocalUser()),
'$app_specific_passwords_message' => DI::l10n()->t('<p>These randomly generated passwords allow you to authenticate on apps not supporting two-factor authentication.</p>'),
'$action_title' => DI::l10n()->t('Actions'),

View file

@ -25,6 +25,7 @@ use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Module\Response;
use Friendica\Security\TwoFactor\Model\RecoveryCode;
@ -49,11 +50,11 @@ class Recovery extends BaseSettings
$this->pConfig = $pConfig;
if (!local_user()) {
if (!Session::getLocalUser()) {
return;
}
$secret = $this->pConfig->get(local_user(), '2fa', 'secret');
$secret = $this->pConfig->get(Session::getLocalUser(), '2fa', 'secret');
if (!$secret) {
$this->baseUrl->redirect('settings/2fa');
@ -67,7 +68,7 @@ class Recovery extends BaseSettings
protected function post(array $request = [])
{
if (!local_user()) {
if (!Session::getLocalUser()) {
return;
}
@ -75,7 +76,7 @@ class Recovery extends BaseSettings
self::checkFormSecurityTokenRedirectOnError('settings/2fa/recovery', 'settings_2fa_recovery');
if ($_POST['action'] == 'regenerate') {
RecoveryCode::regenerateForUser(local_user());
RecoveryCode::regenerateForUser(Session::getLocalUser());
DI::sysmsg()->addInfo($this->t('New recovery codes successfully generated.'));
$this->baseUrl->redirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password'));
}
@ -84,19 +85,19 @@ class Recovery extends BaseSettings
protected function content(array $request = []): string
{
if (!local_user()) {
if (!Session::getLocalUser()) {
return Login::form('settings/2fa/recovery');
}
parent::content();
if (!RecoveryCode::countValidForUser(local_user())) {
RecoveryCode::generateForUser(local_user());
if (!RecoveryCode::countValidForUser(Session::getLocalUser())) {
RecoveryCode::generateForUser(Session::getLocalUser());
}
$recoveryCodes = RecoveryCode::getListForUser(local_user());
$recoveryCodes = RecoveryCode::getListForUser(Session::getLocalUser());
$verified = $this->pConfig->get(local_user(), '2fa', 'verified');
$verified = $this->pConfig->get(Session::getLocalUser(), '2fa', 'verified');
return Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/twofactor/recovery.tpl'), [
'$form_security_token' => self::getFormSecurityToken('settings_2fa_recovery'),

View file

@ -25,6 +25,7 @@ use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Module\BaseSettings;
use Friendica\Module\Response;
@ -52,11 +53,11 @@ class Trusted extends BaseSettings
$this->pConfig = $pConfig;
$this->trustedBrowserRepo = $trustedBrowserRepo;
if (!local_user()) {
if (!Session::getLocalUser()) {
return;
}
$verified = $this->pConfig->get(local_user(), '2fa', 'verified');
$verified = $this->pConfig->get(Session::getLocalUser(), '2fa', 'verified');
if (!$verified) {
$this->baseUrl->redirect('settings/2fa');
@ -70,7 +71,7 @@ class Trusted extends BaseSettings
protected function post(array $request = [])
{
if (!local_user()) {
if (!Session::getLocalUser()) {
return;
}
@ -79,7 +80,7 @@ class Trusted extends BaseSettings
switch ($_POST['action']) {
case 'remove_all':
$this->trustedBrowserRepo->removeAllForUser(local_user());
$this->trustedBrowserRepo->removeAllForUser(Session::getLocalUser());
DI::sysmsg()->addInfo($this->t('Trusted browsers successfully removed.'));
$this->baseUrl->redirect('settings/2fa/trusted?t=' . self::getFormSecurityToken('settings_2fa_password'));
break;
@ -89,7 +90,7 @@ class Trusted extends BaseSettings
if (!empty($_POST['remove_id'])) {
self::checkFormSecurityTokenRedirectOnError('settings/2fa/trusted', 'settings_2fa_trusted');
if ($this->trustedBrowserRepo->removeForUser(local_user(), $_POST['remove_id'])) {
if ($this->trustedBrowserRepo->removeForUser(Session::getLocalUser(), $_POST['remove_id'])) {
DI::sysmsg()->addInfo($this->t('Trusted browser successfully removed.'));
}
@ -102,7 +103,7 @@ class Trusted extends BaseSettings
{
parent::content();
$trustedBrowsers = $this->trustedBrowserRepo->selectAllByUid(local_user());
$trustedBrowsers = $this->trustedBrowserRepo->selectAllByUid(Session::getLocalUser());
$parser = Parser::create();

View file

@ -54,12 +54,12 @@ class Verify extends BaseSettings
$this->pConfig = $pConfig;
if (!local_user()) {
if (!Session::getLocalUser()) {
return;
}
$secret = $this->pConfig->get(local_user(), '2fa', 'secret');
$verified = $this->pConfig->get(local_user(), '2fa', 'verified');
$secret = $this->pConfig->get(Session::getLocalUser(), '2fa', 'secret');
$verified = $this->pConfig->get(Session::getLocalUser(), '2fa', 'verified');
if ($secret && $verified) {
$this->baseUrl->redirect('settings/2fa');
@ -73,7 +73,7 @@ class Verify extends BaseSettings
protected function post(array $request = [])
{
if (!local_user()) {
if (!Session::getLocalUser()) {
return;
}
@ -82,10 +82,10 @@ class Verify extends BaseSettings
$google2fa = new Google2FA();
$valid = $google2fa->verifyKey($this->pConfig->get(local_user(), '2fa', 'secret'), $_POST['verify_code'] ?? '');
$valid = $google2fa->verifyKey($this->pConfig->get(Session::getLocalUser(), '2fa', 'secret'), $_POST['verify_code'] ?? '');
if ($valid) {
$this->pConfig->set(local_user(), '2fa', 'verified', true);
$this->pConfig->set(Session::getLocalUser(), '2fa', 'verified', true);
DI::session()->set('2fa', true);
DI::sysmsg()->addInfo($this->t('Two-factor authentication successfully activated.'));
@ -99,7 +99,7 @@ class Verify extends BaseSettings
protected function content(array $request = []): string
{
if (!local_user()) {
if (!Session::getLocalUser()) {
return Login::form('settings/2fa/verify');
}
@ -107,7 +107,7 @@ class Verify extends BaseSettings
$company = 'Friendica';
$holder = DI::session()->get('my_address');
$secret = $this->pConfig->get(local_user(), '2fa', 'secret');
$secret = $this->pConfig->get(Session::getLocalUser(), '2fa', 'secret');
$otpauthUrl = (new Google2FA())->getQRCodeUrl($company, $holder, $secret);

View file

@ -24,6 +24,7 @@ namespace Friendica\Module\Settings;
use Friendica\App;
use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
@ -54,7 +55,7 @@ class UserExport extends BaseSettings
*/
protected function content(array $request = []): string
{
if (!local_user()) {
if (!Session::getLocalUser()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
@ -100,17 +101,17 @@ class UserExport extends BaseSettings
case "backup":
header("Content-type: application/json");
header('Content-Disposition: attachment; filename="' . DI::app()->getLoggedInUserNickname() . '.' . $action . '"');
self::exportAll(local_user());
self::exportAll(Session::getLocalUser());
break;
case "account":
header("Content-type: application/json");
header('Content-Disposition: attachment; filename="' . DI::app()->getLoggedInUserNickname() . '.' . $action . '"');
self::exportAccount(local_user());
self::exportAccount(Session::getLocalUser());
break;
case "contact":
header("Content-type: application/csv");
header('Content-Disposition: attachment; filename="' . DI::app()->getLoggedInUserNickname() . '-contacts.csv' . '"');
self::exportContactsAsCSV(local_user());
self::exportContactsAsCSV(Session::getLocalUser());
break;
}
System::exit();