X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FSecurity%2FLogin.php;h=080c3ef3caf9b4e2a40e98825d248c1ca363ba3a;hb=6dbbd081795fa1c8fe57db2248ac162efeeada88;hp=311cbdd9bbb69d0db9de0fb75bb495bd81c54353;hpb=25847c4c710a486c3a4c6ae80b7dd2e2e81250a6;p=friendica.git diff --git a/src/Module/Security/Login.php b/src/Module/Security/Login.php index 311cbdd9bb..080c3ef3ca 100644 --- a/src/Module/Security/Login.php +++ b/src/Module/Security/Login.php @@ -1,40 +1,52 @@ . + * */ namespace Friendica\Module\Security; use Friendica\BaseModule; -use Friendica\App\Authentication; -use Friendica\Core\Config; use Friendica\Core\Hook; -use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\Session; +use Friendica\DI; use Friendica\Module\Register; -use Friendica\Util\Strings; /** * Login module - * - * @author Hypolite Petovan */ class Login extends BaseModule { - public static function content(array $parameters = []) + protected function content(array $request = []): string { - $a = self::getApp(); + $return_path = $_REQUEST['return_path'] ?? '' ; if (local_user()) { - $a->internalRedirect(); + DI::baseUrl()->redirect($return_path); + } elseif (!empty($return_path)) { + Session::set('return_path', $return_path); } - return self::form(Session::get('return_path'), intval(Config::get('config', 'register_policy')) !== \Friendica\Module\Register::CLOSED); + return self::form(Session::get('return_path'), intval(DI::config()->get('config', 'register_policy')) !== \Friendica\Module\Register::CLOSED); } - public static function post(array $parameters = []) + protected function post(array $request = []) { $return_path = Session::get('return_path'); Session::clear(); @@ -48,16 +60,12 @@ class Login extends BaseModule ) { $openid_url = trim(($_POST['openid_url'] ?? '') ?: $_POST['username']); - /** @var Authentication $authentication */ - $authentication = self::getClass(Authentication::class); - $authentication->withOpenId($openid_url, !empty($_POST['remember'])); + DI::auth()->withOpenId($openid_url, !empty($_POST['remember'])); } if (!empty($_POST['auth-params']) && $_POST['auth-params'] === 'login') { - /** @var Authentication $authentication */ - $authentication = self::getClass(Authentication::class); - $authentication->withPassword( - self::getApp(), + DI::auth()->withPassword( + DI::app(), trim($_POST['username']), trim($_POST['password']), !empty($_POST['remember']) @@ -66,7 +74,7 @@ class Login extends BaseModule } /** - * @brief Wrapper for adding a login box. + * Wrapper for adding a login box. * * @param string $return_path The path relative to the base the user should be sent * back to after login completes @@ -81,10 +89,9 @@ class Login extends BaseModule */ public static function form($return_path = null, $register = false, $hiddens = []) { - $a = self::getApp(); $o = ''; - $noid = Config::get('system', 'no_openid'); + $noid = DI::config()->get('system', 'no_openid'); if ($noid) { Session::remove('openid_identity'); @@ -92,25 +99,25 @@ class Login extends BaseModule } $reg = false; - if ($register && intval($a->getConfig()->get('config', 'register_policy')) !== Register::CLOSED) { + if ($register && intval(DI::config()->get('config', 'register_policy')) !== Register::CLOSED) { $reg = [ - 'title' => L10n::t('Create a New Account'), - 'desc' => L10n::t('Register'), + 'title' => DI::l10n()->t('Create a New Account'), + 'desc' => DI::l10n()->t('Register'), 'url' => self::getRegisterURL() ]; } if (is_null($return_path)) { - $return_path = $a->query_string; + $return_path = DI::args()->getQueryString(); } if (local_user()) { $tpl = Renderer::getMarkupTemplate('logout.tpl'); } else { - $a->page['htmlhead'] .= Renderer::replaceMacros( + DI::page()['htmlhead'] .= Renderer::replaceMacros( Renderer::getMarkupTemplate('login_head.tpl'), [ - '$baseurl' => $a->getBaseURL(true) + '$baseurl' => DI::baseUrl()->get(true) ] ); @@ -119,12 +126,12 @@ class Login extends BaseModule } if (!empty(Session::get('openid_identity'))) { - $openid_title = L10n::t('Your OpenID: '); + $openid_title = DI::l10n()->t('Your OpenID: '); $openid_readonly = true; $identity = Session::get('openid_identity'); - $username_desc = L10n::t('Please enter your username and password to add the OpenID to your existing account.'); + $username_desc = DI::l10n()->t('Please enter your username and password to add the OpenID to your existing account.'); } else { - $openid_title = L10n::t('Or login using OpenID: '); + $openid_title = DI::l10n()->t('Or login using OpenID: '); $openid_readonly = false; $identity = ''; $username_desc = ''; @@ -133,13 +140,13 @@ class Login extends BaseModule $o .= Renderer::replaceMacros( $tpl, [ - '$dest_url' => self::getApp()->getBaseURL(true) . '/login', - '$logout' => L10n::t('Logout'), - '$login' => L10n::t('Login'), + '$dest_url' => DI::baseUrl()->get(true) . '/login', + '$logout' => DI::l10n()->t('Logout'), + '$login' => DI::l10n()->t('Login'), - '$lname' => ['username', L10n::t('Nickname or Email: '), '', $username_desc], - '$lpassword' => ['password', L10n::t('Password: '), '', ''], - '$lremember' => ['remember', L10n::t('Remember me'), 0, ''], + '$lname' => ['username', DI::l10n()->t('Nickname or Email: '), '', $username_desc], + '$lpassword' => ['password', DI::l10n()->t('Password: '), '', ''], + '$lremember' => ['remember', DI::l10n()->t('Remember me'), 0, ''], '$openid' => !$noid, '$lopenid' => ['openid_url', $openid_title, $identity, '', $openid_readonly], @@ -148,14 +155,14 @@ class Login extends BaseModule '$register' => $reg, - '$lostpass' => L10n::t('Forgot your password?'), - '$lostlink' => L10n::t('Password Reset'), + '$lostpass' => DI::l10n()->t('Forgot your password?'), + '$lostlink' => DI::l10n()->t('Password Reset'), - '$tostitle' => L10n::t('Website Terms of Service'), - '$toslink' => L10n::t('terms of service'), + '$tostitle' => DI::l10n()->t('Website Terms of Service'), + '$toslink' => DI::l10n()->t('terms of service'), - '$privacytitle' => L10n::t('Website Privacy Policy'), - '$privacylink' => L10n::t('privacy policy'), + '$privacytitle' => DI::l10n()->t('Website Privacy Policy'), + '$privacylink' => DI::l10n()->t('privacy policy'), ] ); @@ -179,16 +186,16 @@ class Login extends BaseModule if (is_array($attr) && count($attr)) { foreach ($attr as $k => $v) { if ($k === 'namePerson/friendly') { - $nick = Strings::escapeTags(trim($v)); + $nick = trim($v); } if ($k === 'namePerson/first') { - $first = Strings::escapeTags(trim($v)); + $first = trim($v); } if ($k === 'namePerson') { - $args['username'] = Strings::escapeTags(trim($v)); + $args['username'] = trim($v); } if ($k === 'contact/email') { - $args['email'] = Strings::escapeTags(trim($v)); + $args['email'] = trim($v); } if ($k === 'media/image/aspect11') { $photosq = bin2hex(trim($v)); @@ -211,7 +218,7 @@ class Login extends BaseModule $args['photo'] = $photo; } - $args['openid_url'] = Strings::escapeTags(trim(Session::get('openid_identity'))); + $args['openid_url'] = trim(Session::get('openid_identity')); return 'register?' . http_build_query($args); }