Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
New code, building a migration routine.
James Coleecadf005a868
diff --git a/app/config/database.php b/app/config/database.phpindex 000eceaa7b..3dc48bdd8e 100644--- a/app/config/database.php+++ b/app/config/database.php@@ -4,13 +4,6 @@ return ['fetch' => PDO::FETCH_CLASS,'default' => 'mysql','connections' => [-- 'sqlite' => [- 'driver' => 'sqlite',- 'database' => __DIR__ . '/../database/production.sqlite',- 'prefix' => '',- ],-'mysql' => ['driver' => 'mysql','host' => 'localhost',@@ -21,6 +14,18 @@ return ['collation' => 'utf8_unicode_ci','prefix' => '',],+ // previous database, if present:+ 'old-firefly' => [+ 'driver' => 'mysql',+ 'host' => 'localhost',+ 'database' => '(previous database)',+ 'username' => '',+ 'password' => '',+ 'charset' => 'utf8',+ 'collation' => 'utf8_unicode_ci',+ 'prefix' => '',+ ],+],'migrations' => 'migrations','redis' => [diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.phpindex d6670a8145..5619bfd06e 100644--- a/app/controllers/HomeController.php+++ b/app/controllers/HomeController.php@@ -1,11 +1,25 @@<?php+use Firefly\Storage\Account\AccountRepositoryInterface as ARI;+class HomeController extends BaseController {+ public function __construct(ARI $accounts) {+ $this->accounts = $accounts;+ }+public function index(){+ $count = $this->accounts->count();+ if($count == 0) {+ return Redirect::route('start');+ }return View::make('index');}+ public function start() {+ return View::make('start');+ }+}diff --git a/app/controllers/MigrationController.php b/app/controllers/MigrationController.phpnew file mode 100644index 0000000000..acc1d03bb2--- /dev/null+++ b/app/controllers/MigrationController.php@@ -0,0 +1,29 @@+<?php+class MigrationController extends BaseController {+ public function index() {+ // check if database connection is present.+ $configValue = Config::get('database.connections.old-firefly');+ if(is_null($configValue)) {+ return View::make('migrate.index');+ }++ // try to connect to it:+ try {+ DB::connection('old-firefly')->select('SELECT * from `users`;');+ } catch(PDOException $e) {+ return View::make('migrate.index');+ }++ return Redirect::route('migrate.select-user');+++ }++ public function selectUser() {+ // select a user to import data from.+ }++ public function migrate($userID) {+ // import the data.+ }+}\ No newline at end of filediff --git a/app/controllers/UserController.php b/app/controllers/UserController.phpindex 46e01edefc..931c033400 100644--- a/app/controllers/UserController.php+++ b/app/controllers/UserController.php@@ -22,13 +22,10 @@ class UserController extends BaseController{if (!$this->user->auth()) {$rememberMe = Input::get('remember_me') == '1';- $result = [];$data = [- 'email' => Input::get('email'),+ 'email' => Input::get('email'),'password' => Input::get('password')];--if (Auth::attempt($data, $rememberMe)) {return Redirect::route('index');}@@ -62,6 +59,33 @@ class UserController extends BaseControllerreturn View::make('user.register');}+ public function logout()+ {+ Auth::logout();+ return Redirect::route('index');+ }++ public function remindme()+ {+ return View::make('user.remindme');+ }++ public function postRemindme()+ {+ $user = $this->user->findByEmail(Input::get('email'));+ if ($user) {+ if (Config::get('auth.verify_reset') === true) {+ $this->email->sendResetVerification($user);+ }+ if (Config::get('auth.verify_reset') === false) {+ $this->email->sendPasswordMail($user);+ }+ }+ Session::flash('error', 'No good!');+ return View::make('user.remindme');++ }+public function verify($verification){$user = $this->user->findByVerification($verification);@@ -71,5 +95,14 @@ class UserController extends BaseController}return View::make('error')->with('message', 'Yo no hablo verification code!');}+ public function reset($reset)+ {+ $user = $this->user->findByReset($reset);+ if ($user) {+ $this->email->sendPasswordMail($user);+ return View::make('user.registered');+ }+ return View::make('error')->with('message', 'Yo no hablo reset code!');+ }}\ No newline at end of filediff --git a/app/database/migrations/2014_06_27_163032_create_users_table.php b/app/database/migrations/2014_06_27_163032_create_users_table.phpindex 380223be20..29ea724880 100644--- a/app/database/migrations/2014_06_27_163032_create_users_table.php+++ b/app/database/migrations/2014_06_27_163032_create_users_table.php@@ -18,7 +18,8 @@ class CreateUsersTable extends Migration {$table->timestamps();$table->string('email',100);$table->string('password',60);- $table->string('verification',32);+ $table->string('verification',32)->nullable();+ $table->string('reset',32)->nullable();$table->string('remember_token',255)->nullable();$table->boolean('migrated');});diff --git a/app/lib/Firefly/Helper/Email/EmailHelper.php b/app/lib/Firefly/Helper/Email/EmailHelper.phpindex 366f9fcf92..d1defb325c 100644--- a/app/lib/Firefly/Helper/Email/EmailHelper.php+++ b/app/lib/Firefly/Helper/Email/EmailHelper.php@@ -37,4 +37,21 @@ class EmailHelper implements EmailHelperInterface);}+ public function sendResetVerification(\User $user)+ {+ $reset = \Str::random(32);+ $user->reset = $reset;+ $user->save();+ $email = $user->email;++ $data = ['reset' => $reset];+ \Mail::send(+ ['emails.user.remindme-html', 'emails.user.remindme-text'], $data, function ($message) use ($email) {+ $message->to($email, $email)->subject('Forgot your password?');+ }+ );+++ }+}\ No newline at end of filediff --git a/app/lib/Firefly/Helper/Email/EmailHelperInterface.php b/app/lib/Firefly/Helper/Email/EmailHelperInterface.phpindex 4dba74bc30..9f671f205c 100644--- a/app/lib/Firefly/Helper/Email/EmailHelperInterface.php+++ b/app/lib/Firefly/Helper/Email/EmailHelperInterface.php@@ -6,5 +6,6 @@ interface EmailHelperInterface {public function sendVerificationMail(\User $user);public function sendPasswordMail(\User $user);+ public function sendResetVerification(\User $user);}\ No newline at end of filediff --git a/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.php b/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.phpnew file mode 100644index 0000000000..39399bdbce--- /dev/null+++ b/app/lib/Firefly/Storage/Account/AccountRepositoryInterface.php@@ -0,0 +1,11 @@+<?php+++namespace Firefly\Storage\Account;+++interface AccountRepositoryInterface+{+ public function count();++}\ No newline at end of filediff --git a/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php b/app/lib/Firefly/Storage/Account/EloquentAccountRepository.phpnew file mode 100644index 0000000000..81fbca3990--- /dev/null+++ b/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php@@ -0,0 +1,17 @@+<?php+++namespace Firefly\Storage\Account;++class EloquentAccountRepository implements AccountRepositoryInterface+{+ public function __construct()+ {+ }++ public function count() {+ return \Auth::user()->accounts()->count();++ }++}\ No newline at end of filediff --git a/app/lib/Firefly/Storage/StorageServiceProvider.php b/app/lib/Firefly/Storage/StorageServiceProvider.phpindex 5023f78eb8..58c6eb2868 100644--- a/app/lib/Firefly/Storage/StorageServiceProvider.php+++ b/app/lib/Firefly/Storage/StorageServiceProvider.php@@ -15,6 +15,11 @@ class StorageServiceProvider extends ServiceProvider'Firefly\Storage\User\UserRepositoryInterface','Firefly\Storage\User\EloquentUserRepository');++ $this->app->bind(+ 'Firefly\Storage\Account\AccountRepositoryInterface',+ 'Firefly\Storage\Account\EloquentAccountRepository'+ );}}\ No newline at end of filediff --git a/app/lib/Firefly/Storage/User/EloquentUserRepository.php b/app/lib/Firefly/Storage/User/EloquentUserRepository.phpindex d9693e5630..492d232416 100644--- a/app/lib/Firefly/Storage/User/EloquentUserRepository.php+++ b/app/lib/Firefly/Storage/User/EloquentUserRepository.php@@ -41,4 +41,13 @@ class EloquentUserRepository implements UserRepositoryInterfacereturn \User::where('verification', $verification)->first();}+ public function findByReset($reset)+ {+ return \User::where('reset', $reset)->first();+ }+ public function findByEmail($email)+ {+ return \User::where('email', $email)->first();+ }+}\ No newline at end of filediff --git a/app/lib/Firefly/Storage/User/UserRepositoryInterface.php b/app/lib/Firefly/Storage/User/UserRepositoryInterface.phpindex 4a39c50489..b369e5f852 100644--- a/app/lib/Firefly/Storage/User/UserRepositoryInterface.php+++ b/app/lib/Firefly/Storage/User/UserRepositoryInterface.php@@ -7,9 +7,13 @@ namespace Firefly\Storage\User;interface UserRepositoryInterface{public function register();+public function auth();public function findByVerification($verification);+ public function findByReset($reset);++ public function findByEmail($email);}\ No newline at end of filediff --git a/app/models/User.php b/app/models/User.phpindex 16ddbeee20..aab02454ea 100644--- a/app/models/User.php+++ b/app/models/User.php@@ -33,4 +33,8 @@ class User extends Elegant implements UserInterface, RemindableInterface*/protected $hidden = array('password', 'remember_token');+ public function accounts() {+ return $this->hasMany('Account');+ }+}diff --git a/app/routes.php b/app/routes.phpindex ec948bd205..c04c861fdd 100644--- a/app/routes.php+++ b/app/routes.php@@ -1,10 +1,21 @@<?php++// basic home views:Route::get('/', ['uses' => 'HomeController@index','as' => 'index','before' => 'auth']);+Route::get('/start', ['uses' => 'HomeController@start','as' => 'start','before' => 'auth']);++// migration controller:+Route::get('/migrate/index', ['uses' => 'MigrationController@index','as' => 'migrate.index', 'before' => 'auth']);// login, register, logout:Route::get('/login',['uses' => 'UserController@login','as' => 'login','before' => 'guest']);Route::get('/register',['uses' => 'UserController@register','as' => 'register','before' => 'guest']);Route::get('/verify/{verification}',['uses' => 'UserController@verify','as' => 'verify','before' => 'guest']);+Route::get('/reset/{reset}',['uses' => 'UserController@reset','as' => 'reset','before' => 'guest']);+Route::get('/logout',['uses' => 'UserController@logout','as' => 'logout','before' => 'auth']);+Route::get('/remindme',['uses' => 'UserController@remindme','as' => 'remindme','before' => 'guest']);+Route::post('/login',['uses' => 'UserController@postLogin','before' => 'csrf|guest']);Route::post('/register',['uses' => 'UserController@postRegister','before' => 'csrf|guest']);+Route::post('/remindme',['uses' => 'UserController@postRemindme','before' => 'csrf|guest']);\ No newline at end of filediff --git a/app/views/emails/user/remindme-html.blade.php b/app/views/emails/user/remindme-html.blade.phpnew file mode 100644index 0000000000..e16c85fafe--- /dev/null+++ b/app/views/emails/user/remindme-html.blade.php@@ -0,0 +1,19 @@+<html>+<head>+ <style type="text/css">+ * {font-size:Arial;}+ </style>+</head>+<body>+<p>+ Hi!+</p>+<p>+ To get a new password, please <a href="{{route('reset',$reset)}}">verify your e-mail address</a>.+</p>+<p>+ Cya!+</p>++</body>+</html>\ No newline at end of filediff --git a/app/views/emails/user/remindme-text.php b/app/views/emails/user/remindme-text.phpnew file mode 100644index 0000000000..8d1980a3e4--- /dev/null+++ b/app/views/emails/user/remindme-text.php@@ -0,0 +1,5 @@+Hi!++To get a new password, please verify your e-mail address: {{route('reset',$reset)}}++Cya!diff --git a/app/views/index.blade.php b/app/views/index.blade.phpindex ee6cb58b96..07fe446d52 100644--- a/app/views/index.blade.php+++ b/app/views/index.blade.php@@ -7,5 +7,10 @@@if(Auth::check())logged in!@endif++<br />+<a href="{{route('logout')}}">logout!</a>++</body></html>\ No newline at end of filediff --git a/app/views/layouts/default.blade.php b/app/views/layouts/default.blade.phpindex d7a18ece51..d0187cfb9e 100644--- a/app/views/layouts/default.blade.php+++ b/app/views/layouts/default.blade.php@@ -4,7 +4,7 @@<meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1">- <base href="{{url::to('/')}}">+ <base href="{{URL::route('index')}}/"><title>Firefly</title><!-- Bootstrap -->diff --git a/app/views/migrate/index.blade.php b/app/views/migrate/index.blade.phpnew file mode 100644index 0000000000..2360e87d61--- /dev/null+++ b/app/views/migrate/index.blade.php@@ -0,0 +1,50 @@+@extends('layouts.default')+@section('content')+<div class="row">+ <div class="col-lg-8 col-md-8 col-sm-12">+ <h1>Firefly<br/>+ <small>Migration instructions</small>+ </h1>+ <ol>+ <li>Open <code>app/config/database.php</code></li>+ <li>Fill in the <code>old-firefly</code> connection records.</li>+ <li>Refresh this page.</li>+ </ol>+ <p>+ It should look something like this:+ </p>+<pre>+return [+ 'fetch' => PDO::FETCH_CLASS,+ 'default' => 'mysql',+ 'connections' => [+ 'mysql' => [+ 'driver' => 'mysql',+ 'host' => 'localhost',+ 'database' => '(current database)',+ 'username' => '',+ 'password' => '',+ 'charset' => 'utf8',+ 'collation' => 'utf8_unicode_ci',+ 'prefix' => '',+ ],+ <strong>+ 'old-firefly' => [+ 'driver' => 'mysql',+ 'host' => 'localhost',+ 'database' => '(previous database)',+ 'username' => '',+ 'password' => '',+ 'charset' => 'utf8',+ 'collation' => 'utf8_unicode_ci',+ 'prefix' => '',+ ],</strong>+ ],+</pre>+ <p>+ Refresh this page; when the connection is valid this page will refresh.+ </p>+ </div>+</div>++@stop\ No newline at end of filediff --git a/app/views/start.blade.php b/app/views/start.blade.phpnew file mode 100644index 0000000000..cfbb5ca9f7--- /dev/null+++ b/app/views/start.blade.php@@ -0,0 +1,41 @@+@extends('layouts.default')+@section('content')+<div class="row">+ <div class="col-lg-12 col-md-12 col-sm-12">+ <h1>Firefly<br/>+ <small>Welcome!</small>+ </h1>+ </div>+</div>++<div class="row">+ <div class="col-lg-12 col-md-12 col-sm-12">+ <p>+ Welcome to Firefly! To get started, choose either of the two options below.+ </p>+ </div>+</div>++<div class="row">+ <div class="col-lg-6 col-md-6 col-sm-12">+ <h2>Start anew</h2>+ <p>+ Click the link below to create your first account, and get started with Firefly.+ </p>+ <p>+ <a href="#" class="btn btn-info">Start with a new account</a>+ </p>+ </div>++ <div class="col-lg-6 col-md-6 col-sm-12">+ <h2>Migrate from another Firefly</h2>+ <p>+ If you've used Firefly before and have another database around, follow this link to import+ your data from a previous version.+ </p>+ <p>+ <a href="{{route('migrate.index')}}" class="btn btn-info">Import your old data</a>+ </p>+ </div>+</div>+@stop\ No newline at end of filediff --git a/app/views/user/login.blade.php b/app/views/user/login.blade.phpindex 13da867dbe..692912e6f5 100644--- a/app/views/user/login.blade.php+++ b/app/views/user/login.blade.php@@ -44,7 +44,7 @@</p>@endif<p>- <a href="#" class="btn btn-default">Reset password</a>+ <a href="{{route('remindme')}}" class="btn btn-default">Forgot your password?</a></p></div>diff --git a/app/views/user/register.blade.php b/app/views/user/register.blade.phpindex 28bab127ba..ac6764b98e 100644--- a/app/views/user/register.blade.php+++ b/app/views/user/register.blade.php@@ -33,7 +33,7 @@<a href="{{route('login')}}" class="btn btn-default">Back to login form</a></p><p>- <a href="#" class="btn btn-default">Reset password</a>+ <a href="{{route('remindme')}}" class="btn btn-default">Reset password</a></p></div>diff --git a/app/views/user/remindme.blade.php b/app/views/user/remindme.blade.phpnew file mode 100644index 0000000000..94e8d38e16--- /dev/null+++ b/app/views/user/remindme.blade.php@@ -0,0 +1,42 @@+@extends('layouts.guest')+@section('content')+<div class="row">+ <div class="col-lg-12 col-md-12 col-sm-12">+ <h1>Firefly<br/>+ <small>Forgot your password?</small>+ </h1>+ </div>+</div>++<div class="row">+ <div class="col-lg-12 col-md-12 col-sm-12">+ </div>+</div>++<div class="row">+ <div class="col-lg-4 col-md-4 col-sm-12">+ {{Form::open()}}+ <div class="form-group">+ <label for="inputEmail">Email address</label>+ <input type="email" class="form-control" id="inputEmail" name="email" placeholder="Enter email">+ </div>+ <button type="submit" class="btn btn-info">Submit</button>+ {{Form::close()}}+ </div>+</div>+<div class="row">+ <div class="col-lg-4 col-md-4 col-sm-12">+ <p>+ + </p>+ <p>+ <a href="{{route('login')}}" class="btn btn-default">Back to login form</a>+ </p>+ <p>+ <a href="{{route('register')}}" class="btn btn-default">Register a new account</a>+ </p>++ </div>+</div>++@stop\ No newline at end of file