2016-09-16 06:19:40 +02:00
|
|
|
<?php
|
2017-10-21 08:40:00 +02:00
|
|
|
/**
|
|
|
|
* RegisterController.php
|
2019-10-02 06:37:26 +02:00
|
|
|
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
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;
|
|
|
|
|
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;
|
2018-08-09 17:46:14 +02:00
|
|
|
use FireflyIII\Support\Http\Controllers\RequestInformation;
|
2017-09-14 17:40:02 +02:00
|
|
|
use FireflyIII\User;
|
2017-09-16 07:18:15 +02:00
|
|
|
use Illuminate\Auth\Events\Registered;
|
2016-09-16 06:19:40 +02:00
|
|
|
use Illuminate\Foundation\Auth\RegistersUsers;
|
2017-09-16 07:18:15 +02:00
|
|
|
use Illuminate\Http\Request;
|
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
|
|
|
|
{
|
2018-08-10 17:05:37 +02:00
|
|
|
use RegistersUsers, RequestInformation, 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');
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*
|
2018-07-08 12:28:42 +02:00
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\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.';
|
|
|
|
|
|
|
|
return view('error', compact('message'));
|
|
|
|
}
|
|
|
|
|
2018-07-09 19:24:08 +02:00
|
|
|
/** @noinspection PhpUndefinedMethodInspection */
|
2017-09-16 07:18:15 +02:00
|
|
|
$this->validator($request->all())->validate();
|
|
|
|
|
2018-08-10 17:05:37 +02:00
|
|
|
event(new Registered($user = $this->createUser($request->all())));
|
2017-09-16 07:18:15 +02:00
|
|
|
|
|
|
|
$this->guard()->login($user);
|
|
|
|
|
2018-04-22 17:10:11 +02: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);
|
|
|
|
|
|
|
|
return redirect($this->redirectPath());
|
2017-09-16 07:18:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the application registration form.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
*
|
2018-07-08 12:28:42 +02:00
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\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();
|
2018-11-25 11:31:02 +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.';
|
|
|
|
|
|
|
|
return view('error', compact('message'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$email = $request->old('email');
|
|
|
|
|
2018-11-25 11:31:02 +01:00
|
|
|
return view('auth.register', compact('isDemoSite', 'email', 'pageTitle'));
|
2017-09-16 07:18:15 +02:00
|
|
|
}
|
|
|
|
|
2016-09-16 06:19:40 +02:00
|
|
|
}
|