]> git.mxchange.org Git - friendica.git/blobdiff - mod/regmod.php
Merge pull request #8344 from MrPetovan/bug/8339-remote-follow-local-profile
[friendica.git] / mod / regmod.php
index 11d8eee412eadd013fb2b0197b825803db8baa2c..df1020b9f4df7652f659d963e7546cb9400163bb 100644 (file)
@@ -1,73 +1,67 @@
 <?php
 /**
- * @file mod/regmod.php
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @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/>.
+ *
  */
 
 use Friendica\App;
-use Friendica\Core\Config;
-use Friendica\Core\L10n;
-use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Model\Register;
 use Friendica\Model\User;
-use Friendica\Module\Login;
-
-require_once 'include/enotify.php';
+use Friendica\Module\Security\Login;
 
 function user_allow($hash)
 {
-       $a = get_app();
-
-       $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1",
-               DBA::escape($hash)
-       );
-
-
+       $register = Register::getByHash($hash);
        if (!DBA::isResult($register)) {
                return false;
        }
 
-       $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
-               intval($register[0]['uid'])
-       );
-
+       $user = User::getById($register['uid']);
        if (!DBA::isResult($user)) {
-               killme();
+               exit();
        }
 
-       $r = q("DELETE FROM `register` WHERE `hash` = '%s'",
-               DBA::escape($register[0]['hash'])
-       );
+       Register::deleteByHash($hash);
 
+       DBA::update('user', ['blocked' => false, 'verified' => true], ['uid' => $register['uid']]);
 
-       $r = q("UPDATE `user` SET `blocked` = 0, `verified` = 1 WHERE `uid` = %d",
-               intval($register[0]['uid'])
-       );
+       $profile = DBA::selectFirst('profile', ['net-publish'], ['uid' => $register['uid']]);
 
-       $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default` = 1",
-               intval($user[0]['uid'])
-       );
-       if (DBA::isResult($r) && $r[0]['net-publish']) {
-               $url = System::baseUrl() . '/profile/' . $user[0]['nickname'];
-               if ($url && strlen(Config::get('system', 'directory'))) {
-                       Worker::add(PRIORITY_LOW, "Directory", $url);
-               }
+       if (DBA::isResult($profile) && $profile['net-publish'] && DI::config()->get('system', 'directory')) {
+               $url = DI::baseUrl() . '/profile/' . $user['nickname'];
+               Worker::add(PRIORITY_LOW, "Directory", $url);
        }
 
-       L10n::pushLang($register[0]['language']);
+       $l10n = DI::l10n()->withLang($register['language']);
 
        $res = User::sendRegisterOpenEmail(
-               $user[0]['email'],
-               Config::get('config', 'sitename'),
-               System::baseUrl(),
-               $user[0]['username'],
-               $register[0]['password'],
-               $user[0]);
-
-       L10n::popLang();
+               $l10n,
+               $user,
+               DI::config()->get('config', 'sitename'),
+               DI::baseUrl()->get(),
+               ($register['password'] ?? '') ?: 'Sent in a previous email'
+       );
 
        if ($res) {
-               info(L10n::t('Account approved.') . EOL);
+               info(DI::l10n()->t('Account approved.') . EOL);
                return true;
        }
 }
@@ -77,40 +71,38 @@ function user_allow($hash)
 // allowed to have friends on this system
 function user_deny($hash)
 {
-       $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1",
-               DBA::escape($hash)
-       );
-
+       $register = Register::getByHash($hash);
        if (!DBA::isResult($register)) {
                return false;
        }
 
-       $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
-               intval($register[0]['uid'])
-       );
+       $user = User::getById($register['uid']);
+       if (!DBA::isResult($user)) {
+               exit();
+       }
+
+       DBA::delete('user', ['uid' => $register['uid']]);
 
-       DBA::delete('user', ['uid' => $register[0]['uid']]);
-       DBA::delete('register', ['hash' => $register[0]['hash']]);
+       Register::deleteByHash($register['hash']);
 
-       notice(L10n::t('Registration revoked for %s', $user[0]['username']) . EOL);
+       notice(DI::l10n()->t('Registration revoked for %s', $user['username']) . EOL);
        return true;
 }
 
 function regmod_content(App $a)
 {
        if (!local_user()) {
-               info(L10n::t('Please login.') . EOL);
-               $o = '<br /><br />' . Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? 0 : 1);
-               return $o;
+               info(DI::l10n()->t('Please login.') . EOL);
+               return Login::form(DI::args()->getQueryString(), intval(DI::config()->get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 0 : 1);
        }
 
-       if ((!is_site_admin()) || (x($_SESSION, 'submanage') && intval($_SESSION['submanage']))) {
-               notice(L10n::t('Permission denied.') . EOL);
+       if (!is_site_admin() || !empty($_SESSION['submanage'])) {
+               notice(DI::l10n()->t('Permission denied.') . EOL);
                return '';
        }
 
        if ($a->argc != 3) {
-               killme();
+               exit();
        }
 
        $cmd = $a->argv[1];
@@ -118,13 +110,11 @@ function regmod_content(App $a)
 
        if ($cmd === 'deny') {
                user_deny($hash);
-               goaway(System::baseUrl() . "/admin/users/");
-               killme();
+               DI::baseUrl()->redirect('admin/users/');
        }
 
        if ($cmd === 'allow') {
                user_allow($hash);
-               goaway(System::baseUrl() . "/admin/users/");
-               killme();
+               DI::baseUrl()->redirect('admin/users/');
        }
 }