2016-09-16 06:19:40 +02:00
|
|
|
<?php
|
2017-10-21 08:40:00 +02:00
|
|
|
/**
|
|
|
|
* RegisterController.php
|
2020-01-31 07:32:04 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* 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.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-10-21 08:40:00 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:37:26 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* 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/>.
|
2017-10-21 08:40:00 +02:00
|
|
|
*/
|
2018-07-08 07:59:58 +02:00
|
|
|
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
|
2017-09-14 17:40:02 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-09-16 06:19:40 +02:00
|
|
|
namespace FireflyIII\Http\Controllers\Auth;
|
|
|
|
|
2020-01-01 15:34:38 +01:00
|
|
|
use FireflyIII\Events\RegisteredUser;
|
2020-08-14 09:59:56 +02:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
2017-09-09 22:03:27 +02:00
|
|
|
use FireflyIII\Http\Controllers\Controller;
|
2018-08-10 17:05:37 +02:00
|
|
|
use FireflyIII\Support\Http\Controllers\CreateStuff;
|
2017-09-14 17:40:02 +02:00
|
|
|
use FireflyIII\User;
|
2020-03-17 15:01:00 +01:00
|
|
|
use Illuminate\Contracts\View\Factory;
|
2016-09-16 06:19:40 +02:00
|
|
|
use Illuminate\Foundation\Auth\RegistersUsers;
|
2020-03-17 15:01:00 +01:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2017-09-16 07:18:15 +02:00
|
|
|
use Illuminate\Http\Request;
|
2020-03-17 15:01:00 +01:00
|
|
|
use Illuminate\Routing\Redirector;
|
|
|
|
use Illuminate\View\View;
|
2020-01-01 15:34:38 +01:00
|
|
|
use Log;
|
2018-07-13 15:50:42 +02:00
|
|
|
|
2017-12-17 14:30:53 +01:00
|
|
|
/**
|
|
|
|
* Class RegisterController
|
2017-12-17 18:23:10 +01:00
|
|
|
*
|
|
|
|
* This controller handles the registration of new users as well as their
|
|
|
|
* validation and creation. By default this controller uses a trait to
|
|
|
|
* provide this functionality without requiring any additional code.
|
2018-07-22 08:10:16 +02:00
|
|
|
*
|
|
|
|
* @codeCoverageIgnore
|
2017-12-17 14:30:53 +01:00
|
|
|
*/
|
2016-09-16 06:19:40 +02:00
|
|
|
class RegisterController extends Controller
|
|
|
|
{
|
2021-04-06 17:00:16 +02:00
|
|
|
use RegistersUsers, CreateStuff;
|
2016-09-16 06:19:40 +02:00
|
|
|
|
|
|
|
/**
|
2017-09-09 22:03:27 +02:00
|
|
|
* Where to redirect users after registration.
|
2016-09-16 06:19:40 +02:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $redirectTo = '/home';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2017-09-16 07:18:15 +02:00
|
|
|
parent::__construct();
|
2016-09-16 06:19:40 +02:00
|
|
|
$this->middleware('guest');
|
2020-08-14 09:59:56 +02:00
|
|
|
|
|
|
|
$loginProvider = config('firefly.login_provider');
|
|
|
|
$authGuard = config('firefly.authentication_guard');
|
|
|
|
|
|
|
|
if ('eloquent' !== $loginProvider || 'web' !== $authGuard) {
|
|
|
|
throw new FireflyException('Using external identity provider. Cannot continue.');
|
|
|
|
}
|
2016-09-16 06:19:40 +02:00
|
|
|
}
|
|
|
|
|
2017-09-16 07:18:15 +02:00
|
|
|
/**
|
|
|
|
* Handle a registration request for the application.
|
|
|
|
*
|
2018-07-08 12:28:42 +02:00
|
|
|
* @param Request $request
|
2017-09-16 07:18:15 +02:00
|
|
|
*
|
2020-03-17 15:01:00 +01:00
|
|
|
* @return Factory|RedirectResponse|Redirector|View
|
2017-09-16 07:18:15 +02:00
|
|
|
*/
|
|
|
|
public function register(Request $request)
|
|
|
|
{
|
|
|
|
// is allowed to?
|
2018-10-13 15:06:56 +02:00
|
|
|
$allowRegistration = true;
|
2018-12-15 07:59:02 +01:00
|
|
|
$loginProvider = config('firefly.login_provider');
|
2019-02-13 17:38:41 +01:00
|
|
|
$singleUserMode = app('fireflyconfig')->get('single_user_mode', config('firefly.configuration.single_user_mode'))->data;
|
2018-10-13 15:06:56 +02:00
|
|
|
$userCount = User::count();
|
|
|
|
if (true === $singleUserMode && $userCount > 0 && 'eloquent' === $loginProvider) {
|
|
|
|
$allowRegistration = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('eloquent' !== $loginProvider) {
|
|
|
|
$allowRegistration = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (false === $allowRegistration) {
|
2017-09-16 07:18:15 +02:00
|
|
|
$message = 'Registration is currently not available.';
|
|
|
|
|
2021-01-31 20:35:54 +01:00
|
|
|
return prefixView('error', compact('message'));
|
2017-09-16 07:18:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->validator($request->all())->validate();
|
2020-01-01 15:34:38 +01:00
|
|
|
$user = $this->createUser($request->all());
|
|
|
|
Log::info(sprintf('Registered new user %s', $user->email));
|
|
|
|
event(new RegisteredUser($user, $request->ip()));
|
2017-09-16 07:18:15 +02:00
|
|
|
|
|
|
|
$this->guard()->login($user);
|
|
|
|
|
2021-03-21 09:15:40 +01:00
|
|
|
session()->flash('success', (string)trans('firefly.registered'));
|
2017-09-16 07:18:15 +02:00
|
|
|
|
2018-07-26 06:27:52 +02:00
|
|
|
$this->registered($request, $user);
|
|
|
|
|
2020-05-24 11:24:28 +02:00
|
|
|
// telemetry
|
2020-07-24 16:41:41 +02:00
|
|
|
app('telemetry')->feature('system.users.count', (string)User::count());
|
2020-05-24 11:24:28 +02:00
|
|
|
|
2018-07-26 06:27:52 +02:00
|
|
|
return redirect($this->redirectPath());
|
2017-09-16 07:18:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the application registration form.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
*
|
2020-03-17 15:01:00 +01:00
|
|
|
* @return Factory|View
|
2017-09-16 07:18:15 +02:00
|
|
|
*/
|
|
|
|
public function showRegistrationForm(Request $request)
|
|
|
|
{
|
2018-10-13 15:06:56 +02:00
|
|
|
$allowRegistration = true;
|
2018-12-15 07:59:02 +01:00
|
|
|
$loginProvider = config('firefly.login_provider');
|
2019-02-13 17:38:41 +01:00
|
|
|
$isDemoSite = app('fireflyconfig')->get('is_demo_site', config('firefly.configuration.is_demo_site'))->data;
|
|
|
|
$singleUserMode = app('fireflyconfig')->get('single_user_mode', config('firefly.configuration.single_user_mode'))->data;
|
2018-10-13 15:06:56 +02:00
|
|
|
$userCount = User::count();
|
2021-03-21 09:15:40 +01:00
|
|
|
$pageTitle = (string)trans('firefly.register_page_title');
|
2018-10-13 15:06:56 +02:00
|
|
|
|
|
|
|
if (true === $isDemoSite) {
|
|
|
|
$allowRegistration = false;
|
|
|
|
}
|
2017-09-16 07:18:15 +02:00
|
|
|
|
2018-10-13 15:06:56 +02:00
|
|
|
if (true === $singleUserMode && $userCount > 0 && 'eloquent' === $loginProvider) {
|
|
|
|
$allowRegistration = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('eloquent' !== $loginProvider) {
|
|
|
|
$allowRegistration = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (false === $allowRegistration) {
|
2017-09-16 07:18:15 +02:00
|
|
|
$message = 'Registration is currently not available.';
|
|
|
|
|
2021-01-31 20:35:54 +01:00
|
|
|
return prefixView('error', compact('message'));
|
2017-09-16 07:18:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$email = $request->old('email');
|
|
|
|
|
2021-01-31 20:35:54 +01:00
|
|
|
return prefixView('auth.register', compact('isDemoSite', 'email', 'pageTitle'));
|
2017-09-16 07:18:15 +02:00
|
|
|
}
|
|
|
|
|
2016-09-16 06:19:40 +02:00
|
|
|
}
|