Wired Up Account Confirmation

This commit is contained in:
David Bomba 2019-04-18 15:01:40 +10:00
parent d5e2787272
commit f03da9d02d
10 changed files with 66 additions and 70 deletions

View File

@ -19,18 +19,24 @@ class UserCreated
use Dispatchable, InteractsWithSockets, SerializesModels; use Dispatchable, InteractsWithSockets, SerializesModels;
/** /**
* @var * @var $user
*/ */
public $user; public $user;
/**
* @var $company
*/
public $company;
/** /**
* Create a new event instance. * Create a new event instance.
* *
* @return void * @return void
*/ */
public function __construct($user) public function __construct($user, $company)
{ {
$this->user = $user; $this->user = $user;
$this->company = $company;
} }
/** /**

View File

@ -48,9 +48,13 @@ class InvoiceCalc
*/ */
public function __construct($invoice) public function __construct($invoice)
{ {
$this->invoice = $invoice; $this->invoice = $invoice;
$this->settings = $invoice->settings; $this->settings = $invoice->settings;
$this->tax_map = new Collection; $this->tax_map = new Collection;
} }
/** /**
@ -58,18 +62,23 @@ class InvoiceCalc
*/ */
public function build() public function build()
{ {
Log::error(print_r($this->invoice,1)); //Log::error(print_r($this->invoice,1));
$this->calcLineItems() $this->calcLineItems()
->calcDiscount() ->calcDiscount()
->calcCustomValues() ->calcCustomValues()
//->calcTaxes()
->calcBalance() ->calcBalance()
->calcPartial(); ->calcPartial();
return $this; return $this;
} }
/**
* Calculates the partial balance.
*
* @return self The partial.
*/
private function calcPartial() private function calcPartial()
{ {
if ( !isset($this->invoice->id) && isset($this->invoice->partial) ) { if ( !isset($this->invoice->id) && isset($this->invoice->partial) ) {
@ -79,6 +88,12 @@ class InvoiceCalc
return $this; return $this;
} }
/**
* Calculates the discount.
*
* @return self The discount.
*/
private function calcDiscount() private function calcDiscount()
{ {
if ($this->invoice->discount != 0) { if ($this->invoice->discount != 0) {
@ -102,8 +117,6 @@ class InvoiceCalc
/** /**
* Calculates the balance. * Calculates the balance.
* *
* //todo need to understand this better
*
* @return self The balance. * @return self The balance.
*/ */
private function calcBalance() private function calcBalance()
@ -120,6 +133,12 @@ class InvoiceCalc
} }
/**
* Calculates the custom values.
*
* @return self The custom values.
*/
private function calcCustomValues() private function calcCustomValues()
{ {
@ -206,24 +225,11 @@ class InvoiceCalc
* Getters and Setters * Getters and Setters
*/ */
/**
* Gets the sub total.
*
* @return float The sub total.
*/
public function getSubTotal() public function getSubTotal()
{ {
return $this->sub_total; return $this->sub_total;
} }
/**
* Sets the sub total.
*
* @param float $value The value
*
* @return self $this
*/
public function setSubTotal($value) public function setSubTotal($value)
{ {
$this->sub_total = $value; $this->sub_total = $value;
@ -231,23 +237,11 @@ class InvoiceCalc
return $this; return $this;
} }
/**
* Gets the tax map.
*
* @return Collection The tax map.
*/
public function getTaxMap() public function getTaxMap()
{ {
return $this->tax_map; return $this->tax_map;
} }
/**
* Sets the tax map.
*
* @param Collection $value Collection of mapped taxes
*
* @return self $this
*/
public function setTaxMap($value) public function setTaxMap($value)
{ {
$htis->tax_map = $value; $htis->tax_map = $value;
@ -255,23 +249,11 @@ class InvoiceCalc
return $this; return $this;
} }
/**
* Gets the total discount.
*
* @return float The total discount.
*/
public function getTotalDiscount() public function getTotalDiscount()
{ {
return $this->total_discount; return $this->total_discount;
} }
/**
* Sets the total discount.
*
* @param float $value The value
*
* @return self $this
*/
public function setTotalDiscount($value) public function setTotalDiscount($value)
{ {
$this->total_discount = $value; $this->total_discount = $value;
@ -279,23 +261,11 @@ class InvoiceCalc
return $this; return $this;
} }
/**
* Gets the total taxes.
*
* @return float The total taxes.
*/
public function getTotalTaxes() public function getTotalTaxes()
{ {
return $this->total_taxes; return $this->total_taxes;
} }
/**
* Sets the total taxes.
*
* @param float $value The value
*
* @return self ( $this )
*/
public function setTotalTaxes($value) public function setTotalTaxes($value)
{ {
$this->total_taxes = $value; $this->total_taxes = $value;

View File

@ -20,21 +20,22 @@ trait VerifiesUserEmail
*/ */
public function confirm($code) public function confirm($code)
{ {
$user = User::where('confirmation_code', $code)->first(); //$user = User::where('confirmation_code', $code)->first();
if ($user) { if ($user = User::whereRaw("BINARY `confirmation_code`= ?",$code)->first()) {
$user->email_verified_at = now(); $user->email_verified_at = now();
$user->confirmation_code = null; $user->confirmation_code = null;
$user->save(); $user->save();
Auth::loginUsingId($user->id, true); return response()->json(['message' => ctrans('texts.security_confirmation')]);
//return redirect()->route('dashboard.index')->with('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'));
} }
} }

View File

@ -25,7 +25,7 @@ class UrlSetDb
if (config('ninja.db.multi_db_enabled')) 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 //parse URL hash and set DB
$segments = explode("-", $request->route('confirmation_code')); $segments = explode("-", $request->route('confirmation_code'));

View File

@ -41,6 +41,9 @@ class CreateUser
*/ */
public function handle() : ?User public function handle() : ?User
{ {
$x = mt_rand(1,10);
$email = 'turbo124+'. $x .'@gmail.com';
$user = new User(); $user = new User();
$user->account_id = $this->account->id; $user->account_id = $this->account->id;
@ -48,6 +51,7 @@ class CreateUser
$user->accepted_terms_version = config('ninja.terms_version'); $user->accepted_terms_version = config('ninja.terms_version');
$user->confirmation_code = $this->createDbHash(config('database.default')); $user->confirmation_code = $this->createDbHash(config('database.default'));
$user->fill($this->request); $user->fill($this->request);
$user->email = $email;//todo need to remove this in production
$user->save(); $user->save();
$user->companies()->attach($this->company->id, [ $user->companies()->attach($this->company->id, [
@ -59,7 +63,7 @@ class CreateUser
'settings' => json_encode(DefaultSettings::userSettings()), 'settings' => json_encode(DefaultSettings::userSettings()),
]); ]);
event(new UserCreated($user)); event(new UserCreated($user,$this->company));
return $user; return $user;

View File

@ -28,13 +28,14 @@ class SendVerificationNotification
*/ */
public function handle($event) public function handle($event)
{//todo handle the change of DB locaiton to Company Token table {//todo handle the change of DB locaiton to Company Token table
/*send confirmation email using $event->user /*send confirmation email using $event->user*/
MultiDB::setDB($event->user->db);
MultiDB::setDB($event->company->db);
Mail::to($event->user->email) Mail::to($event->user->email)
//->cc('') //->cc('')
//->bcc('') //->bcc('')
->queue(new VerifyUser($event->user)); ->queue(new VerifyUser($event->user));
*/
} }
} }

View File

@ -1,4 +1,4 @@
ß<?php <?php
namespace App\Models; namespace App\Models;

View File

@ -22,6 +22,7 @@ trait MakesHash
/** /**
* Creates a simple alphanumeric Hash which is prepended with a encoded database prefix * Creates a simple alphanumeric Hash which is prepended with a encoded database prefix
*
* @param $db - Full database name * @param $db - Full database name
* @return string 01-asfas8df76a78f6a78dfsdf * @return string 01-asfas8df76a78f6a78dfsdf
*/ */

View File

@ -8,13 +8,25 @@ namespace App\Utils\Traits;
*/ */
trait NumberFormatter trait NumberFormatter
{ {
private function formatValue($value, $precision) : string private function formatValue($value, $precision) : string
{ {
return number_format($this->parseFloat($value), $precision, '.', ''); return number_format($this->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 // check for comma as decimal separator
if (preg_match('/,[\d]{1,2}$/', $value)) { if (preg_match('/,[\d]{1,2}$/', $value)) {
$value = str_replace(',', '.', $value); $value = str_replace(',', '.', $value);
@ -23,6 +35,7 @@ trait NumberFormatter
$value = preg_replace('/[^0-9\.\-]/', '', $value); $value = preg_replace('/[^0-9\.\-]/', '', $value);
return floatval($value); return floatval($value);
} }
} }

View File

@ -11,7 +11,7 @@ Header Title
{{ $user }} {{ $user }}
@lang('texts.confirmation_message') @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') @lang('texts.confirm')
@endcomponent @endcomponent