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 user based on a given user id
54 * @param int $uid The user id
56 * @return array The pending user information
60 public static function getPendingForUser(int $uid)
62 return DBA::fetchFirst(
63 "SELECT `register`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`email`
65 INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
66 INNER JOIN `user` ON `register`.`uid` = `user`.`uid`
67 WHERE `register`.uid = ?",
73 * Returns the pending registration count
78 public static function getPendingCount()
80 $register = DBA::fetchFirst(
81 "SELECT COUNT(*) AS `count`
83 INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` AND `contact`.`self`"
86 return $register['count'];
90 * Returns the register record associated with the provided hash
96 public static function getByHash($hash)
98 return DBA::selectFirst('register', [], ['hash' => $hash]);
102 * Returns true if a register record exists with the provided hash
104 * @param string $hash
108 public static function existsByHash($hash)
110 return DBA::exists('register', ['hash' => $hash]);
114 * Creates a register record for an invitation and returns the auto-generated code for it
119 public static function createForInvitation()
121 $code = Strings::getRandomName(8) . random_int(1000, 9999);
125 'created' => DateTimeFormat::utcNow()
128 DBA::insert('register', $fields);
134 * Creates a register record for approval and returns the success of the database insert
135 * Checks for the existence of the provided user id
137 * @param integer $uid The ID of the user needing approval
138 * @param string $language The registration language
139 * @param string $note An additional message from the user
143 public static function createForApproval($uid, $language, $note = '')
145 $hash = Strings::getRandomHex();
147 if (!User::exists($uid)) {
153 'created' => DateTimeFormat::utcNow(),
155 'password' => '', // Obsolete, slated for deletion
156 'language' => $language,
160 return DBA::insert('register', $fields);
164 * Deletes a register record by the provided hash and returns the success of the database deletion
166 * @param string $hash
170 public static function deleteByHash($hash)
172 return DBA::delete('register', ['hash' => $hash]);