2016-05-20 01:57:45 -05:00
|
|
|
<?php
|
2016-05-20 05:27:31 -05:00
|
|
|
/**
|
|
|
|
* NewUserController.php
|
2020-01-31 00:32:04 -06:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2016-05-20 05:27:31 -05:00
|
|
|
*
|
2019-10-01 23:37:26 -05:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2016-10-04 23:52:15 -05:00
|
|
|
*
|
2019-10-01 23:37:26 -05: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 01:40:00 -05:00
|
|
|
*
|
2019-10-01 23:37:26 -05:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-10-21 01:40:00 -05:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-01 23:37:26 -05:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-10-21 01:40:00 -05:00
|
|
|
*
|
2019-10-01 23:37:26 -05: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/>.
|
2016-05-20 05:27:31 -05:00
|
|
|
*/
|
2017-04-09 00:44:22 -05:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-05-20 01:57:45 -05:00
|
|
|
namespace FireflyIII\Http\Controllers;
|
2015-06-01 11:13:54 -05:00
|
|
|
|
|
|
|
use FireflyIII\Http\Requests\NewUserFormRequest;
|
2020-04-14 10:23:58 -05:00
|
|
|
use FireflyIII\Models\AccountType;
|
2016-10-09 01:18:47 -05:00
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
2017-11-03 00:58:39 -05:00
|
|
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
2018-08-10 10:05:37 -05:00
|
|
|
use FireflyIII\Support\Http\Controllers\CreateStuff;
|
2020-03-17 09:01:00 -05:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Illuminate\Routing\Redirector;
|
2015-06-01 11:13:54 -05:00
|
|
|
use View;
|
|
|
|
|
|
|
|
/**
|
2017-11-15 05:25:49 -06:00
|
|
|
* Class NewUserController.
|
2015-06-01 11:13:54 -05:00
|
|
|
*/
|
|
|
|
class NewUserController extends Controller
|
|
|
|
{
|
2018-08-10 10:05:37 -05:00
|
|
|
use CreateStuff;
|
2018-07-20 13:53:48 -05:00
|
|
|
/** @var AccountRepositoryInterface The account repository */
|
2018-04-15 01:52:58 -05:00
|
|
|
private $repository;
|
|
|
|
|
2016-01-09 01:20:55 -06:00
|
|
|
/**
|
|
|
|
* NewUserController constructor.
|
|
|
|
*/
|
2016-01-08 11:29:47 -06:00
|
|
|
public function __construct()
|
|
|
|
{
|
2016-01-08 13:40:48 -06:00
|
|
|
parent::__construct();
|
2016-10-29 00:44:46 -05:00
|
|
|
|
|
|
|
$this->middleware(
|
|
|
|
function ($request, $next) {
|
2018-04-15 01:52:58 -05:00
|
|
|
$this->repository = app(AccountRepositoryInterface::class);
|
|
|
|
|
2016-10-29 00:44:46 -05:00
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
);
|
2016-01-08 11:29:47 -06:00
|
|
|
}
|
2015-06-01 11:13:54 -05:00
|
|
|
|
|
|
|
/**
|
2018-07-22 01:10:16 -05:00
|
|
|
* Form the user gets when he has no data in the system.
|
|
|
|
*
|
2020-03-25 01:03:23 -05:00
|
|
|
* @return RedirectResponse|Redirector|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
2015-06-01 11:13:54 -05:00
|
|
|
*/
|
2018-04-15 01:52:58 -05:00
|
|
|
public function index()
|
2015-06-01 11:13:54 -05:00
|
|
|
{
|
2020-03-17 09:01:00 -05:00
|
|
|
app('view')->share('title', (string) trans('firefly.welcome'));
|
2017-12-16 12:46:36 -06:00
|
|
|
app('view')->share('mainTitleIcon', 'fa-fire');
|
2015-06-01 11:13:54 -05:00
|
|
|
|
2016-04-26 14:40:15 -05:00
|
|
|
$types = config('firefly.accountTypesByIdentifier.asset');
|
2018-04-15 01:52:58 -05:00
|
|
|
$count = $this->repository->count($types);
|
|
|
|
|
|
|
|
$languages = [];
|
2015-06-01 11:13:54 -05:00
|
|
|
|
|
|
|
if ($count > 0) {
|
2015-07-06 09:27:21 -05:00
|
|
|
return redirect(route('index'));
|
2015-06-01 11:13:54 -05:00
|
|
|
}
|
|
|
|
|
2018-04-15 01:52:58 -05:00
|
|
|
return view('new-user.index', compact('languages'));
|
2015-06-01 11:13:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-22 01:10:16 -05:00
|
|
|
* Store his new settings.
|
|
|
|
*
|
2017-11-17 22:46:19 -06:00
|
|
|
* @param NewUserFormRequest $request
|
|
|
|
* @param CurrencyRepositoryInterface $currencyRepository
|
2015-06-05 00:10:51 -05:00
|
|
|
*
|
2020-03-17 09:01:00 -05:00
|
|
|
* @return RedirectResponse|Redirector
|
2015-06-01 11:13:54 -05:00
|
|
|
*/
|
2018-04-15 01:52:58 -05:00
|
|
|
public function submit(NewUserFormRequest $request, CurrencyRepositoryInterface $currencyRepository)
|
2015-06-01 11:13:54 -05:00
|
|
|
{
|
2018-04-15 01:52:58 -05:00
|
|
|
$language = $request->string('language');
|
|
|
|
if (!array_key_exists($language, config('firefly.languages'))) {
|
|
|
|
$language = 'en_US';
|
2015-06-01 11:13:54 -05:00
|
|
|
|
2018-04-15 01:52:58 -05:00
|
|
|
}
|
2015-06-01 11:13:54 -05:00
|
|
|
|
2018-04-15 01:52:58 -05:00
|
|
|
// set language preference:
|
2018-07-14 09:08:34 -05:00
|
|
|
app('preferences')->set('language', $language);
|
2018-04-15 01:52:58 -05:00
|
|
|
// Store currency preference from input:
|
2020-03-17 09:01:00 -05:00
|
|
|
$currency = $currencyRepository->findNull((int) $request->input('amount_currency_id_bank_balance'));
|
2017-11-03 00:58:39 -05:00
|
|
|
|
2018-04-15 01:52:58 -05:00
|
|
|
// if is null, set to EUR:
|
|
|
|
if (null === $currency) {
|
|
|
|
$currency = $currencyRepository->findByCodeNull('EUR');
|
2017-11-03 00:58:39 -05:00
|
|
|
}
|
2018-11-10 03:04:46 -06:00
|
|
|
$currencyRepository->enable($currency);
|
2017-11-03 00:58:39 -05:00
|
|
|
|
2018-07-20 07:34:56 -05:00
|
|
|
$this->createAssetAccount($request, $currency); // create normal asset account
|
|
|
|
$this->createSavingsAccount($request, $currency, $language); // create savings account
|
|
|
|
$this->createCashWalletAccount($currency, $language); // create cash wallet account
|
2018-04-15 01:52:58 -05:00
|
|
|
|
|
|
|
// store currency preference:
|
2018-07-14 09:08:34 -05:00
|
|
|
app('preferences')->set('currencyPreference', $currency->code);
|
2020-04-14 10:23:58 -05:00
|
|
|
|
|
|
|
// store frontpage preferences:
|
|
|
|
$accounts = $this->repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray();
|
|
|
|
app('preferences')->set('frontPageAccounts', $accounts);
|
|
|
|
|
|
|
|
// mark.
|
2018-07-08 05:08:53 -05:00
|
|
|
app('preferences')->mark();
|
2018-04-15 01:52:58 -05:00
|
|
|
|
2018-02-10 01:21:35 -06:00
|
|
|
// set default optional fields:
|
2018-07-20 07:34:56 -05:00
|
|
|
$visibleFields = ['interest_date' => true, 'book_date' => false, 'process_date' => false, 'due_date' => false, 'payment_date' => false,
|
|
|
|
'invoice_date' => false, 'internal_reference' => false, 'notes' => true, 'attachments' => true,];
|
2018-07-14 09:08:34 -05:00
|
|
|
app('preferences')->set('transaction_journal_optional_fields', $visibleFields);
|
2018-02-10 01:21:35 -06:00
|
|
|
|
2020-05-24 04:24:28 -05:00
|
|
|
// telemetry: user language preference + default language.
|
2020-05-24 05:12:06 -05:00
|
|
|
app('telemetry')->feature('config.firefly.default_language', config('firefly.default_language', 'en_US'));
|
|
|
|
app('telemetry')->feature('user.preferences.language', app('steam')->getLanguage());
|
|
|
|
app('telemetry')->feature('user.preferences.locale', app('steam')->getLocale());
|
2020-05-24 04:24:28 -05:00
|
|
|
|
2020-03-17 09:01:00 -05:00
|
|
|
session()->flash('success', (string) trans('firefly.stored_new_accounts_new_user'));
|
2018-07-08 05:08:53 -05:00
|
|
|
app('preferences')->mark();
|
2015-06-01 11:13:54 -05:00
|
|
|
|
2015-07-06 09:27:21 -05:00
|
|
|
return redirect(route('index'));
|
2015-06-01 11:13:54 -05:00
|
|
|
}
|
2016-05-20 10:53:03 -05:00
|
|
|
|
2015-06-05 06:39:24 -05:00
|
|
|
}
|