New stuff pertaining to the import procedure and user registration.

This commit is contained in:
James Cole
2014-07-05 16:19:15 +02:00
parent c3254c2351
commit a0c0dc288d
23 changed files with 305 additions and 63 deletions

View File

@@ -3,6 +3,8 @@
namespace Firefly\Storage\Account;
use Firefly\Helper\MigrationException;
class EloquentAccountRepository implements AccountRepositoryInterface
{
public $validator;
@@ -28,11 +30,17 @@ class EloquentAccountRepository implements AccountRepositoryInterface
$initial->user()->associate(\Auth::user());
$initial->name = $data['name'] . ' initial balance';
$initial->active = 0;
$initial->save();
try {
$initial->save();
} catch (\Illuminate\Database\QueryException $e) {
\Log::error('DB ERROR: ' . $e->getMessage());
throw new FireflyException('Could not save counterbalance account for ' . $data['name']);
}
// create new transaction journal (and transactions):
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalInterface $transactionJournal */
$transactionJournal = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalInterface');
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $transactionJournal */
$transactionJournal = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
$transactionJournal->createSimpleJournal(
$initial, $account, 'Initial Balance for ' . $data['name'], $amount, $date
);
@@ -54,7 +62,13 @@ class EloquentAccountRepository implements AccountRepositoryInterface
$account->user()->associate(\Auth::user());
$account->name = $data['name'];
$account->active = isset($data['active']) ? $data['active'] : 1;
$account->save();
try {
$account->save();
} catch (\Illuminate\Database\QueryException $e) {
\Log::error('DB ERROR: ' . $e->getMessage());
throw new \Firefly\Exception\FireflyException('Could not save account ' . $data['name']);
}
return $account;
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Firefly\Storage\Component;
interface ComponentRepositoryInterface
{
public function count();
public function store($data);
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Firefly\Storage\Component;
class EloquentComponentRepository implements ComponentRepositoryInterface
{
public $validator;
public function __construct()
{
}
public function count()
{
return \Auth::user()->accounts()->count();
}
public function store($data)
{
if (!isset($data['component_type'])) {
throw new \Firefly\Exception\FireflyException('No component type present.');
}
$component = new \Component;
$component->componentType()->associate($data['component_type']);
$component->name = $data['name'];
$component->user()->associate(\Auth::user());
try {
$component->save();
} catch (\Illuminate\Database\QueryException $e) {
\Log::error('DB ERROR: ' . $e->getMessage());
throw new \Firefly\Exception\FireflyException('Could not save component ' . $data['name']);
}
return $component;
}
}

View File

@@ -21,9 +21,13 @@ class StorageServiceProvider extends ServiceProvider
'Firefly\Storage\Account\EloquentAccountRepository'
);
$this->app->bind(
'Firefly\Storage\TransactionJournal\TransactionJournalInterface',
'Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface',
'Firefly\Storage\TransactionJournal\EloquentTransactionJournalRepository'
);
$this->app->bind(
'Firefly\Storage\Component\ComponentRepositoryInterface',
'Firefly\Storage\Component\EloquentComponentRepository'
);
}
}

View File

@@ -9,7 +9,7 @@
namespace Firefly\Storage\TransactionJournal;
class EloquentTransactionJournalRepository implements TransactionJournalInterface
class EloquentTransactionJournalRepository implements TransactionJournalRepositoryInterface
{
public function createSimpleJournal(\Account $from, \Account $to, $description, $amount, \Carbon\Carbon $date)
@@ -45,6 +45,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalInterfac
$toAT = $to->accountType->description;
$fromAT = $from->accountType->description;
$journalType = null;
switch (true) {
// is withdrawal from one of your own accounts:
@@ -66,8 +67,17 @@ class EloquentTransactionJournalRepository implements TransactionJournalInterfac
$journalType = \TransactionType::where('type', 'Deposit')->first();
break;
}
if (is_null($journalType)) {
\Log::error('Could not figure out transacion type!');
throw new \Firefly\Exception\FireflyException('Could not figure out transaction type.');
}
// always the same currency:
$currency = \TransactionCurrency::where('code', 'EUR')->first();
if (is_null($currency)) {
\Log::error('No currency for journal!');
throw new \Firefly\Exception\FireflyException('No currency for journal!');
}
// new journal:
$journal = new \TransactionJournal();
@@ -77,7 +87,9 @@ class EloquentTransactionJournalRepository implements TransactionJournalInterfac
$journal->description = $description;
$journal->date = $date;
if (!$journal->isValid()) {
return false;
\Log::error('Cannot create valid journal.');
\Log::error('Errors: ' . print_r($journal->validator->messages()->all(), true));
throw new \Firefly\Exception\FireflyException('Cannot create valid journal.');
}
$journal->save();
@@ -88,7 +100,9 @@ class EloquentTransactionJournalRepository implements TransactionJournalInterfac
$fromTransaction->description = null;
$fromTransaction->amount = $amountFrom;
if (!$fromTransaction->isValid()) {
return false;
\Log::error('Cannot create valid transaction (from) for journal #' . $journal->id);
\Log::error('Errors: ' . print_r($fromTransaction->validator->messages()->all(), true));
throw new \Firefly\Exception\FireflyException('Cannot create valid transaction (from).');
}
$fromTransaction->save();
@@ -98,7 +112,11 @@ class EloquentTransactionJournalRepository implements TransactionJournalInterfac
$toTransaction->description = null;
$toTransaction->amount = $amountTo;
if (!$toTransaction->isValid()) {
return false;
if (!$toTransaction->isValid()) {
\Log::error('Cannot create valid transaction (to) for journal #' . $journal->id);
\Log::error('Errors: ' . print_r($toTransaction->validator->messages()->all(), true));
throw new \Firefly\Exception\FireflyException('Cannot create valid transaction (to).');
}
}
$toTransaction->save();
@@ -107,7 +125,6 @@ class EloquentTransactionJournalRepository implements TransactionJournalInterfac
return;
echo 'saved!';
}

View File

@@ -9,7 +9,7 @@
namespace Firefly\Storage\TransactionJournal;
interface TransactionJournalInterface {
interface TransactionJournalRepositoryInterface {
public function createSimpleJournal(\Account $from, \Account $to, $description, $amount, \Carbon\Carbon $date);

View File

@@ -14,12 +14,12 @@ class EloquentUserRepository implements UserRepositoryInterface
$user = new \User;
$user->email = isset($array['email']) ? $array['email'] : null;
$user->migrated = 0;
$user->verification = \Str::random(32);
$user->reset = \Str::random(32);
$user->password = \Hash::make(\Str::random(12));
if (!$user->isValid()) {
\Log::error('Invalid user');
\Session::flash('error', 'Input invalid, please try again.');
\Session::flash('error', 'Input invalid, please try again: ' . $user->validator->messages()->first());
return false;
}
$user->save();
@@ -36,11 +36,6 @@ class EloquentUserRepository implements UserRepositoryInterface
return false;
}
public function findByVerification($verification)
{
return \User::where('verification', $verification)->first();
}
public function findByReset($reset)
{
return \User::where('reset', $reset)->first();

View File

@@ -10,12 +10,11 @@ interface UserRepositoryInterface
public function auth($array);
public function findByVerification($verification);
public function findByReset($reset);
public function findByEmail($email);
public function updatePassword(\User $user,$password);
public function updatePassword(\User $user, $password);
}