1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

Generate temp email address for direct client portal viewing.

This commit is contained in:
David Bomba 2021-05-25 08:32:08 +10:00
parent 9d20ddca2a
commit 5e33eb9130
3 changed files with 30 additions and 15 deletions

View File

@ -309,10 +309,6 @@ class BaseController extends Controller
},
'company.tax_rates' => function ($query) use ($updated_at, $user) {
$query->where('updated_at', '>=', $updated_at);
if(!$user->isAdmin())
$query->where('tax_rates.user_id', $user->id);
},
'company.vendors'=> function ($query) use ($updated_at, $user) {
$query->where('updated_at', '>=', $updated_at)->with('contacts', 'documents');
@ -323,15 +319,9 @@ class BaseController extends Controller
},
'company.expense_categories'=> function ($query) use ($updated_at, $user) {
$query->where('updated_at', '>=', $updated_at);
if(!$user->isAdmin())
$query->where('expense_categories.user_id', $user->id);
},
'company.task_statuses'=> function ($query) use ($updated_at, $user) {
$query->where('updated_at', '>=', $updated_at);
},
'company.activities'=> function ($query) use($user) {

View File

@ -57,7 +57,7 @@ class InvitationController extends Controller
/* Return early if we have the correct client_hash embedded */
if (request()->has('client_hash') && request()->input('client_hash') == $invitation->contact->client->client_hash) {
auth()->guard('contact')->login($invitation->contact, true);
auth()->guard('contact')->loginUsingId($invitation->contact->id, true);
} elseif ((bool) $invitation->contact->client->getSetting('enable_client_portal_password') !== false) {
@ -66,7 +66,7 @@ class InvitationController extends Controller
return redirect()->route('client.login');
} else {
auth()->guard('contact')->login($invitation->contact, true);
auth()->guard('contact')->loginUsingId($invitation->contact->id, true);
}

View File

@ -18,6 +18,7 @@ use Auth;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
class ContactKeyLogin
{
@ -42,6 +43,9 @@ class ContactKeyLogin
if (MultiDB::findAndSetDbByContactKey($request->segment(3))) {
if($client_contact = ClientContact::where('contact_key', $request->segment(3))->first()){
if(empty($client_contact->email))
$client_contact->email = Str::random(6) . "@example.com"; $client_contact->save();
Auth::guard('contact')->login($client_contact, true);
return redirect()->to('client/dashboard');
}
@ -49,6 +53,10 @@ class ContactKeyLogin
}
} elseif ($request->segment(2) && $request->segment(2) == 'key_login' && $request->segment(3)) {
if ($client_contact = ClientContact::where('contact_key', $request->segment(3))->first()) {
if(empty($client_contact->email))
$client_contact->email = Str::random(6) . "@example.com"; $client_contact->save();
auth()->guard('contact')->login($client_contact, true);
return redirect()->to('client/dashboard');
}
@ -56,19 +64,36 @@ class ContactKeyLogin
if (MultiDB::findAndSetDbByClientHash($request->input('client_hash'))) {
if($client = Client::where('client_hash', $request->input('client_hash'))->first()){
auth()->guard('contact')->login($client->primary_contact()->first(), true);
$primary_contact = $client->primary_contact()->first();
if(empty($primary_contact->email))
$primary_contact->email = Str::random(6) . "@example.com"; $primary_contact->save();
auth()->guard('contact')->login($primary_contact, true);
return redirect()->to('client/dashboard');
}
}
} elseif ($request->has('client_hash')) {
if ($client = Client::where('client_hash', $request->input('client_hash'))->first()) {
Auth::guard('contact')->login($client->primary_contact()->first(), true);
$primary_contact = $client->primary_contact()->first();
if(empty($primary_contact->email))
$primary_contact->email = Str::random(6) . "@example.com"; $primary_contact->save();
auth()->guard('contact')->login($primary_contact, true);
return redirect()->to('client/dashboard');
}
} elseif ($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()){
Auth::guard('contact')->login($client_contact, true);
if(empty($client_contact->email))
$client_contact->email = Str::random(6) . "@example.com"; $client_contact->save();
auth()->guard('contact')->login($client_contact, true);
if ($request->query('redirect') && !empty($request->query('redirect'))) {
return redirect()->to($request->query('redirect'));