mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Move methods to traits.
This commit is contained in:
@@ -25,6 +25,7 @@ namespace FireflyIII\Http\Controllers\Auth;
|
|||||||
|
|
||||||
use FireflyConfig;
|
use FireflyConfig;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
|
use FireflyIII\Support\Http\Controllers\CreateStuff;
|
||||||
use FireflyIII\Support\Http\Controllers\RequestInformation;
|
use FireflyIII\Support\Http\Controllers\RequestInformation;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Auth\Events\Registered;
|
use Illuminate\Auth\Events\Registered;
|
||||||
@@ -42,7 +43,7 @@ use Illuminate\Http\Request;
|
|||||||
*/
|
*/
|
||||||
class RegisterController extends Controller
|
class RegisterController extends Controller
|
||||||
{
|
{
|
||||||
use RegistersUsers, RequestInformation;
|
use RegistersUsers, RequestInformation, CreateStuff;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Where to redirect users after registration.
|
* Where to redirect users after registration.
|
||||||
@@ -81,7 +82,7 @@ class RegisterController extends Controller
|
|||||||
/** @noinspection PhpUndefinedMethodInspection */
|
/** @noinspection PhpUndefinedMethodInspection */
|
||||||
$this->validator($request->all())->validate();
|
$this->validator($request->all())->validate();
|
||||||
|
|
||||||
event(new Registered($user = $this->create($request->all())));
|
event(new Registered($user = $this->createUser($request->all())));
|
||||||
|
|
||||||
$this->guard()->login($user);
|
$this->guard()->login($user);
|
||||||
|
|
||||||
@@ -118,20 +119,4 @@ class RegisterController extends Controller
|
|||||||
return view('auth.register', compact('isDemoSite', 'email'));
|
return view('auth.register', compact('isDemoSite', 'email'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new user instance after a valid registration.
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
*
|
|
||||||
* @return \FireflyIII\User
|
|
||||||
*/
|
|
||||||
protected function create(array $data): User // create object
|
|
||||||
{
|
|
||||||
return User::create(
|
|
||||||
[
|
|
||||||
'email' => $data['email'],
|
|
||||||
'password' => bcrypt($data['password']),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -24,9 +24,9 @@ namespace FireflyIII\Http\Controllers\Import;
|
|||||||
|
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Import\JobConfiguration\JobConfigurationInterface;
|
|
||||||
use FireflyIII\Models\ImportJob;
|
use FireflyIII\Models\ImportJob;
|
||||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||||
|
use FireflyIII\Support\Http\Controllers\CreateStuff;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
use Illuminate\Support\MessageBag;
|
use Illuminate\Support\MessageBag;
|
||||||
@@ -37,6 +37,7 @@ use Log;
|
|||||||
*/
|
*/
|
||||||
class JobConfigurationController extends Controller
|
class JobConfigurationController extends Controller
|
||||||
{
|
{
|
||||||
|
use CreateStuff;
|
||||||
/** @var ImportJobRepositoryInterface The import job repository */
|
/** @var ImportJobRepositoryInterface The import job repository */
|
||||||
public $repository;
|
public $repository;
|
||||||
|
|
||||||
@@ -161,27 +162,5 @@ class JobConfigurationController extends Controller
|
|||||||
return redirect(route('import.job.configuration.index', [$importJob->key]));
|
return redirect(route('import.job.configuration.index', [$importJob->key]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Make a configurator object.
|
|
||||||
*
|
|
||||||
* @param ImportJob $importJob
|
|
||||||
*
|
|
||||||
* @return JobConfigurationInterface
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
protected function makeConfigurator(ImportJob $importJob): JobConfigurationInterface // make object
|
|
||||||
{
|
|
||||||
$key = sprintf('import.configuration.%s', $importJob->provider);
|
|
||||||
$className = (string)config($key);
|
|
||||||
if (null === $className || !class_exists($className)) {
|
|
||||||
throw new FireflyException(sprintf('Cannot find configurator class for job with provider "%s".', $importJob->provider)); // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
Log::debug(sprintf('Going to create class "%s"', $className));
|
|
||||||
/** @var JobConfigurationInterface $configurator */
|
|
||||||
$configurator = app($className);
|
|
||||||
$configurator->setImportJob($importJob);
|
|
||||||
|
|
||||||
return $configurator;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -26,9 +26,9 @@ use Exception;
|
|||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Import\Routine\RoutineInterface;
|
use FireflyIII\Import\Routine\RoutineInterface;
|
||||||
use FireflyIII\Import\Storage\ImportArrayStorage;
|
|
||||||
use FireflyIII\Models\ImportJob;
|
use FireflyIII\Models\ImportJob;
|
||||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||||
|
use FireflyIII\Support\Http\Controllers\CreateStuff;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
@@ -37,6 +37,7 @@ use Log;
|
|||||||
*/
|
*/
|
||||||
class JobStatusController extends Controller
|
class JobStatusController extends Controller
|
||||||
{
|
{
|
||||||
|
use CreateStuff;
|
||||||
/** @var ImportJobRepositoryInterface The import job repository */
|
/** @var ImportJobRepositoryInterface The import job repository */
|
||||||
private $repository;
|
private $repository;
|
||||||
|
|
||||||
@@ -224,22 +225,5 @@ class JobStatusController extends Controller
|
|||||||
return response()->json(['status' => 'OK', 'message' => 'storage_finished']);
|
return response()->json(['status' => 'OK', 'message' => 'storage_finished']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Store the transactions.
|
|
||||||
*
|
|
||||||
* @param ImportJob $importJob
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
protected function storeTransactions(ImportJob $importJob): void // make object + execute
|
|
||||||
{
|
|
||||||
/** @var ImportArrayStorage $storage */
|
|
||||||
$storage = app(ImportArrayStorage::class);
|
|
||||||
$storage->setImportJob($importJob);
|
|
||||||
try {
|
|
||||||
$storage->store();
|
|
||||||
} catch (FireflyException|Exception $e) {
|
|
||||||
throw new FireflyException($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -22,11 +22,10 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Controllers;
|
namespace FireflyIII\Http\Controllers;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use FireflyIII\Http\Requests\NewUserFormRequest;
|
use FireflyIII\Http\Requests\NewUserFormRequest;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
|
use FireflyIII\Support\Http\Controllers\CreateStuff;
|
||||||
use View;
|
use View;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,6 +33,7 @@ use View;
|
|||||||
*/
|
*/
|
||||||
class NewUserController extends Controller
|
class NewUserController extends Controller
|
||||||
{
|
{
|
||||||
|
use CreateStuff;
|
||||||
/** @var AccountRepositoryInterface The account repository */
|
/** @var AccountRepositoryInterface The account repository */
|
||||||
private $repository;
|
private $repository;
|
||||||
|
|
||||||
@@ -120,87 +120,4 @@ class NewUserController extends Controller
|
|||||||
return redirect(route('index'));
|
return redirect(route('index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an asset account.
|
|
||||||
*
|
|
||||||
* @param NewUserFormRequest $request
|
|
||||||
* @param TransactionCurrency $currency
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function createAssetAccount(NewUserFormRequest $request, TransactionCurrency $currency): bool // create stuff
|
|
||||||
{
|
|
||||||
$assetAccount = [
|
|
||||||
'name' => $request->get('bank_name'),
|
|
||||||
'iban' => null,
|
|
||||||
'accountType' => 'asset',
|
|
||||||
'virtualBalance' => 0,
|
|
||||||
'account_type_id' => null,
|
|
||||||
'active' => true,
|
|
||||||
'accountRole' => 'defaultAsset',
|
|
||||||
'openingBalance' => $request->input('bank_balance'),
|
|
||||||
'openingBalanceDate' => new Carbon,
|
|
||||||
'currency_id' => $currency->id,
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->repository->store($assetAccount);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a cash wallet.
|
|
||||||
*
|
|
||||||
* @param TransactionCurrency $currency
|
|
||||||
* @param string $language
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function createCashWalletAccount(TransactionCurrency $currency, string $language): bool // create stuff
|
|
||||||
{
|
|
||||||
$assetAccount = [
|
|
||||||
'name' => (string)trans('firefly.cash_wallet', [], $language),
|
|
||||||
'iban' => null,
|
|
||||||
'accountType' => 'asset',
|
|
||||||
'virtualBalance' => 0,
|
|
||||||
'account_type_id' => null,
|
|
||||||
'active' => true,
|
|
||||||
'accountRole' => 'cashWalletAsset',
|
|
||||||
'openingBalance' => null,
|
|
||||||
'openingBalanceDate' => null,
|
|
||||||
'currency_id' => $currency->id,
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->repository->store($assetAccount);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a savings account.
|
|
||||||
*
|
|
||||||
* @param NewUserFormRequest $request
|
|
||||||
* @param TransactionCurrency $currency
|
|
||||||
* @param string $language
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function createSavingsAccount(NewUserFormRequest $request, TransactionCurrency $currency, string $language): bool // create stuff
|
|
||||||
{
|
|
||||||
$savingsAccount = [
|
|
||||||
'name' => (string)trans('firefly.new_savings_account', ['bank_name' => $request->get('bank_name')], $language),
|
|
||||||
'iban' => null,
|
|
||||||
'accountType' => 'asset',
|
|
||||||
'account_type_id' => null,
|
|
||||||
'virtualBalance' => 0,
|
|
||||||
'active' => true,
|
|
||||||
'accountRole' => 'savingAsset',
|
|
||||||
'openingBalance' => $request->input('savings_balance'),
|
|
||||||
'openingBalanceDate' => new Carbon,
|
|
||||||
'currency_id' => $currency->id,
|
|
||||||
];
|
|
||||||
$this->repository->store($savingsAccount);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -35,6 +35,7 @@ use FireflyIII\Http\Requests\ProfileFormRequest;
|
|||||||
use FireflyIII\Http\Requests\TokenFormRequest;
|
use FireflyIII\Http\Requests\TokenFormRequest;
|
||||||
use FireflyIII\Models\Preference;
|
use FireflyIII\Models\Preference;
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
|
use FireflyIII\Support\Http\Controllers\CreateStuff;
|
||||||
use FireflyIII\Support\Http\Controllers\RequestInformation;
|
use FireflyIII\Support\Http\Controllers\RequestInformation;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Google2FA;
|
use Google2FA;
|
||||||
@@ -42,9 +43,7 @@ use Hash;
|
|||||||
use Illuminate\Contracts\Auth\Guard;
|
use Illuminate\Contracts\Auth\Guard;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Laravel\Passport\ClientRepository;
|
use Laravel\Passport\ClientRepository;
|
||||||
use Laravel\Passport\Passport;
|
|
||||||
use Log;
|
use Log;
|
||||||
use phpseclib\Crypt\RSA;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ProfileController.
|
* Class ProfileController.
|
||||||
@@ -55,7 +54,7 @@ use phpseclib\Crypt\RSA;
|
|||||||
*/
|
*/
|
||||||
class ProfileController extends Controller
|
class ProfileController extends Controller
|
||||||
{
|
{
|
||||||
use RequestInformation;
|
use RequestInformation, CreateStuff;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProfileController constructor.
|
* ProfileController constructor.
|
||||||
@@ -442,27 +441,5 @@ class ProfileController extends Controller
|
|||||||
return redirect(route('login'));
|
return redirect(route('login'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create new RSA keys.
|
|
||||||
*/
|
|
||||||
protected function createOAuthKeys(): void // create stuff
|
|
||||||
{
|
|
||||||
$rsa = new RSA();
|
|
||||||
$keys = $rsa->createKey(4096);
|
|
||||||
|
|
||||||
[$publicKey, $privateKey] = [
|
|
||||||
Passport::keyPath('oauth-public.key'),
|
|
||||||
Passport::keyPath('oauth-private.key'),
|
|
||||||
];
|
|
||||||
|
|
||||||
if (file_exists($publicKey) || file_exists($privateKey)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// @codeCoverageIgnoreStart
|
|
||||||
Log::alert('NO OAuth keys were found. They have been created.');
|
|
||||||
|
|
||||||
file_put_contents($publicKey, array_get($keys, 'publickey'));
|
|
||||||
file_put_contents($privateKey, array_get($keys, 'privatekey'));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
use FireflyIII\Models\PiggyBank;
|
use FireflyIII\Models\PiggyBank;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -23,7 +23,6 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
use FireflyIII\Models\RuleGroup;
|
use FireflyIII\Models\RuleGroup;
|
||||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class RuleGroupFormRequest.
|
* Class RuleGroupFormRequest.
|
||||||
@@ -61,7 +60,7 @@ class RuleGroupFormRequest extends Request
|
|||||||
*/
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title';
|
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title';
|
||||||
|
|
||||||
/** @var RuleGroup $ruleGroup */
|
/** @var RuleGroup $ruleGroup */
|
||||||
$ruleGroup = $this->route()->parameter('ruleGroup');
|
$ruleGroup = $this->route()->parameter('ruleGroup');
|
||||||
|
@@ -30,6 +30,23 @@ namespace FireflyIII\Support\Http\Controllers;
|
|||||||
*/
|
*/
|
||||||
trait BasicDataSupport
|
trait BasicDataSupport
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Sum up an array.
|
||||||
|
*
|
||||||
|
* @param array $array
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function arraySum(array $array): string // filter + group data
|
||||||
|
{
|
||||||
|
$sum = '0';
|
||||||
|
foreach ($array as $entry) {
|
||||||
|
$sum = bcadd($sum, $entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sum;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the ID in a given array. Return '0' of not there (amount).
|
* Find the ID in a given array. Return '0' of not there (amount).
|
||||||
*
|
*
|
||||||
@@ -47,21 +64,4 @@ trait BasicDataSupport
|
|||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sum up an array.
|
|
||||||
*
|
|
||||||
* @param array $array
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function arraySum(array $array): string // filter + group data
|
|
||||||
{
|
|
||||||
$sum = '0';
|
|
||||||
foreach ($array as $entry) {
|
|
||||||
$sum = bcadd($sum, $entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $sum;
|
|
||||||
}
|
|
||||||
}
|
}
|
220
app/Support/Http/Controllers/CreateStuff.php
Normal file
220
app/Support/Http/Controllers/CreateStuff.php
Normal file
@@ -0,0 +1,220 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* CreateStuff.php
|
||||||
|
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III.
|
||||||
|
*
|
||||||
|
* Firefly III is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Firefly III is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\Support\Http\Controllers;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Exception;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use FireflyIII\Http\Requests\NewUserFormRequest;
|
||||||
|
use FireflyIII\Import\JobConfiguration\JobConfigurationInterface;
|
||||||
|
use FireflyIII\Import\Storage\ImportArrayStorage;
|
||||||
|
use FireflyIII\Models\ImportJob;
|
||||||
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
|
use FireflyIII\User;
|
||||||
|
use Laravel\Passport\Passport;
|
||||||
|
use Log;
|
||||||
|
use phpseclib\Crypt\RSA;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trait CreateStuff
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Support\Http\Controllers
|
||||||
|
*/
|
||||||
|
trait CreateStuff
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an asset account.
|
||||||
|
*
|
||||||
|
* @param NewUserFormRequest $request
|
||||||
|
* @param TransactionCurrency $currency
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function createAssetAccount(NewUserFormRequest $request, TransactionCurrency $currency): bool // create stuff
|
||||||
|
{
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
|
$assetAccount = [
|
||||||
|
'name' => $request->get('bank_name'),
|
||||||
|
'iban' => null,
|
||||||
|
'accountType' => 'asset',
|
||||||
|
'virtualBalance' => 0,
|
||||||
|
'account_type_id' => null,
|
||||||
|
'active' => true,
|
||||||
|
'accountRole' => 'defaultAsset',
|
||||||
|
'openingBalance' => $request->input('bank_balance'),
|
||||||
|
'openingBalanceDate' => new Carbon,
|
||||||
|
'currency_id' => $currency->id,
|
||||||
|
];
|
||||||
|
|
||||||
|
$repository->store($assetAccount);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a cash wallet.
|
||||||
|
*
|
||||||
|
* @param TransactionCurrency $currency
|
||||||
|
* @param string $language
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function createCashWalletAccount(TransactionCurrency $currency, string $language): bool // create stuff
|
||||||
|
{
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
|
$assetAccount = [
|
||||||
|
'name' => (string)trans('firefly.cash_wallet', [], $language),
|
||||||
|
'iban' => null,
|
||||||
|
'accountType' => 'asset',
|
||||||
|
'virtualBalance' => 0,
|
||||||
|
'account_type_id' => null,
|
||||||
|
'active' => true,
|
||||||
|
'accountRole' => 'cashWalletAsset',
|
||||||
|
'openingBalance' => null,
|
||||||
|
'openingBalanceDate' => null,
|
||||||
|
'currency_id' => $currency->id,
|
||||||
|
];
|
||||||
|
|
||||||
|
$repository->store($assetAccount);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new RSA keys.
|
||||||
|
*/
|
||||||
|
protected function createOAuthKeys(): void // create stuff
|
||||||
|
{
|
||||||
|
$rsa = new RSA();
|
||||||
|
$keys = $rsa->createKey(4096);
|
||||||
|
|
||||||
|
[$publicKey, $privateKey] = [
|
||||||
|
Passport::keyPath('oauth-public.key'),
|
||||||
|
Passport::keyPath('oauth-private.key'),
|
||||||
|
];
|
||||||
|
|
||||||
|
if (file_exists($publicKey) || file_exists($privateKey)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
|
Log::alert('NO OAuth keys were found. They have been created.');
|
||||||
|
|
||||||
|
file_put_contents($publicKey, array_get($keys, 'publickey'));
|
||||||
|
file_put_contents($privateKey, array_get($keys, 'privatekey'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a savings account.
|
||||||
|
*
|
||||||
|
* @param NewUserFormRequest $request
|
||||||
|
* @param TransactionCurrency $currency
|
||||||
|
* @param string $language
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function createSavingsAccount(NewUserFormRequest $request, TransactionCurrency $currency, string $language): bool // create stuff
|
||||||
|
{
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
|
$savingsAccount = [
|
||||||
|
'name' => (string)trans('firefly.new_savings_account', ['bank_name' => $request->get('bank_name')], $language),
|
||||||
|
'iban' => null,
|
||||||
|
'accountType' => 'asset',
|
||||||
|
'account_type_id' => null,
|
||||||
|
'virtualBalance' => 0,
|
||||||
|
'active' => true,
|
||||||
|
'accountRole' => 'savingAsset',
|
||||||
|
'openingBalance' => $request->input('savings_balance'),
|
||||||
|
'openingBalanceDate' => new Carbon,
|
||||||
|
'currency_id' => $currency->id,
|
||||||
|
];
|
||||||
|
$repository->store($savingsAccount);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new user instance after a valid registration.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @return \FireflyIII\User
|
||||||
|
*/
|
||||||
|
protected function createUser(array $data): User // create object
|
||||||
|
{
|
||||||
|
return User::create(
|
||||||
|
[
|
||||||
|
'email' => $data['email'],
|
||||||
|
'password' => bcrypt($data['password']),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a configurator object.
|
||||||
|
*
|
||||||
|
* @param ImportJob $importJob
|
||||||
|
*
|
||||||
|
* @return JobConfigurationInterface
|
||||||
|
*
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
protected function makeConfigurator(ImportJob $importJob): JobConfigurationInterface // make object
|
||||||
|
{
|
||||||
|
$key = sprintf('import.configuration.%s', $importJob->provider);
|
||||||
|
$className = (string)config($key);
|
||||||
|
if (null === $className || !class_exists($className)) {
|
||||||
|
throw new FireflyException(sprintf('Cannot find configurator class for job with provider "%s".', $importJob->provider)); // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
Log::debug(sprintf('Going to create class "%s"', $className));
|
||||||
|
/** @var JobConfigurationInterface $configurator */
|
||||||
|
$configurator = app($className);
|
||||||
|
$configurator->setImportJob($importJob);
|
||||||
|
|
||||||
|
return $configurator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store the transactions.
|
||||||
|
*
|
||||||
|
* @param ImportJob $importJob
|
||||||
|
*
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
protected function storeTransactions(ImportJob $importJob): void // make object + execute
|
||||||
|
{
|
||||||
|
/** @var ImportArrayStorage $storage */
|
||||||
|
$storage = app(ImportArrayStorage::class);
|
||||||
|
$storage->setImportJob($importJob);
|
||||||
|
try {
|
||||||
|
$storage->store();
|
||||||
|
} catch (FireflyException|Exception $e) {
|
||||||
|
throw new FireflyException($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -44,8 +44,9 @@ use Illuminate\Support\Collection;
|
|||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Log;
|
use Log;
|
||||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
|
||||||
use Route as RouteFacade;
|
use Route as RouteFacade;
|
||||||
|
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trait RequestInformation
|
* Trait RequestInformation
|
||||||
*
|
*
|
||||||
|
@@ -87,16 +87,6 @@ trait UserNavigation
|
|||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Remember previous URL.
|
|
||||||
*
|
|
||||||
* @param string $identifier
|
|
||||||
*/
|
|
||||||
protected function rememberPreviousUri(string $identifier): void
|
|
||||||
{
|
|
||||||
session()->put($identifier, URL::previous());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
*
|
*
|
||||||
@@ -124,4 +114,14 @@ trait UserNavigation
|
|||||||
|
|
||||||
return redirect(route('accounts.show', [$opposingTransaction->account_id]));
|
return redirect(route('accounts.show', [$opposingTransaction->account_id]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remember previous URL.
|
||||||
|
*
|
||||||
|
* @param string $identifier
|
||||||
|
*/
|
||||||
|
protected function rememberPreviousUri(string $identifier): void
|
||||||
|
{
|
||||||
|
session()->put($identifier, URL::previous());
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user