Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Various changes to support the removed old code.
James Cole5cb9907bf8cd
diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.phpindex 814436a793..4bf3ee667b 100644--- a/app/controllers/HomeController.php+++ b/app/controllers/HomeController.php@@ -19,14 +19,6 @@ class HomeController extends BaseController$this->_preferences = $preferences;}- public function jobDev()- {- $fullName = storage_path() . DIRECTORY_SEPARATOR . 'firefly-export-2014-07-23.json';- \Log::notice('Pushed start job.');- Queue::push('Firefly\Queue\Import@start', ['file' => $fullName, 'user' => 1]);-- }-/***/diff --git a/app/controllers/UserController.php b/app/controllers/UserController.phpindex 834c2bb9cb..60300f52e7 100644--- a/app/controllers/UserController.php+++ b/app/controllers/UserController.php@@ -1,8 +1,5 @@<?php-use Firefly\Helper\Email\EmailHelperInterface as EHI;-use Firefly\Storage\User\UserRepositoryInterface as URI;-/*** Class UserController*/@@ -11,15 +8,9 @@ class UserController extends BaseController/*** Constructor.- *- * @param URI $user- * @param EHI $email*/- public function __construct(URI $user, EHI $email)+ public function __construct(){- $this->user = $user;- $this->email = $email;-}/**@@ -84,14 +75,25 @@ class UserController extends BaseControllerif (Config::get('auth.allow_register') !== true) {return View::make('error')->with('message', 'Not possible');}- $user = $this->user->register(Input::all());++ /** @var \FireflyIII\Database\User $repository */+ $repository = App::make('FireflyIII\Database\User');++ /** @var \FireflyIII\Shared\Mail\RegistrationInterface $email */+ $email = App::make('FireflyIII\Shared\Mail\RegistrationInterface');++ $user = $repository->register(Input::all());++++ //$user = $this->user->register(Input::all());if ($user) {if (Config::get('auth.verify_mail') === true) {- $this->email->sendVerificationMail($user);+ $email->sendVerificationMail($user);return View::make('user.verification-pending');}- $this->email->sendPasswordMail($user);+ $email->sendPasswordMail($user);return View::make('user.registered');}@@ -130,18 +132,26 @@ class UserController extends BaseController*/public function postRemindme(){- $user = $this->user->findByEmail(Input::get('email'));++ /** @var \FireflyIII\Database\User $repository */+ $repository = App::make('FireflyIII\Database\User');++ /** @var \FireflyIII\Shared\Mail\RegistrationInterface $email */+ $email = App::make('FireflyIII\Shared\Mail\RegistrationInterface');+++ $user = $repository->findByEmail(Input::get('email'));if (!$user) {Session::flash('error', 'No good!');return View::make('user.remindme');}if (Config::get('auth.verify_reset') === true) {- $this->email->sendResetVerification($user);+ $email->sendResetVerification($user);return View::make('user.verification-pending');}- $this->email->sendPasswordMail($user);+ $email->sendPasswordMail($user);return View::make('user.registered');@@ -156,9 +166,16 @@ class UserController extends BaseController*/public function reset($reset){- $user = $this->user->findByReset($reset);++ /** @var \FireflyIII\Database\User $repository */+ $repository = App::make('FireflyIII\Database\User');++ /** @var \FireflyIII\Shared\Mail\RegistrationInterface $email */+ $email = App::make('FireflyIII\Shared\Mail\RegistrationInterface');++ $user = $repository->findByReset($reset);if ($user) {- $this->email->sendPasswordMail($user);+ $email->sendPasswordMail($user);return View::make('user.registered');}diff --git a/app/lib/FireflyIII/Database/User.php b/app/lib/FireflyIII/Database/User.phpnew file mode 100644index 0000000000..591b204991--- /dev/null+++ b/app/lib/FireflyIII/Database/User.php@@ -0,0 +1,57 @@+<?php++namespace FireflyIII\Database;+++/**+ * Class User+ * @package FireflyIII\Database+ */+class User+{++ /**+ * @param array $data+ * @return bool|\User+ */+ public function register(array $data)+ {+ $user = new \User;+ $user->email = isset($data['email']) ? $data['email'] : null;+ $user->migrated = 0;+ $user->reset = \Str::random(32);+ $user->password = \Hash::make(\Str::random(12));++ if (!$user->save()) {+ \Log::error('Invalid user with data: ' . isset($data['email']) ? $data['email'] : '(no email!)');+ \Session::flash('error', 'Input invalid, please try again: ' . $user->errors()->first());++ return false;+ }+ $user->save();++ return $user;++ }++ /**+ * @param $mail+ *+ * @return null|User+ */+ public function findByEmail($mail)+ {+ return \User::where('email', $mail)->first();+ }++ /**+ * @param $reset+ *+ * @return null|User+ */+ public function findByReset($reset)+ {+ return \User::where('reset', $reset)->first();+ }++}\ No newline at end of filediff --git a/app/lib/FireflyIII/FF3ServiceProvider.php b/app/lib/FireflyIII/FF3ServiceProvider.phpindex 2f8206f937..9aba717cfe 100644--- a/app/lib/FireflyIII/FF3ServiceProvider.php+++ b/app/lib/FireflyIII/FF3ServiceProvider.php@@ -1,6 +1,7 @@<?phpnamespace FireflyIII;+use FireflyIII\Shared\Validation\FireflyValidator;use Illuminate\Support\ServiceProvider;/**@@ -11,6 +12,14 @@ use Illuminate\Support\ServiceProvider;class FF3ServiceProvider extends ServiceProvider{+ public function boot()+ {+ $this->app->validator->resolver(+ function ($translator, $data, $rules, $messages) {+ return new FireflyValidator($translator, $data, $rules, $messages);+ }+ );+ }/*** Triggered automatically by Laravel@@ -23,6 +32,9 @@ class FF3ServiceProvider extends ServiceProvider// preferences:$this->app->bind('FireflyIII\Shared\Preferences\PreferencesInterface', 'FireflyIII\Shared\Preferences\Preferences');+ // registration and user mail:+ $this->app->bind('FireflyIII\Shared\Mail\RegistrationInterface', 'FireflyIII\Shared\Mail\Registration');+}}\ No newline at end of filediff --git a/app/lib/FireflyIII/Shared/Mail/Registration.php b/app/lib/FireflyIII/Shared/Mail/Registration.phpnew file mode 100644index 0000000000..922c67141e--- /dev/null+++ b/app/lib/FireflyIII/Shared/Mail/Registration.php@@ -0,0 +1,77 @@+<?php+namespace FireflyIII\Shared\Mail;++/**+ * Class Registration+ *+ * @package FireflyIII\Shared\Mail+ */+class Registration implements RegistrationInterface+{+ /**+ * @param \User $user+ *+ * @return mixed|void+ */+ public function sendVerificationMail(\User $user)+ {++ $reset = \Str::random(32);+ $user->reset = $reset;+ $user->forceSave();+ $email = $user->email;+ $data = ['reset' => $reset];++ \Mail::send(+ ['emails.user.verify-html', 'emails.user.verify-text'], $data, function ($message) use ($email) {+ $message->to($email, $email)->subject('Verify your e-mail address.');+ }+ );+ }++ /**+ * @param \User $user+ *+ * @return mixed|void+ */+ public function sendPasswordMail(\User $user)+ {++ $password = \Str::random(12);+ $user->password = $password;+ $user->reset = \Str::random(32); // new one.+ $user->forceSave();+ $email = $user->email;+++ $data = ['password' => $password];+ \Mail::send(+ ['emails.user.register-html', 'emails.user.register-text'], $data, function ($message) use ($email) {+ $message->to($email, $email)->subject('Welcome to Firefly!');+ }+ );+ }++ /**+ * @param \User $user+ *+ * @return mixed|void+ */+ public function sendResetVerification(\User $user)+ {+ $reset = \Str::random(32);+ $user->reset = $reset;+ $user->forceSave();+ $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/FireflyIII/Shared/Mail/RegistrationInterface.php b/app/lib/FireflyIII/Shared/Mail/RegistrationInterface.phpnew file mode 100644index 0000000000..0606956120--- /dev/null+++ b/app/lib/FireflyIII/Shared/Mail/RegistrationInterface.php@@ -0,0 +1,34 @@+<?php++namespace FireflyIII\Shared\Mail;++/**+ * Interface RegistrationInterface+ *+ * @package FireflyIII\Shared\Mail+ */+interface RegistrationInterface+{++ /**+ * @param \User $user+ *+ * @return mixed+ */+ public function sendVerificationMail(\User $user);++ /**+ * @param \User $user+ *+ * @return mixed+ */+ public function sendPasswordMail(\User $user);++ /**+ * @param \User $user+ *+ * @return mixed+ */+ public function sendResetVerification(\User $user);++}\ No newline at end of filediff --git a/app/lib/FireflyIII/Shared/Toolkit/Filter.php b/app/lib/FireflyIII/Shared/Toolkit/Filter.phpindex a927d64408..c0cc51834e 100644--- a/app/lib/FireflyIII/Shared/Toolkit/Filter.php+++ b/app/lib/FireflyIII/Shared/Toolkit/Filter.php@@ -29,8 +29,8 @@ class Filterif (!is_null(\Session::get('range'))) {$range = \Session::get('range');} else {- /** @noinspection PhpUndefinedClassInspection */- $preferences = \App::make('Firefly\Helper\Preferences\PreferencesHelperInterface');+ /** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */+ $preferences = \App::make('FireflyIII\Shared\Preferences\PreferencesInterface');$viewRange = $preferences->get('viewRange', '1M');// default range:diff --git a/app/lib/FireflyIII/Shared/Validation/FireflyValidator.php b/app/lib/FireflyIII/Shared/Validation/FireflyValidator.phpnew file mode 100644index 0000000000..1f26103651--- /dev/null+++ b/app/lib/FireflyIII/Shared/Validation/FireflyValidator.php@@ -0,0 +1,22 @@+<?php+namespace FireflyIII\Shared\Validation;++use Illuminate\Validation\Validator;++/**+ * Class FireflyValidator+ *+ * @package FireflyIII\Shared\Validation+ */+class FireflyValidator extends Validator+{+ public function validateAlphabasic($attribute, $value, $parameters)+ {+ $pattern = '/[^[:alnum:]_\-\.\& \(\)\'"]/iu';+ if (preg_match($pattern, $value)) {+ return false;+ } else {+ return true;+ }+ }+}\ No newline at end of filediff --git a/app/lib/FireflyIII/Shared/Validation/ValidationServiceProvider.php b/app/lib/FireflyIII/Shared/Validation/ValidationServiceProvider.phpnew file mode 100644index 0000000000..5ba7a32446--- /dev/null+++ b/app/lib/FireflyIII/Shared/Validation/ValidationServiceProvider.php@@ -0,0 +1,26 @@+<?php+++namespace FireflyIII\Shared\Validation;++use Illuminate\Support\ServiceProvider;++/**+ * Class ValidationServiceProvider+ * @package FireflyIII\Shared\Validation+ */+class ValidationServiceProvider extends ServiceProvider+{+ public function boot()+ {+ $this->app->validator->resolver(+ function ($translator, $data, $rules, $messages) {+ return new FireflyValidator($translator, $data, $rules, $messages);+ }+ );+ }++ public function register()+ {+ }+}\ No newline at end of filediff --git a/app/views/index.blade.php b/app/views/index.blade.phpindex 66857d7cfd..479e6ede81 100644--- a/app/views/index.blade.php+++ b/app/views/index.blade.php@@ -7,24 +7,13 @@<p class="lead">Welcome to Firefly III.</p><p>- To get get started, choose below:+ Create a new asset account to get started.</p></div></div><div class="row">- <div class="col-lg-6 col-md-6 col-sm-12">- <h2><a href="{{route('migrate.index')}}">Migrate from Firefly II</a></h2>-- <p>- Use this option if you have a JSON file from your current Firefly II installation.- </p>- </div><div class="col-lg-6 col-md-6 col-sm-12"><h2><a href="{{route('accounts.create','asset')}}">Start from scratch</a></h2>-- <p>- Use this option if you are new to Firefly (III).- </p></div>@else