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

Merge pull request #5906 from turbo124/v5-develop

Fixes for magic links
This commit is contained in:
David Bomba 2021-06-03 09:50:44 +10:00 committed by GitHub
commit 98cab9db8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 10 deletions

View File

@ -14,11 +14,12 @@ namespace App\Http\Livewire;
use App\Factory\ClientFactory;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Libraries\MultiDB;
use App\Mail\ContactPasswordlessLogin;
use App\Models\Client;
use App\Models\Subscription;
use App\Models\ClientContact;
use App\Models\Invoice;
use App\Models\Subscription;
use App\Repositories\ClientContactRepository;
use App\Repositories\ClientRepository;
use Illuminate\Support\Facades\App;
@ -162,6 +163,13 @@ class BillingPortalPurchase extends Component
*/
public $passwordless_login_btn = false;
/**
* Instance of company.
*
* @var Company
*/
public $company
/**
* Campaign reference.
*
@ -171,6 +179,8 @@ class BillingPortalPurchase extends Component
public function mount()
{
MultiDB::setDb($this->company->db);
$this->price = $this->subscription->price;
if (request()->query('coupon')) {
@ -444,7 +454,7 @@ class BillingPortalPurchase extends Component
->first();
$mailer = new NinjaMailerObject();
$mailer->mailable = new ContactPasswordlessLogin($this->email, (string)route('client.subscription.purchase', $this->subscription->hashed_id) . '?coupon=' . $this->coupon);
$mailer->mailable = new ContactPasswordlessLogin($this->email, $this->subscription->company->id, (string)route('client.subscription.purchase', $this->subscription->hashed_id) . '?coupon=' . $this->coupon);
$mailer->company = $this->subscription->company;
$mailer->settings = $this->subscription->company->settings;
$mailer->to_user = $contact;

View File

@ -40,8 +40,10 @@ class ContactKeyLogin
}
if ($request->segment(2) && $request->segment(2) == 'magic_link' && $request->segment(3)) {
$contact_email = Cache::get($request->segment(3));
if($client_contact = ClientContact::where('email', $contact_email)->first()){
$payload = Cache::get($request->segment(3));
$contact_email = $payload['email'];
if($client_contact = ClientContact::where('email', $contact_email)->where('company_id', $payload['company_id'])->first()){
if(empty($client_contact->email))
$client_contact->email = Str::random(6) . "@example.com"; $client_contact->save();

View File

@ -12,6 +12,7 @@
namespace App\Mail;
use App\Models\Company;
use App\Utils\ClientPortal\MagicLink;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
@ -20,7 +21,6 @@ use Illuminate\Queue\SerializesModels;
class ContactPasswordlessLogin extends Mailable
{
use Queueable, SerializesModels;
/**
* @var string
@ -28,17 +28,18 @@ class ContactPasswordlessLogin extends Mailable
public $email;
public $url;
/**
* Create a new message instance.
*
* @param string $email
* @param string $redirect
*/
public function __construct(string $email, string $redirect = '')
public function __construct(string $email, $company_id, string $redirect = '')
{
$this->email = $email;
$this->url = MagicLink::create($email, $redirect);
$this->url = MagicLink::create($email, $company_id, $redirect);
}
/**

View File

@ -18,12 +18,17 @@ class MagicLink
{
//return a magic login link URL
public static function create($email, $url = null) :string
public static function create($email, $company_id, $url = null) :string
{
$magic_key = Str::random(64);
$timeout = 600; //seconds
Cache::add($magic_key, $email, $timeout);
$payload = [
'email' => $email,
'company_id' => $company_id,
];
Cache::add($magic_key, $payload, $timeout);
return route('client.contact_magic_link', ['magic_link' => $magic_key, 'redirect' => $url]);
}

View File

@ -2,7 +2,7 @@
@section('meta_title', ctrans('texts.purchase'))
@section('body')
@livewire('billing-portal-purchase', ['subscription' => $subscription, 'contact' => auth('contact')->user(), 'hash' => $hash, 'request_data' => $request_data, 'campaign' => request()->query('campaign') ?? null])
@livewire('billing-portal-purchase', ['subscription' => $subscription, 'company' => $subscription->company, 'contact' => auth('contact')->user(), 'hash' => $hash, 'request_data' => $request_data, 'campaign' => request()->query('campaign') ?? null])
@stop
@push('footer')