1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

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;
/**
* @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;
}
/**

View File

@ -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;

View File

@ -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'));
}
}

View File

@ -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'));

View File

@ -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;

View File

@ -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));
*/
}
}

View File

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

View File

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

View File

@ -8,13 +8,25 @@ namespace App\Utils\Traits;
*/
trait NumberFormatter
{
private function formatValue($value, $precision) : string
{
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
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);
}
}

View File

@ -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