From 5cb9907bf8cd113d1495d2853f3debd090c80825 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 11 Nov 2014 21:09:56 +0100 Subject: [PATCH] Various changes to support the removed old code. --- app/controllers/HomeController.php | 8 -- app/controllers/UserController.php | 53 ++++++++----- app/lib/FireflyIII/Database/User.php | 57 ++++++++++++++ app/lib/FireflyIII/FF3ServiceProvider.php | 12 +++ .../FireflyIII/Shared/Mail/Registration.php | 77 +++++++++++++++++++ .../Shared/Mail/RegistrationInterface.php | 34 ++++++++ app/lib/FireflyIII/Shared/Toolkit/Filter.php | 4 +- .../Shared/Validation/FireflyValidator.php | 22 ++++++ .../Validation/ValidationServiceProvider.php | 26 +++++++ app/views/index.blade.php | 13 +--- 10 files changed, 266 insertions(+), 40 deletions(-) create mode 100644 app/lib/FireflyIII/Database/User.php create mode 100644 app/lib/FireflyIII/Shared/Mail/Registration.php create mode 100644 app/lib/FireflyIII/Shared/Mail/RegistrationInterface.php create mode 100644 app/lib/FireflyIII/Shared/Validation/FireflyValidator.php create mode 100644 app/lib/FireflyIII/Shared/Validation/ValidationServiceProvider.php diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.php index 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.php index 834c2bb9cb..60300f52e7 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -1,8 +1,5 @@ user = $user; - $this->email = $email; - } /** @@ -84,14 +75,25 @@ class UserController extends BaseController if (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.php new file mode 100644 index 0000000000..591b204991 --- /dev/null +++ b/app/lib/FireflyIII/Database/User.php @@ -0,0 +1,57 @@ +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 file diff --git a/app/lib/FireflyIII/FF3ServiceProvider.php b/app/lib/FireflyIII/FF3ServiceProvider.php index 2f8206f937..9aba717cfe 100644 --- a/app/lib/FireflyIII/FF3ServiceProvider.php +++ b/app/lib/FireflyIII/FF3ServiceProvider.php @@ -1,6 +1,7 @@ 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 file diff --git a/app/lib/FireflyIII/Shared/Mail/Registration.php b/app/lib/FireflyIII/Shared/Mail/Registration.php new file mode 100644 index 0000000000..922c67141e --- /dev/null +++ b/app/lib/FireflyIII/Shared/Mail/Registration.php @@ -0,0 +1,77 @@ +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 file diff --git a/app/lib/FireflyIII/Shared/Mail/RegistrationInterface.php b/app/lib/FireflyIII/Shared/Mail/RegistrationInterface.php new file mode 100644 index 0000000000..0606956120 --- /dev/null +++ b/app/lib/FireflyIII/Shared/Mail/RegistrationInterface.php @@ -0,0 +1,34 @@ +get('viewRange', '1M'); // default range: diff --git a/app/lib/FireflyIII/Shared/Validation/FireflyValidator.php b/app/lib/FireflyIII/Shared/Validation/FireflyValidator.php new file mode 100644 index 0000000000..1f26103651 --- /dev/null +++ b/app/lib/FireflyIII/Shared/Validation/FireflyValidator.php @@ -0,0 +1,22 @@ +app->validator->resolver( + function ($translator, $data, $rules, $messages) { + return new FireflyValidator($translator, $data, $rules, $messages); + } + ); + } + + public function register() + { + } +} \ No newline at end of file diff --git a/app/views/index.blade.php b/app/views/index.blade.php index 66857d7cfd..479e6ede81 100644 --- a/app/views/index.blade.php +++ b/app/views/index.blade.php @@ -7,24 +7,13 @@

Welcome to Firefly III.

- To get get started, choose below: + Create a new asset account to get started.

-
-

Migrate from Firefly II

- -

- Use this option if you have a JSON file from your current Firefly II installation. -

-

Start from scratch

- -

- Use this option if you are new to Firefly (III). -

@else