]> git.mxchange.org Git - friendica.git/commitdiff
Move Login/Logout/TwoFactor to bundled submodule "Security"
authornupplaPhil <admin@philipp.info>
Fri, 27 Dec 2019 21:19:28 +0000 (22:19 +0100)
committernupplaPhil <admin@philipp.info>
Fri, 27 Dec 2019 21:19:28 +0000 (22:19 +0100)
31 files changed:
mod/api.php
mod/dfrn_poll.php
mod/dfrn_request.php
mod/events.php
mod/message.php
mod/network.php
mod/notifications.php
mod/oexchange.php
mod/profiles.php
mod/regmod.php
mod/settings.php
src/App.php
src/Module/Bookmarklet.php
src/Module/Contact.php
src/Module/Home.php
src/Module/Item/Compose.php
src/Module/Login.php [deleted file]
src/Module/Logout.php [deleted file]
src/Module/Profile.php
src/Module/Search/Directory.php
src/Module/Security/Login.php [new file with mode: 0644]
src/Module/Security/Logout.php [new file with mode: 0644]
src/Module/Security/TwoFactor/Recovery.php [new file with mode: 0644]
src/Module/Security/TwoFactor/Verify.php [new file with mode: 0644]
src/Module/Settings/TwoFactor/AppSpecific.php
src/Module/Settings/TwoFactor/Index.php
src/Module/Settings/TwoFactor/Recovery.php
src/Module/Settings/TwoFactor/Verify.php
src/Module/TwoFactor/Recovery.php [deleted file]
src/Module/TwoFactor/Verify.php [deleted file]
static/routes.config.php

index 9a802b515a6a1a0f1cd7a504336f38c7e3e5e532..929832480ac228087fde92d3f0969c2bf18c8873 100644 (file)
@@ -8,7 +8,7 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 
 require_once __DIR__ . '/../include/api.php';
 
index 8479217195e5921fcfd890637c99a5b9ac1647cb..0641b9177b4d20030ddaf19c8209060efb2eb6c3 100644 (file)
@@ -13,7 +13,7 @@ use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\Core\Session;
 use Friendica\Database\DBA;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 use Friendica\Protocol\DFRN;
 use Friendica\Protocol\OStatus;
 use Friendica\Util\Network;
index a9e17b34b362decab98f55913894bbfcac387bba..28845634ad8cdfa5474856587aa26ed824e94447 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Model\Contact;
 use Friendica\Model\Group;
 use Friendica\Model\Profile;
 use Friendica\Model\User;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 use Friendica\Network\Probe;
 use Friendica\Protocol\Activity;
 use Friendica\Util\DateTimeFormat;
index 5e129aaf6105b8936b8e4e09e4dfdd52e0017146..6547a9b9cecbb13993645ee9b0962b7248a1c00a 100644 (file)
@@ -19,7 +19,7 @@ use Friendica\Database\DBA;
 use Friendica\Model\Event;
 use Friendica\Model\Item;
 use Friendica\Model\Profile;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 use Friendica\Util\ACLFormatter;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
index 393d5d276bdee950a8ca48049e4b1ede011d5121..8efe825cd96795faff5c3a566eef723ce5b6d728 100644 (file)
@@ -15,7 +15,7 @@ use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Mail;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
index 44c7c8b44f9aa4859baf0d606cbee35e7ac1465c..5d8656cd354ffde73742132d2b3272292c784fea 100644 (file)
@@ -27,7 +27,7 @@ use Friendica\Model\Group;
 use Friendica\Model\Item;
 use Friendica\Model\Profile;
 use Friendica\Model\Term;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Strings;
index 90036705bc9d1eb33bf5f307ed888753ffdaa032..502a2397def8385540e6dfebdc89e0c466fd9adc 100644 (file)
@@ -13,7 +13,7 @@ use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 use Friendica\Model\Introduction;
 use Friendica\Model\Notify;
 
index e042a22f52038f9a47b4fe7f7edc821c429ea356..a55ee56d21d90bb74f8cc460208f5049ac4b6267 100644 (file)
@@ -6,7 +6,7 @@ use Friendica\App;
 use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
 use Friendica\Core\System;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
 
index d3a6c3e38a41d6e3da56d1c95408f55b4afd351d..46bc36db5313d8142f3b1c4815f534678a66ac84 100644 (file)
@@ -20,7 +20,7 @@ use Friendica\Model\Contact;
 use Friendica\Model\GContact;
 use Friendica\Model\Profile;
 use Friendica\Model\User;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 use Friendica\Network\Probe;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
index 295d8df25f5a02066c41d74376f8bdd0941f7bb4..ab03f939337afec9481f8c6b639dd7824b251509 100644 (file)
@@ -11,7 +11,7 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Model\Register;
 use Friendica\Model\User;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 
 function user_allow($hash)
 {
index 8b5254976d70fbbe0482d8ae400d532dbcebaac9..ad83b682104f76093b516ac22bbc63428dbef178 100644 (file)
@@ -24,7 +24,7 @@ use Friendica\Model\Contact;
 use Friendica\Model\GContact;
 use Friendica\Model\Group;
 use Friendica\Model\User;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 use Friendica\Protocol\Email;
 use Friendica\Util\ACLFormatter;
 use Friendica\Util\Network;
index 3325f5b260357694b0bc81d590cd48abe31788d3..3ea7d05f0c39bd27c6ee9894b16c0552cde9f9a9 100644 (file)
@@ -18,7 +18,7 @@ use Friendica\Core\System;
 use Friendica\Core\Theme;
 use Friendica\Database\Database;
 use Friendica\Model\Profile;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 use Friendica\Module\Special\HTTPException as ModuleHTTPException;
 use Friendica\Network\HTTPException;
 use Friendica\Util\ConfigFileLoader;
index 08bac2c1d06bba6add18bc35c669e7b58a6dd4e1..2993c20a7b6b864ae7ad379ccebcfc3e9ae7235c 100644 (file)
@@ -5,6 +5,7 @@ namespace Friendica\Module;
 use Friendica\BaseModule;
 use Friendica\Core\ACL;
 use Friendica\Core\L10n;
+use Friendica\Module\Security\Login;
 use Friendica\Network\HTTPException;
 use Friendica\Util\Strings;
 
index 01af275864480e3f1e708d69b246d8571e6accd6..48bb9ba310802058e3bf5fc3db1b316539e0a0c3 100644 (file)
@@ -18,6 +18,7 @@ use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Model;
+use Friendica\Module\Security\Login;
 use Friendica\Network\HTTPException\BadRequestException;
 use Friendica\Network\HTTPException\NotFoundException;
 use Friendica\Network\Probe;
index e6fb8c349669b241f53b702300c65a22da60f4d1..8fdb613f9b0e0c63b75061047645c1a5a8683ea3 100644 (file)
@@ -6,6 +6,7 @@ use Friendica\BaseModule;
 use Friendica\Core\Hook;
 use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
+use Friendica\Module\Security\Login;
 
 /**
  * Home module - Landing page of the current node
index b9cda4863e28ab1999dbf8befa4a8bff5dc0ab37..ded41fe3925ff4befa9ac226bf87192821978221 100644 (file)
@@ -17,7 +17,7 @@ use Friendica\Model\FileTag;
 use Friendica\Model\Group;
 use Friendica\Model\Item;
 use Friendica\Model\User;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 use Friendica\Network\HTTPException\NotImplementedException;
 use Friendica\Util\ACLFormatter;
 use Friendica\Util\Crypto;
diff --git a/src/Module/Login.php b/src/Module/Login.php
deleted file mode 100644 (file)
index d7c5378..0000000
+++ /dev/null
@@ -1,217 +0,0 @@
-<?php
-
-/**
- * @file src/Module/Login.php
- */
-
-namespace Friendica\Module;
-
-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\Util\Strings;
-
-/**
- * Login module
- *
- * @author Hypolite Petovan <hypolite@mrpetovan.com>
- */
-class Login extends BaseModule
-{
-       public static function content(array $parameters = [])
-       {
-               $a = self::getApp();
-
-               if (local_user()) {
-                       $a->internalRedirect();
-               }
-
-               return self::form(Session::get('return_path'), intval(Config::get('config', 'register_policy')) !== \Friendica\Module\Register::CLOSED);
-       }
-
-       public static function post(array $parameters = [])
-       {
-               $return_path = Session::get('return_path');
-               Session::clear();
-               Session::set('return_path', $return_path);
-
-               // OpenId Login
-               if (
-                       empty($_POST['password'])
-                       && (!empty($_POST['openid_url'])
-                               || !empty($_POST['username']))
-               ) {
-                       $openid_url = trim(($_POST['openid_url'] ?? '') ?: $_POST['username']);
-
-                       /** @var Authentication $authentication */
-                       $authentication = self::getClass(Authentication::class);
-                       $authentication->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(),
-                               trim($_POST['username']),
-                               trim($_POST['password']),
-                               !empty($_POST['remember'])
-                       );
-               }
-       }
-
-       /**
-        * @brief 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
-        * @param bool   $register     If $register == true provide a registration link.
-        *                             This will most always depend on the value of config.register_policy.
-        * @param array  $hiddens      optional
-        *
-        * @return string Returns the complete html for inserting into the page
-        *
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
-        * @hooks 'login_hook' string $o
-        */
-       public static function form($return_path = null, $register = false, $hiddens = [])
-       {
-               $a = self::getApp();
-               $o = '';
-
-               $noid = Config::get('system', 'no_openid');
-
-               if ($noid) {
-                       Session::remove('openid_identity');
-                       Session::remove('openid_attributes');
-               }
-
-               $reg = false;
-               if ($register && intval($a->getConfig()->get('config', 'register_policy')) !== Register::CLOSED) {
-                       $reg = [
-                               'title' => L10n::t('Create a New Account'),
-                               'desc' => L10n::t('Register'),
-                               'url' => self::getRegisterURL()
-                       ];
-               }
-
-               if (is_null($return_path)) {
-                       $return_path = $a->query_string;
-               }
-
-               if (local_user()) {
-                       $tpl = Renderer::getMarkupTemplate('logout.tpl');
-               } else {
-                       $a->page['htmlhead'] .= Renderer::replaceMacros(
-                               Renderer::getMarkupTemplate('login_head.tpl'),
-                               [
-                                       '$baseurl' => $a->getBaseURL(true)
-                               ]
-                       );
-
-                       $tpl = Renderer::getMarkupTemplate('login.tpl');
-                       $_SESSION['return_path'] = $return_path;
-               }
-
-               if (!empty(Session::get('openid_identity'))) {
-                       $openid_title = 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.');
-               } else {
-                       $openid_title = L10n::t('Or login using OpenID: ');
-                       $openid_readonly = false;
-                       $identity = '';
-                       $username_desc = '';
-               }
-
-               $o .= Renderer::replaceMacros(
-                       $tpl,
-                       [
-                               '$dest_url'     => self::getApp()->getBaseURL(true) . '/login',
-                               '$logout'       => L10n::t('Logout'),
-                               '$login'        => L10n::t('Login'),
-
-                               '$lname'        => ['username', L10n::t('Nickname or Email: '), '', $username_desc],
-                               '$lpassword'    => ['password', L10n::t('Password: '), '', ''],
-                               '$lremember'    => ['remember', L10n::t('Remember me'), 0,  ''],
-
-                               '$openid'       => !$noid,
-                               '$lopenid'      => ['openid_url', $openid_title, $identity, '', $openid_readonly],
-
-                               '$hiddens'      => $hiddens,
-
-                               '$register'     => $reg,
-
-                               '$lostpass'     => L10n::t('Forgot your password?'),
-                               '$lostlink'     => L10n::t('Password Reset'),
-
-                               '$tostitle'     => L10n::t('Website Terms of Service'),
-                               '$toslink'      => L10n::t('terms of service'),
-
-                               '$privacytitle' => L10n::t('Website Privacy Policy'),
-                               '$privacylink'  => L10n::t('privacy policy'),
-                       ]
-               );
-
-               Hook::callAll('login_hook', $o);
-
-               return $o;
-       }
-
-       /**
-        * Get the URL to the register page and add OpenID parameters to it
-        */
-       private static function getRegisterURL()
-       {
-               if (empty(Session::get('openid_identity'))) {
-                       return 'register';
-               }
-
-               $args = [];
-               $attr = Session::get('openid_attributes', []);
-
-               if (is_array($attr) && count($attr)) {
-                       foreach ($attr as $k => $v) {
-                               if ($k === 'namePerson/friendly') {
-                                       $nick = Strings::escapeTags(trim($v));
-                               }
-                               if ($k === 'namePerson/first') {
-                                       $first = Strings::escapeTags(trim($v));
-                               }
-                               if ($k === 'namePerson') {
-                                       $args['username'] = Strings::escapeTags(trim($v));
-                               }
-                               if ($k === 'contact/email') {
-                                       $args['email'] = Strings::escapeTags(trim($v));
-                               }
-                               if ($k === 'media/image/aspect11') {
-                                       $photosq = bin2hex(trim($v));
-                               }
-                               if ($k === 'media/image/default') {
-                                       $photo = bin2hex(trim($v));
-                               }
-                       }
-               }
-
-               if (!empty($nick)) {
-                       $args['nickname'] = $nick;
-               } elseif (!empty($first)) {
-                       $args['nickname'] = $first;
-               }
-
-               if (!empty($photosq)) {
-                       $args['photo'] = $photosq;
-               } elseif (!empty($photo)) {
-                       $args['photo'] = $photo;
-               }
-
-               $args['openid_url'] = Strings::escapeTags(trim(Session::get('openid_identity')));
-
-               return 'register?' . http_build_query($args);
-       }
-}
diff --git a/src/Module/Logout.php b/src/Module/Logout.php
deleted file mode 100644 (file)
index 9e6c674..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-/**
- * @file src/Module/Logout.php
- */
-
-namespace Friendica\Module;
-
-use Friendica\BaseModule;
-use Friendica\App\Authentication;
-use Friendica\Core\Cache;
-use Friendica\Core\Hook;
-use Friendica\Core\L10n;
-use Friendica\Core\Session;
-use Friendica\Core\System;
-use Friendica\Model\Profile;
-
-/**
- * Logout module
- *
- * @author Hypolite Petovan <hypolite@mrpetovan.com>
- */
-class Logout extends BaseModule
-{
-       /**
-        * @brief Process logout requests
-        */
-       public static function init(array $parameters = [])
-       {
-               $visitor_home = null;
-               if (remote_user()) {
-                       $visitor_home = Profile::getMyURL();
-                       Cache::delete('zrlInit:' . $visitor_home);
-               }
-
-               Hook::callAll("logging_out");
-               Session::clear();
-
-               if ($visitor_home) {
-                       System::externalRedirect($visitor_home);
-               } else {
-                       info(L10n::t('Logged out.'));
-                       self::getApp()->internalRedirect();
-               }
-       }
-}
index db1a6f86b3db44e4674aeb8394772f12d6373df0..d399ba8ddf4f82c6538d4e882313da59ce025f21 100644 (file)
@@ -19,6 +19,7 @@ use Friendica\Model\Group;
 use Friendica\Model\Item;
 use Friendica\Model\Profile as ProfileModel;
 use Friendica\Model\User;
+use Friendica\Module\Security\Login;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Protocol\DFRN;
 use Friendica\Util\DateTimeFormat;
index e3515713f55a57d10d05766951926534e6ae50d0..f9988c00492b44094fd1b3f117a62a2029bf8bdb 100644 (file)
@@ -5,7 +5,7 @@ namespace Friendica\Module\Search;
 use Friendica\Content\Widget;
 use Friendica\Core\L10n;
 use Friendica\Module\BaseSearchModule;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 use Friendica\Util\Strings;
 
 /**
diff --git a/src/Module/Security/Login.php b/src/Module/Security/Login.php
new file mode 100644 (file)
index 0000000..311cbdd
--- /dev/null
@@ -0,0 +1,218 @@
+<?php
+
+/**
+ * @file src/Module/Login.php
+ */
+
+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\Module\Register;
+use Friendica\Util\Strings;
+
+/**
+ * Login module
+ *
+ * @author Hypolite Petovan <hypolite@mrpetovan.com>
+ */
+class Login extends BaseModule
+{
+       public static function content(array $parameters = [])
+       {
+               $a = self::getApp();
+
+               if (local_user()) {
+                       $a->internalRedirect();
+               }
+
+               return self::form(Session::get('return_path'), intval(Config::get('config', 'register_policy')) !== \Friendica\Module\Register::CLOSED);
+       }
+
+       public static function post(array $parameters = [])
+       {
+               $return_path = Session::get('return_path');
+               Session::clear();
+               Session::set('return_path', $return_path);
+
+               // OpenId Login
+               if (
+                       empty($_POST['password'])
+                       && (!empty($_POST['openid_url'])
+                               || !empty($_POST['username']))
+               ) {
+                       $openid_url = trim(($_POST['openid_url'] ?? '') ?: $_POST['username']);
+
+                       /** @var Authentication $authentication */
+                       $authentication = self::getClass(Authentication::class);
+                       $authentication->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(),
+                               trim($_POST['username']),
+                               trim($_POST['password']),
+                               !empty($_POST['remember'])
+                       );
+               }
+       }
+
+       /**
+        * @brief 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
+        * @param bool   $register     If $register == true provide a registration link.
+        *                             This will most always depend on the value of config.register_policy.
+        * @param array  $hiddens      optional
+        *
+        * @return string Returns the complete html for inserting into the page
+        *
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @hooks 'login_hook' string $o
+        */
+       public static function form($return_path = null, $register = false, $hiddens = [])
+       {
+               $a = self::getApp();
+               $o = '';
+
+               $noid = Config::get('system', 'no_openid');
+
+               if ($noid) {
+                       Session::remove('openid_identity');
+                       Session::remove('openid_attributes');
+               }
+
+               $reg = false;
+               if ($register && intval($a->getConfig()->get('config', 'register_policy')) !== Register::CLOSED) {
+                       $reg = [
+                               'title' => L10n::t('Create a New Account'),
+                               'desc' => L10n::t('Register'),
+                               'url' => self::getRegisterURL()
+                       ];
+               }
+
+               if (is_null($return_path)) {
+                       $return_path = $a->query_string;
+               }
+
+               if (local_user()) {
+                       $tpl = Renderer::getMarkupTemplate('logout.tpl');
+               } else {
+                       $a->page['htmlhead'] .= Renderer::replaceMacros(
+                               Renderer::getMarkupTemplate('login_head.tpl'),
+                               [
+                                       '$baseurl' => $a->getBaseURL(true)
+                               ]
+                       );
+
+                       $tpl = Renderer::getMarkupTemplate('login.tpl');
+                       $_SESSION['return_path'] = $return_path;
+               }
+
+               if (!empty(Session::get('openid_identity'))) {
+                       $openid_title = 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.');
+               } else {
+                       $openid_title = L10n::t('Or login using OpenID: ');
+                       $openid_readonly = false;
+                       $identity = '';
+                       $username_desc = '';
+               }
+
+               $o .= Renderer::replaceMacros(
+                       $tpl,
+                       [
+                               '$dest_url'     => self::getApp()->getBaseURL(true) . '/login',
+                               '$logout'       => L10n::t('Logout'),
+                               '$login'        => L10n::t('Login'),
+
+                               '$lname'        => ['username', L10n::t('Nickname or Email: '), '', $username_desc],
+                               '$lpassword'    => ['password', L10n::t('Password: '), '', ''],
+                               '$lremember'    => ['remember', L10n::t('Remember me'), 0,  ''],
+
+                               '$openid'       => !$noid,
+                               '$lopenid'      => ['openid_url', $openid_title, $identity, '', $openid_readonly],
+
+                               '$hiddens'      => $hiddens,
+
+                               '$register'     => $reg,
+
+                               '$lostpass'     => L10n::t('Forgot your password?'),
+                               '$lostlink'     => L10n::t('Password Reset'),
+
+                               '$tostitle'     => L10n::t('Website Terms of Service'),
+                               '$toslink'      => L10n::t('terms of service'),
+
+                               '$privacytitle' => L10n::t('Website Privacy Policy'),
+                               '$privacylink'  => L10n::t('privacy policy'),
+                       ]
+               );
+
+               Hook::callAll('login_hook', $o);
+
+               return $o;
+       }
+
+       /**
+        * Get the URL to the register page and add OpenID parameters to it
+        */
+       private static function getRegisterURL()
+       {
+               if (empty(Session::get('openid_identity'))) {
+                       return 'register';
+               }
+
+               $args = [];
+               $attr = Session::get('openid_attributes', []);
+
+               if (is_array($attr) && count($attr)) {
+                       foreach ($attr as $k => $v) {
+                               if ($k === 'namePerson/friendly') {
+                                       $nick = Strings::escapeTags(trim($v));
+                               }
+                               if ($k === 'namePerson/first') {
+                                       $first = Strings::escapeTags(trim($v));
+                               }
+                               if ($k === 'namePerson') {
+                                       $args['username'] = Strings::escapeTags(trim($v));
+                               }
+                               if ($k === 'contact/email') {
+                                       $args['email'] = Strings::escapeTags(trim($v));
+                               }
+                               if ($k === 'media/image/aspect11') {
+                                       $photosq = bin2hex(trim($v));
+                               }
+                               if ($k === 'media/image/default') {
+                                       $photo = bin2hex(trim($v));
+                               }
+                       }
+               }
+
+               if (!empty($nick)) {
+                       $args['nickname'] = $nick;
+               } elseif (!empty($first)) {
+                       $args['nickname'] = $first;
+               }
+
+               if (!empty($photosq)) {
+                       $args['photo'] = $photosq;
+               } elseif (!empty($photo)) {
+                       $args['photo'] = $photo;
+               }
+
+               $args['openid_url'] = Strings::escapeTags(trim(Session::get('openid_identity')));
+
+               return 'register?' . http_build_query($args);
+       }
+}
diff --git a/src/Module/Security/Logout.php b/src/Module/Security/Logout.php
new file mode 100644 (file)
index 0000000..062d556
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+/**
+ * @file src/Module/Logout.php
+ */
+
+namespace Friendica\Module\Security;
+
+use Friendica\BaseModule;
+use Friendica\App\Authentication;
+use Friendica\Core\Cache;
+use Friendica\Core\Hook;
+use Friendica\Core\L10n;
+use Friendica\Core\Session;
+use Friendica\Core\System;
+use Friendica\Model\Profile;
+
+/**
+ * Logout module
+ *
+ * @author Hypolite Petovan <hypolite@mrpetovan.com>
+ */
+class Logout extends BaseModule
+{
+       /**
+        * @brief Process logout requests
+        */
+       public static function init(array $parameters = [])
+       {
+               $visitor_home = null;
+               if (remote_user()) {
+                       $visitor_home = Profile::getMyURL();
+                       Cache::delete('zrlInit:' . $visitor_home);
+               }
+
+               Hook::callAll("logging_out");
+               Session::clear();
+
+               if ($visitor_home) {
+                       System::externalRedirect($visitor_home);
+               } else {
+                       info(L10n::t('Logged out.'));
+                       self::getApp()->internalRedirect();
+               }
+       }
+}
diff --git a/src/Module/Security/TwoFactor/Recovery.php b/src/Module/Security/TwoFactor/Recovery.php
new file mode 100644 (file)
index 0000000..90e1488
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+
+namespace Friendica\Module\Security\TwoFactor;
+
+use Friendica\BaseModule;
+use Friendica\App\Authentication;
+use Friendica\Core\L10n;
+use Friendica\Core\Renderer;
+use Friendica\Core\Session;
+use Friendica\Model\TwoFactor\RecoveryCode;
+
+/**
+ * // Page 1a: Recovery code verification
+ *
+ * @package Friendica\Module\TwoFactor
+ */
+class Recovery extends BaseModule
+{
+       public static function init(array $parameters = [])
+       {
+               if (!local_user()) {
+                       return;
+               }
+       }
+
+       public static function post(array $parameters = [])
+       {
+               if (!local_user()) {
+                       return;
+               }
+
+               if (($_POST['action'] ?? '') == 'recover') {
+                       self::checkFormSecurityTokenRedirectOnError('2fa', 'twofactor_recovery');
+
+                       $a = self::getApp();
+
+                       $recovery_code = $_POST['recovery_code'] ?? '';
+
+                       if (RecoveryCode::existsForUser(local_user(), $recovery_code)) {
+                               RecoveryCode::markUsedForUser(local_user(), $recovery_code);
+                               Session::set('2fa', true);
+                               notice(L10n::t('Remaining recovery codes: %d', RecoveryCode::countValidForUser(local_user())));
+
+                               // Resume normal login workflow
+                               /** @var Authentication $authentication */
+                               $authentication = self::getClass(Authentication::class);
+                               $authentication->setForUser($a, $a->user, true, true);
+                       } else {
+                               notice(L10n::t('Invalid code, please retry.'));
+                       }
+               }
+       }
+
+       public static function content(array $parameters = [])
+       {
+               if (!local_user()) {
+                       self::getApp()->internalRedirect();
+               }
+
+               // Already authenticated with 2FA token
+               if (Session::get('2fa')) {
+                       self::getApp()->internalRedirect();
+               }
+
+               return Renderer::replaceMacros(Renderer::getMarkupTemplate('twofactor/recovery.tpl'), [
+                       '$form_security_token' => self::getFormSecurityToken('twofactor_recovery'),
+
+                       '$title'            => L10n::t('Two-factor recovery'),
+                       '$message'          => L10n::t('<p>You can enter one of your one-time recovery codes in case you lost access to your mobile device.</p>'),
+                       '$recovery_message' => L10n::t('Don’t have your phone? <a href="%s">Enter a two-factor recovery code</a>', '2fa/recovery'),
+                       '$recovery_code'    => ['recovery_code', L10n::t('Please enter a recovery code'), '', '', '', 'placeholder="000000-000000"'],
+                       '$recovery_label'   => L10n::t('Submit recovery code and complete login'),
+               ]);
+       }
+}
diff --git a/src/Module/Security/TwoFactor/Verify.php b/src/Module/Security/TwoFactor/Verify.php
new file mode 100644 (file)
index 0000000..10327ae
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+
+namespace Friendica\Module\Security\TwoFactor;
+
+use Friendica\BaseModule;
+use Friendica\App\Authentication;
+use Friendica\Core\L10n;
+use Friendica\Core\PConfig;
+use Friendica\Core\Renderer;
+use Friendica\Core\Session;
+use PragmaRX\Google2FA\Google2FA;
+
+/**
+ * Page 1: Authenticator code verification
+ *
+ * @package Friendica\Module\TwoFactor
+ */
+class Verify extends BaseModule
+{
+       private static $errors = [];
+
+       public static function post(array $parameters = [])
+       {
+               if (!local_user()) {
+                       return;
+               }
+
+               if (($_POST['action'] ?? '') == 'verify') {
+                       self::checkFormSecurityTokenRedirectOnError('2fa', 'twofactor_verify');
+
+                       $a = self::getApp();
+
+                       $code = $_POST['verify_code'] ?? '';
+
+                       $valid = (new Google2FA())->verifyKey(PConfig::get(local_user(), '2fa', 'secret'), $code);
+
+                       // The same code can't be used twice even if it's valid
+                       if ($valid && Session::get('2fa') !== $code) {
+                               Session::set('2fa', $code);
+
+                               // Resume normal login workflow
+                               /** @var Authentication $authentication */
+                               $authentication = self::getClass(Authentication::class);
+                               $authentication->setForUser($a, $a->user, true, true);
+                       } else {
+                               self::$errors[] = L10n::t('Invalid code, please retry.');
+                       }
+               }
+       }
+
+       public static function content(array $parameters = [])
+       {
+               if (!local_user()) {
+                       self::getApp()->internalRedirect();
+               }
+
+               // Already authenticated with 2FA token
+               if (Session::get('2fa')) {
+                       self::getApp()->internalRedirect();
+               }
+
+               return Renderer::replaceMacros(Renderer::getMarkupTemplate('twofactor/verify.tpl'), [
+                       '$form_security_token' => self::getFormSecurityToken('twofactor_verify'),
+
+                       '$title'            => L10n::t('Two-factor authentication'),
+                       '$message'          => L10n::t('<p>Open the two-factor authentication app on your device to get an authentication code and verify your identity.</p>'),
+                       '$errors_label'     => L10n::tt('Error', 'Errors', count(self::$errors)),
+                       '$errors'           => self::$errors,
+                       '$recovery_message' => L10n::t('Don’t have your phone? <a href="%s">Enter a two-factor recovery code</a>', '2fa/recovery'),
+                       '$verify_code'      => ['verify_code', L10n::t('Please enter a code from your authentication app'), '', '', 'required', 'autofocus placeholder="000000"', 'tel'],
+                       '$verify_label'     => L10n::t('Verify code and complete login'),
+               ]);
+       }
+}
index 72b233f422f094483c9fa9ebfc93fff1dc999a72..fe7423c5d214ea7a6bc1d9e1bff5ee78962b3fe2 100644 (file)
@@ -9,7 +9,7 @@ use Friendica\Core\PConfig;
 use Friendica\Core\Renderer;
 use Friendica\Model\TwoFactor\AppSpecificPassword;
 use Friendica\Module\BaseSettingsModule;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 
 /**
  * // Page 5: 2FA enabled, app-specific password generation
index 34d6f97b49c0092e5c0425872795e192bc3402d2..03c866ce89ceb3bedbf136312bd480d2f06930bf 100644 (file)
@@ -12,7 +12,7 @@ use Friendica\Model\TwoFactor\AppSpecificPassword;
 use Friendica\Model\TwoFactor\RecoveryCode;
 use Friendica\Model\User;
 use Friendica\Module\BaseSettingsModule;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 use PragmaRX\Google2FA\Google2FA;
 
 class Index extends BaseSettingsModule
index 0d7de7d9023a0eccdb3c60196e41e82facb54fdb..8bd40bec980d81f285b8efd8a0b16c77872f5931 100644 (file)
@@ -9,7 +9,7 @@ use Friendica\Core\PConfig;
 use Friendica\Core\Renderer;
 use Friendica\Model\TwoFactor\RecoveryCode;
 use Friendica\Module\BaseSettingsModule;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 
 /**
  * // Page 3: 2FA enabled but not verified, show recovery codes
index 63c186e3a8f6129a613607ac77dbcb9d65c15a44..28ee999d142bc9bd94788bdc0a8880c164311be2 100644 (file)
@@ -14,7 +14,7 @@ use Friendica\Core\PConfig;
 use Friendica\Core\Renderer;
 use Friendica\Core\Session;
 use Friendica\Module\BaseSettingsModule;
-use Friendica\Module\Login;
+use Friendica\Module\Security\Login;
 use PragmaRX\Google2FA\Google2FA;
 
 /**
diff --git a/src/Module/TwoFactor/Recovery.php b/src/Module/TwoFactor/Recovery.php
deleted file mode 100644 (file)
index 371b7d7..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-<?php
-
-namespace Friendica\Module\TwoFactor;
-
-use Friendica\BaseModule;
-use Friendica\App\Authentication;
-use Friendica\Core\L10n;
-use Friendica\Core\Renderer;
-use Friendica\Core\Session;
-use Friendica\Model\TwoFactor\RecoveryCode;
-
-/**
- * // Page 1a: Recovery code verification
- *
- * @package Friendica\Module\TwoFactor
- */
-class Recovery extends BaseModule
-{
-       public static function init(array $parameters = [])
-       {
-               if (!local_user()) {
-                       return;
-               }
-       }
-
-       public static function post(array $parameters = [])
-       {
-               if (!local_user()) {
-                       return;
-               }
-
-               if (($_POST['action'] ?? '') == 'recover') {
-                       self::checkFormSecurityTokenRedirectOnError('2fa', 'twofactor_recovery');
-
-                       $a = self::getApp();
-
-                       $recovery_code = $_POST['recovery_code'] ?? '';
-
-                       if (RecoveryCode::existsForUser(local_user(), $recovery_code)) {
-                               RecoveryCode::markUsedForUser(local_user(), $recovery_code);
-                               Session::set('2fa', true);
-                               notice(L10n::t('Remaining recovery codes: %d', RecoveryCode::countValidForUser(local_user())));
-
-                               // Resume normal login workflow
-                               /** @var Authentication $authentication */
-                               $authentication = self::getClass(Authentication::class);
-                               $authentication->setForUser($a, $a->user, true, true);
-                       } else {
-                               notice(L10n::t('Invalid code, please retry.'));
-                       }
-               }
-       }
-
-       public static function content(array $parameters = [])
-       {
-               if (!local_user()) {
-                       self::getApp()->internalRedirect();
-               }
-
-               // Already authenticated with 2FA token
-               if (Session::get('2fa')) {
-                       self::getApp()->internalRedirect();
-               }
-
-               return Renderer::replaceMacros(Renderer::getMarkupTemplate('twofactor/recovery.tpl'), [
-                       '$form_security_token' => self::getFormSecurityToken('twofactor_recovery'),
-
-                       '$title'            => L10n::t('Two-factor recovery'),
-                       '$message'          => L10n::t('<p>You can enter one of your one-time recovery codes in case you lost access to your mobile device.</p>'),
-                       '$recovery_message' => L10n::t('Don’t have your phone? <a href="%s">Enter a two-factor recovery code</a>', '2fa/recovery'),
-                       '$recovery_code'    => ['recovery_code', L10n::t('Please enter a recovery code'), '', '', '', 'placeholder="000000-000000"'],
-                       '$recovery_label'   => L10n::t('Submit recovery code and complete login'),
-               ]);
-       }
-}
diff --git a/src/Module/TwoFactor/Verify.php b/src/Module/TwoFactor/Verify.php
deleted file mode 100644 (file)
index 828f125..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-
-namespace Friendica\Module\TwoFactor;
-
-use Friendica\BaseModule;
-use Friendica\App\Authentication;
-use Friendica\Core\L10n;
-use Friendica\Core\PConfig;
-use Friendica\Core\Renderer;
-use Friendica\Core\Session;
-use PragmaRX\Google2FA\Google2FA;
-
-/**
- * Page 1: Authenticator code verification
- *
- * @package Friendica\Module\TwoFactor
- */
-class Verify extends BaseModule
-{
-       private static $errors = [];
-
-       public static function post(array $parameters = [])
-       {
-               if (!local_user()) {
-                       return;
-               }
-
-               if (($_POST['action'] ?? '') == 'verify') {
-                       self::checkFormSecurityTokenRedirectOnError('2fa', 'twofactor_verify');
-
-                       $a = self::getApp();
-
-                       $code = $_POST['verify_code'] ?? '';
-
-                       $valid = (new Google2FA())->verifyKey(PConfig::get(local_user(), '2fa', 'secret'), $code);
-
-                       // The same code can't be used twice even if it's valid
-                       if ($valid && Session::get('2fa') !== $code) {
-                               Session::set('2fa', $code);
-
-                               // Resume normal login workflow
-                               /** @var Authentication $authentication */
-                               $authentication = self::getClass(Authentication::class);
-                               $authentication->setForUser($a, $a->user, true, true);
-                       } else {
-                               self::$errors[] = L10n::t('Invalid code, please retry.');
-                       }
-               }
-       }
-
-       public static function content(array $parameters = [])
-       {
-               if (!local_user()) {
-                       self::getApp()->internalRedirect();
-               }
-
-               // Already authenticated with 2FA token
-               if (Session::get('2fa')) {
-                       self::getApp()->internalRedirect();
-               }
-
-               return Renderer::replaceMacros(Renderer::getMarkupTemplate('twofactor/verify.tpl'), [
-                       '$form_security_token' => self::getFormSecurityToken('twofactor_verify'),
-
-                       '$title'            => L10n::t('Two-factor authentication'),
-                       '$message'          => L10n::t('<p>Open the two-factor authentication app on your device to get an authentication code and verify your identity.</p>'),
-                       '$errors_label'     => L10n::tt('Error', 'Errors', count(self::$errors)),
-                       '$errors'           => self::$errors,
-                       '$recovery_message' => L10n::t('Don’t have your phone? <a href="%s">Enter a two-factor recovery code</a>', '2fa/recovery'),
-                       '$verify_code'      => ['verify_code', L10n::t('Please enter a code from your authentication app'), '', '', 'required', 'autofocus placeholder="000000"', 'tel'],
-                       '$verify_label'     => L10n::t('Verify code and complete login'),
-               ]);
-       }
-}
index 15e7383a4b69a5d6544f05a360e12233c78067bd..9dced33107d1d5684ecb1ba6f286d41222d12641 100644 (file)
@@ -23,8 +23,8 @@ return [
        ],
 
        '/2fa' => [
-               '[/]'       => [Module\TwoFactor\Verify::class,   [R::GET, R::POST]],
-               '/recovery' => [Module\TwoFactor\Recovery::class, [R::GET, R::POST]],
+               '[/]'       => [Module\Security\TwoFactor\Verify::class,   [R::GET, R::POST]],
+               '/recovery' => [Module\Security\TwoFactor\Recovery::class, [R::GET, R::POST]],
        ],
 
        '/api' => [
@@ -156,8 +156,8 @@ return [
 
        '/like/{item:\d+}'    => [Module\Like::class,            [R::GET]],
        '/localtime'          => [Module\Debug\Localtime::class, [R::GET, R::POST]],
-       '/login'              => [Module\Login::class,           [R::GET, R::POST]],
-       '/logout'             => [Module\Logout::class,          [R::GET, R::POST]],
+       '/login'              => [Module\Security\Login::class,  [R::GET, R::POST]],
+       '/logout'             => [Module\Security\Logout::class, [R::GET, R::POST]],
        '/magic'              => [Module\Magic::class,           [R::GET]],
        '/maintenance'        => [Module\Maintenance::class,     [R::GET]],
        '/manifest'           => [Module\Manifest::class,        [R::GET]],