3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Model;
24 use Friendica\Database\DBA;
25 use Friendica\Util\DateTimeFormat;
26 use Friendica\Util\Strings;
29 * Class interacting with the register database table
34 * Return the list of pending registrations
39 public static function getPending()
42 "SELECT `register`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`email`
44 INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
45 INNER JOIN `user` ON `register`.`uid` = `user`.`uid`"
48 return DBA::toArray($stmt);
52 * Returns the pending registration count
57 public static function getPendingCount()
59 $register = DBA::fetchFirst(
60 "SELECT COUNT(*) AS `count`
62 INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` AND `contact`.`self`"
65 return $register['count'];
69 * Returns the register record associated with the provided hash
75 public static function getByHash($hash)
77 return DBA::selectFirst('register', [], ['hash' => $hash]);
81 * Returns true if a register record exists with the provided hash
87 public static function existsByHash($hash)
89 return DBA::exists('register', ['hash' => $hash]);
93 * Creates a register record for an invitation and returns the auto-generated code for it
98 public static function createForInvitation()
100 $code = Strings::getRandomName(8) . random_int(1000, 9999);
104 'created' => DateTimeFormat::utcNow()
107 DBA::insert('register', $fields);
113 * Creates a register record for approval and returns the success of the database insert
114 * Checks for the existence of the provided user id
116 * @param integer $uid The ID of the user needing approval
117 * @param string $language The registration language
118 * @param string $note An additional message from the user
122 public static function createForApproval($uid, $language, $note = '')
124 $hash = Strings::getRandomHex();
126 if (!User::exists($uid)) {
132 'created' => DateTimeFormat::utcNow(),
134 'password' => '', // Obsolete, slated for deletion
135 'language' => $language,
139 return DBA::insert('register', $fields);
143 * Deletes a register record by the provided hash and returns the success of the database deletion
145 * @param string $hash
149 public static function deleteByHash($hash)
151 return DBA::delete('register', ['hash' => $hash]);