Various small updates [skip ci]

This commit is contained in:
James Cole
2014-08-06 07:06:45 +02:00
parent 2d0820873a
commit 5e809633e3
11 changed files with 100 additions and 47 deletions

View File

@@ -67,7 +67,7 @@ class ChartController extends BaseController
} }
// loop and get array data. // loop and get array data.
$url = count($accounts) == 1 $url = count($accounts) == 1 && is_array($accounts)
? '<a href="' . route('accounts.show', [$account->id]) . '">View more</a>' ? '<a href="' . route('accounts.show', [$account->id]) . '">View more</a>'
: :
'<a href="' . route('accounts.index') . '">View more</a>'; '<a href="' . route('accounts.index') . '">View more</a>';

View File

@@ -21,7 +21,9 @@ class CreateUsersTable extends Migration {
$table->string('reset',32)->nullable(); $table->string('reset',32)->nullable();
$table->string('remember_token',255)->nullable(); $table->string('remember_token',255)->nullable();
$table->boolean('migrated'); $table->boolean('migrated');
});
$table->unique('email');
});
} }
/** /**

View File

@@ -30,6 +30,8 @@ class CreateAccountsTable extends Migration {
$table->foreign('account_type_id') $table->foreign('account_type_id')
->references('id')->on('account_types') ->references('id')->on('account_types')
->onDelete('cascade'); ->onDelete('cascade');
$table->unique(['user_id','account_type_id','name']);
}); });
} }

View File

@@ -24,7 +24,10 @@ class CreateComponentsTable extends Migration {
$table->foreign('user_id') $table->foreign('user_id')
->references('id')->on('users') ->references('id')->on('users')
->onDelete('cascade'); ->onDelete('cascade');
$table->unique(['user_id','class','name']);
}); });
} }
/** /**

View File

@@ -19,7 +19,7 @@ class CreatePiggybanksTable extends Migration
$table->timestamps(); $table->timestamps();
$table->integer('account_id')->unsigned(); $table->integer('account_id')->unsigned();
$table->date('targetdate')->nullable(); $table->date('targetdate')->nullable();
$table->string('name', 500); $table->string('name', 100);
$table->decimal('amount', 10, 2); $table->decimal('amount', 10, 2);
$table->decimal('target', 10, 2)->nullable(); $table->decimal('target', 10, 2)->nullable();
$table->integer('order')->unsigned(); $table->integer('order')->unsigned();
@@ -28,6 +28,7 @@ class CreatePiggybanksTable extends Migration
$table->foreign('account_id') $table->foreign('account_id')
->references('id')->on('accounts') ->references('id')->on('accounts')
->onDelete('cascade'); ->onDelete('cascade');
$table->unique(['account_id','name']);
} }
); );

View File

@@ -12,10 +12,20 @@ class CreateRecurringTransactionsTable extends Migration {
*/ */
public function up() public function up()
{ {
Schema::create('recurringtransactions', function(Blueprint $table) Schema::create('recurring_transactions', function(Blueprint $table)
{ {
$table->increments('id'); $table->increments('id');
$table->timestamps(); $table->timestamps();
$table->integer('user_id')->unsigned();
$table->string('name',50);
$table->decimal('amount_max',10,2);
$table->decimal('amount_min',10,2);
$table->boolean('active');
$table->enum('repeat_freq', ['daily', 'weekly','monthly','quarterly','half-year','yearly']);
$table->unique(['user_id','name']);
}); });
} }
@@ -26,7 +36,7 @@ class CreateRecurringTransactionsTable extends Migration {
*/ */
public function down() public function down()
{ {
Schema::drop('recurringtransactions'); Schema::drop('recurring_transactions');
} }
} }

View File

@@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class RecurringTransactionsToComponents extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('component_recurring_transaction', function(Blueprint $table)
{
$table->increments('id');
$table->integer('component_id')->unsigned();
$table->integer('recurring_transaction_id')->unsigned();
// link components with component_id
$table->foreign('component_id')
->references('id')->on('components')
->onDelete('cascade');
// link transaction journals with transaction_journal_id
$table->foreign('recurring_transaction_id')
->references('id')->on('recurring_transactions')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('component_recurring_transaction');
}
}

View File

@@ -18,7 +18,7 @@ class EmailHelper implements EmailHelperInterface
$reset = \Str::random(32); $reset = \Str::random(32);
$user->reset = $reset; $user->reset = $reset;
$user->save(); $user->forceSave();
$email = $user->email; $email = $user->email;
$data = ['reset' => $reset]; $data = ['reset' => $reset];
@@ -40,7 +40,7 @@ class EmailHelper implements EmailHelperInterface
$password = \Str::random(12); $password = \Str::random(12);
$user->password = \Hash::make($password); $user->password = \Hash::make($password);
$user->reset = \Str::random(32); // new one. $user->reset = \Str::random(32); // new one.
$user->save(); $user->forceSave();
$email = $user->email; $email = $user->email;
@@ -61,7 +61,7 @@ class EmailHelper implements EmailHelperInterface
{ {
$reset = \Str::random(32); $reset = \Str::random(32);
$user->reset = $reset; $user->reset = $reset;
$user->save(); $user->forceSave();
$email = $user->email; $email = $user->email;
$data = ['reset' => $reset]; $data = ['reset' => $reset];

View File

@@ -17,30 +17,6 @@ class EloquentUserRepository implements UserRepositoryInterface
{ {
} }
/**
* @param $array
*
* @return bool|\User
*/
public function register($array)
{
$user = new \User;
$user->email = isset($array['email']) ? $array['email'] : null;
$user->migrated = 0;
$user->reset = \Str::random(32);
$user->password = \Hash::make(\Str::random(12));
if (!$user->save()) {
\Log::error('Invalid user');
\Session::flash('error', 'Input invalid, please try again: ' . $user->errors()->first());
return false;
}
$user->save();
return $user;
}
/** /**
* @param $array * @param $array
* *
@@ -57,6 +33,16 @@ class EloquentUserRepository implements UserRepositoryInterface
return false; return false;
} }
/**
* @param $email
*
* @return mixed
*/
public function findByEmail($email)
{
return \User::where('email', $email)->first();
}
/** /**
* @param $reset * @param $reset
* *
@@ -68,13 +54,26 @@ class EloquentUserRepository implements UserRepositoryInterface
} }
/** /**
* @param $email * @param $array
* *
* @return mixed * @return bool|\User
*/ */
public function findByEmail($email) public function register($array)
{ {
return \User::where('email', $email)->first(); $user = new \User;
$user->email = isset($array['email']) ? $array['email'] : null;
$user->migrated = 0;
$user->reset = \Str::random(32);
$user->password = \Hash::make(\Str::random(12));
if (!$user->save()) {
\Log::error('Invalid user');
\Session::flash('error', 'Input invalid, please try again: ' . $user->errors()->first());
return false;
}
$user->save();
return $user;
} }
/** /**
@@ -89,13 +88,7 @@ class EloquentUserRepository implements UserRepositoryInterface
/** @noinspection PhpUndefinedFieldInspection */ /** @noinspection PhpUndefinedFieldInspection */
$user->password = $password; $user->password = $password;
/** @noinspection PhpUndefinedMethodInspection */ /** @noinspection PhpUndefinedMethodInspection */
if($user->validate()) { $user->forceSave();
$user->save();
} else {
var_dump($user->errors()->all());
exit;
}
$user->save();
return true; return true;
} }

View File

@@ -42,7 +42,7 @@ class User extends Ardent implements UserInterface, RemindableInterface
public static $rules public static $rules
= [ = [
'email' => 'required|email', 'email' => 'required|email|unique:users,email',
'migrated' => 'required|numeric|between:0,1', 'migrated' => 'required|numeric|between:0,1',
'password' => 'required|between:60,60', 'password' => 'required|between:60,60',
'reset' => 'between:32,32', 'reset' => 'between:32,32',
@@ -66,7 +66,7 @@ class User extends Ardent implements UserInterface, RemindableInterface
* *
* @var array * @var array
*/ */
protected $hidden = array('remember_token'); protected $hidden = ['remember_token'];
public function accounts() public function accounts()
{ {

View File

@@ -22,7 +22,6 @@
</p> </p>
</div> </div>
</div> </div>
<div id="something">Bla bla</div>
<div class="row"> <div class="row">
<div class="col-lg-6 col-md-6 col-sm-12"> <div class="col-lg-6 col-md-6 col-sm-12">
<h2><a href="{{route('migrate')}}">Migrate from Firefly II</a></h2> <h2><a href="{{route('migrate')}}">Migrate from Firefly II</a></h2>
@@ -32,7 +31,7 @@
</p> </p>
</div> </div>
<div class="col-lg-6 col-md-6 col-sm-12"> <div class="col-lg-6 col-md-6 col-sm-12">
<h2><a href="#">Start from scratch</a></h2> <h2><a href="{{route('accounts.create')}}">Start from scratch</a></h2>
<p> <p>
Use this option if you are new to Firefly (III). Use this option if you are new to Firefly (III).