3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU APGL 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;
26 use Friendica\Core\Config\IConfig;
27 use Friendica\Core\L10n;
28 use Friendica\Network\HTTPException\InternalServerErrorException;
29 use Friendica\Util\Emailer;
30 use Friendica\Util\Strings;
31 use Friendica\Model\User as UserModel;
40 /** @var App\BaseURL */
45 public function __construct(L10n $l10n, IConfig $config, Emailer $emailer, App\BaseURL $baseUrl)
48 $this->config = $config;
49 $this->emailer = $emailer;
50 $this->baseUrl = $baseUrl;
54 * Creates a new user based on a minimal set and sends an email to this user
56 * @param string $name The user's name
57 * @param string $email The user's email address
58 * @param string $nick The user's nick name
59 * @param string $lang The user's language (default is english)
61 * @return bool True, if the user was created successfully
62 * @throws InternalServerErrorException
63 * @throws ErrorException
64 * @throws ImagickException
66 public function createMinimal(string $name, string $email, string $nick, string $lang = L10n::DEFAULT)
71 throw new InternalServerErrorException('Invalid arguments.');
74 $result = UserModel::create([
82 $user = $result['user'];
83 $preamble = Strings::deindent($this->l10n->t('
85 the administrator of %2$s has set up an account for you.'));
86 $body = Strings::deindent($this->l10n->t('
87 The login details are as follows:
93 You may change your password from your account "Settings" page after logging
96 Please take a few moments to review the other account settings on that page.
98 You may also wish to add some basic information to your default profile
99 (on the "Profiles" page) so that other people can easily find you.
101 We recommend setting your full name, adding a profile photo,
102 adding some profile "keywords" (very useful in making new friends) - and
103 perhaps what country you live in; if you do not wish to be more specific
106 We fully respect your right to privacy, and none of these items are necessary.
107 If you are new and do not know anybody here, they may help
108 you to make some new and interesting friends.
110 If you ever want to delete your account, you can do so at %1$s/removeme
112 Thank you and welcome to %4$s.'));
114 $preamble = sprintf($preamble, $user['username'], $this->config->get('config', 'sitename'));
115 $body = sprintf($body, $this->baseUrl->get(), $user['nickname'], $result['password'], $this->config->get('config', 'sitename'));
117 $email = $this->emailer
119 ->withMessage($this->l10n->t('Registration details for %s', $this->config->get('config', 'sitename')), $preamble, $body)
121 ->withRecipient($user['email'])
123 return $this->emailer->send($email);