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\Content\Pager;
25 use Friendica\Database\DBA;
26 use Friendica\Util\DateTimeFormat;
27 use Friendica\Util\Strings;
30 * Class interacting with the register database table
35 * Return the list of pending registrations
37 * @param int $start Start count (Default is 0)
38 * @param int $count Count of the items per page (Default is @see Pager::ITEMS_PER_PAGE)
43 public static function getPending($start = 0, $count = Pager::ITEMS_PER_PAGE)
46 "SELECT `register`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`email`, `contact`.`nick`
48 INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
49 INNER JOIN `user` ON `register`.`uid` = `user`.`uid`
50 LIMIT ?, ?", $start, $count
53 return DBA::toArray($stmt);
57 * Returns the pending user based on a given user id
59 * @param int $uid The user id
61 * @return array The pending user information
65 public static function getPendingForUser(int $uid)
67 return DBA::fetchFirst(
68 "SELECT `register`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`email`
70 INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
71 INNER JOIN `user` ON `register`.`uid` = `user`.`uid`
72 WHERE `register`.uid = ?",
78 * Returns the pending registration count
83 public static function getPendingCount()
85 $register = DBA::fetchFirst(
86 "SELECT COUNT(*) AS `count`
88 INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` AND `contact`.`self`"
91 return $register['count'];
95 * Returns the register record associated with the provided hash
101 public static function getByHash($hash)
103 return DBA::selectFirst('register', [], ['hash' => $hash]);
107 * Returns true if a register record exists with the provided hash
109 * @param string $hash
113 public static function existsByHash($hash)
115 return DBA::exists('register', ['hash' => $hash]);
119 * Creates a register record for an invitation and returns the auto-generated code for it
124 public static function createForInvitation()
126 $code = Strings::getRandomName(8) . random_int(1000, 9999);
130 'created' => DateTimeFormat::utcNow()
133 DBA::insert('register', $fields);
139 * Creates a register record for approval and returns the success of the database insert
140 * Checks for the existence of the provided user id
142 * @param integer $uid The ID of the user needing approval
143 * @param string $language The registration language
144 * @param string $note An additional message from the user
148 public static function createForApproval($uid, $language, $note = '')
150 $hash = Strings::getRandomHex();
152 if (!User::exists($uid)) {
158 'created' => DateTimeFormat::utcNow(),
160 'password' => '', // Obsolete, slated for deletion
161 'language' => $language,
165 return DBA::insert('register', $fields);
169 * Deletes a register record by the provided hash and returns the success of the database deletion
171 * @param string $hash
175 public static function deleteByHash($hash)
177 return DBA::delete('register', ['hash' => $hash]);