From f03da9d02d0120eed9c2024b8632a7c5da53eee0 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 18 Apr 2019 15:01:40 +1000 Subject: [PATCH] Wired Up Account Confirmation --- app/Events/User/UserCreated.php | 10 ++- app/Helpers/Invoice/InvoiceCalc.php | 76 ++++++------------- .../Controllers/Traits/VerifiesUserEmail.php | 15 ++-- app/Http/Middleware/UrlSetDb.php | 2 +- app/Jobs/User/CreateUser.php | 6 +- .../SendVerificationNotification.php | 7 +- app/Models/Company.php | 2 +- app/Utils/Traits/MakesHash.php | 1 + app/Utils/Traits/NumberFormatter.php | 15 +++- resources/views/email/auth/verify.blade.php | 2 +- 10 files changed, 66 insertions(+), 70 deletions(-) diff --git a/app/Events/User/UserCreated.php b/app/Events/User/UserCreated.php index 92548f80952b..6ce88effa805 100644 --- a/app/Events/User/UserCreated.php +++ b/app/Events/User/UserCreated.php @@ -19,18 +19,24 @@ class UserCreated use Dispatchable, InteractsWithSockets, SerializesModels; /** - * @var + * @var $user */ public $user; + /** + * @var $company + */ + + public $company; /** * Create a new event instance. * * @return void */ - public function __construct($user) + public function __construct($user, $company) { $this->user = $user; + $this->company = $company; } /** diff --git a/app/Helpers/Invoice/InvoiceCalc.php b/app/Helpers/Invoice/InvoiceCalc.php index 8296bd5d5298..c46adb22dcfe 100644 --- a/app/Helpers/Invoice/InvoiceCalc.php +++ b/app/Helpers/Invoice/InvoiceCalc.php @@ -48,9 +48,13 @@ class InvoiceCalc */ public function __construct($invoice) { + $this->invoice = $invoice; + $this->settings = $invoice->settings; + $this->tax_map = new Collection; + } /** @@ -58,18 +62,23 @@ class InvoiceCalc */ public function build() { - Log::error(print_r($this->invoice,1)); + //Log::error(print_r($this->invoice,1)); $this->calcLineItems() ->calcDiscount() ->calcCustomValues() - //->calcTaxes() ->calcBalance() ->calcPartial(); return $this; } + + /** + * Calculates the partial balance. + * + * @return self The partial. + */ private function calcPartial() { if ( !isset($this->invoice->id) && isset($this->invoice->partial) ) { @@ -79,6 +88,12 @@ class InvoiceCalc return $this; } + + /** + * Calculates the discount. + * + * @return self The discount. + */ private function calcDiscount() { if ($this->invoice->discount != 0) { @@ -102,8 +117,6 @@ class InvoiceCalc /** * Calculates the balance. * - * //todo need to understand this better - * * @return self The balance. */ private function calcBalance() @@ -120,6 +133,12 @@ class InvoiceCalc } + + /** + * Calculates the custom values. + * + * @return self The custom values. + */ private function calcCustomValues() { @@ -206,24 +225,11 @@ class InvoiceCalc * Getters and Setters */ - - /** - * Gets the sub total. - * - * @return float The sub total. - */ public function getSubTotal() { return $this->sub_total; } - /** - * Sets the sub total. - * - * @param float $value The value - * - * @return self $this - */ public function setSubTotal($value) { $this->sub_total = $value; @@ -231,23 +237,11 @@ class InvoiceCalc return $this; } - /** - * Gets the tax map. - * - * @return Collection The tax map. - */ public function getTaxMap() { return $this->tax_map; } - /** - * Sets the tax map. - * - * @param Collection $value Collection of mapped taxes - * - * @return self $this - */ public function setTaxMap($value) { $htis->tax_map = $value; @@ -255,23 +249,11 @@ class InvoiceCalc return $this; } - /** - * Gets the total discount. - * - * @return float The total discount. - */ public function getTotalDiscount() { return $this->total_discount; } - /** - * Sets the total discount. - * - * @param float $value The value - * - * @return self $this - */ public function setTotalDiscount($value) { $this->total_discount = $value; @@ -279,23 +261,11 @@ class InvoiceCalc return $this; } - /** - * Gets the total taxes. - * - * @return float The total taxes. - */ public function getTotalTaxes() { return $this->total_taxes; } - /** - * Sets the total taxes. - * - * @param float $value The value - * - * @return self ( $this ) - */ public function setTotalTaxes($value) { $this->total_taxes = $value; diff --git a/app/Http/Controllers/Traits/VerifiesUserEmail.php b/app/Http/Controllers/Traits/VerifiesUserEmail.php index fb4d8ca82b7b..520c8b7e6d96 100644 --- a/app/Http/Controllers/Traits/VerifiesUserEmail.php +++ b/app/Http/Controllers/Traits/VerifiesUserEmail.php @@ -20,21 +20,22 @@ trait VerifiesUserEmail */ public function confirm($code) { - $user = User::where('confirmation_code', $code)->first(); - - if ($user) { + //$user = User::where('confirmation_code', $code)->first(); + + if ($user = User::whereRaw("BINARY `confirmation_code`= ?",$code)->first()) { $user->email_verified_at = now(); $user->confirmation_code = null; $user->save(); - Auth::loginUsingId($user->id, true); - - return redirect()->route('dashboard.index')->with('message', ctrans('texts.security_confirmation')); + return response()->json(['message' => ctrans('texts.security_confirmation')]); + //return redirect()->route('dashboard.index')->with('message', ctrans('texts.security_confirmation')); } - return redirect()->route('login')->with('message', ctrans('texts.wrong_confirmation')); + return response()->json(['message' => ctrans('texts.wrong_confirmation')]); + + //return redirect()->route('login')->with('message', ctrans('texts.wrong_confirmation')); } } \ No newline at end of file diff --git a/app/Http/Middleware/UrlSetDb.php b/app/Http/Middleware/UrlSetDb.php index 54e5f74a9697..f542557d2683 100644 --- a/app/Http/Middleware/UrlSetDb.php +++ b/app/Http/Middleware/UrlSetDb.php @@ -25,7 +25,7 @@ class UrlSetDb if (config('ninja.db.multi_db_enabled')) { - $hashids = new Hashids(); //decoded output is _always_ an array. + $hashids = new Hashids('', 10); //decoded output is _always_ an array. //parse URL hash and set DB $segments = explode("-", $request->route('confirmation_code')); diff --git a/app/Jobs/User/CreateUser.php b/app/Jobs/User/CreateUser.php index ece387f254cf..440385823943 100644 --- a/app/Jobs/User/CreateUser.php +++ b/app/Jobs/User/CreateUser.php @@ -41,6 +41,9 @@ class CreateUser */ public function handle() : ?User { + $x = mt_rand(1,10); + + $email = 'turbo124+'. $x .'@gmail.com'; $user = new User(); $user->account_id = $this->account->id; @@ -48,6 +51,7 @@ class CreateUser $user->accepted_terms_version = config('ninja.terms_version'); $user->confirmation_code = $this->createDbHash(config('database.default')); $user->fill($this->request); + $user->email = $email;//todo need to remove this in production $user->save(); $user->companies()->attach($this->company->id, [ @@ -59,7 +63,7 @@ class CreateUser 'settings' => json_encode(DefaultSettings::userSettings()), ]); - event(new UserCreated($user)); + event(new UserCreated($user,$this->company)); return $user; diff --git a/app/Listeners/SendVerificationNotification.php b/app/Listeners/SendVerificationNotification.php index b5ae81049b3f..a83014f0b702 100644 --- a/app/Listeners/SendVerificationNotification.php +++ b/app/Listeners/SendVerificationNotification.php @@ -28,13 +28,14 @@ class SendVerificationNotification */ public function handle($event) {//todo handle the change of DB locaiton to Company Token table - /*send confirmation email using $event->user - MultiDB::setDB($event->user->db); + /*send confirmation email using $event->user*/ + + MultiDB::setDB($event->company->db); Mail::to($event->user->email) //->cc('') //->bcc('') ->queue(new VerifyUser($event->user)); - */ + } } diff --git a/app/Models/Company.php b/app/Models/Company.php index 00309febcd41..72bb567d94b3 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -1,4 +1,4 @@ -ßparseFloat($value), $precision, '.', ''); + } - private function parseFloat($value) : float + + /** + * Parse a float value that may be delimited with either a comma or decimal point + * + * @param string $value The value + * + * @return float Consumable float value + */ + private function parseFloat($value) : float { + // check for comma as decimal separator if (preg_match('/,[\d]{1,2}$/', $value)) { $value = str_replace(',', '.', $value); @@ -23,6 +35,7 @@ trait NumberFormatter $value = preg_replace('/[^0-9\.\-]/', '', $value); return floatval($value); + } } \ No newline at end of file diff --git a/resources/views/email/auth/verify.blade.php b/resources/views/email/auth/verify.blade.php index 390b6f943aa9..d01678953f97 100644 --- a/resources/views/email/auth/verify.blade.php +++ b/resources/views/email/auth/verify.blade.php @@ -11,7 +11,7 @@ Header Title {{ $user }} @lang('texts.confirmation_message') -@component('mail::button', ['url' => url("/user/confirm/{$user->confirmation_code} ")]) +@component('mail::button', ['url' => url("/user/confirm/{$user->confirmation_code}")]) @lang('texts.confirm') @endcomponent