diff --git a/app/Http/Controllers/ClientPortal/EntityViewController.php b/app/Http/Controllers/ClientPortal/EntityViewController.php new file mode 100644 index 000000000000..72fc44b6bb22 --- /dev/null +++ b/app/Http/Controllers/ClientPortal/EntityViewController.php @@ -0,0 +1,114 @@ +entity_types)) { + abort(404); + } + + $invitation_entity = sprintf('App\\Models\\%sInvitation', ucfirst($entity_type)); + + $key = $entity_type . '_id'; + + $invitation = $invitation_entity::whereRaw("BINARY `key`= ?", [$invitation_key])->firstOrFail(); + + $contact = $invitation->contact; + + if (is_null($contact->password) || empty($contact->password)) { + return redirect("/client/password/reset?email={$contact->email}"); + } + + $entity_class = sprintf('App\\Models\\%s', ucfirst($entity_type)); + $entity = $entity_class::findOrFail($invitation->{$key}); + + if ((bool) $invitation->contact->client->getSetting('enable_client_portal_password') !== false) { + session()->flash("{$entity_type}_VIEW_{$entity->hashed_id}", true); + } + + if (!session("{$entity_type}_VIEW_{$entity->hashed_id}")) { + return redirect()->route('client.entity_view.password', compact('entity_type', 'invitation_key')); + } + + return $this->render('view_entity.index', [ + 'root' => 'themes', + 'entity' => $entity, + ]); + } + + /** + * Show the form for entering password. + * + * @param string $entity_type + * @param string $invitation_key + * + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function password(string $entity_type, string $invitation_key) + { + return $this->render('view_entity.password', [ + 'root' => 'themes', + 'entity_type' => $entity_type, + ]); + } + + /**` + * Handle the password check. + * + * @param string $entity_type + * @param string $invitation_key + * + * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse|mixed + */ + public function handlePassword(string $entity_type, string $invitation_key) + { + if (!in_array($entity_type, $this->entity_types)) { + abort(404); + } + + $invitation_entity = sprintf('App\\Models\\%sInvitation', ucfirst($entity_type)); + + $key = $entity_type . '_id'; + + $invitation = $invitation_entity::whereRaw("BINARY `key`= ?", [$invitation_key])->firstOrFail(); + + $contact = $invitation->contact; + + $check = Hash::check(request()->password, $contact->password); + + $entity_class = sprintf('App\\Models\\%s', ucfirst($entity_type)); + + $entity = $entity_class::findOrFail($invitation->{$key}); + + if ($check) { + session()->flash("{$entity_type}_VIEW_{$entity->hashed_id}", true); + + return redirect()->route('client.entity_view', compact('entity_type', 'invitation_key')); + } + + session()->flash('PASSWORD_FAILED', true); + return back(); + } +} diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 497ac8f81cfc..7e3be03f6df3 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -3201,4 +3201,5 @@ return [ 'page' => 'Page', 'of' => 'Of', 'view_credit' => 'View Credit', + 'to_view_entity_password' => 'To view the :entity you need to enter password.', ]; diff --git a/resources/views/portal/ninja2020/auth/passwords/request.blade.php b/resources/views/portal/ninja2020/auth/passwords/request.blade.php index e7d9a1636605..9da2833852e0 100644 --- a/resources/views/portal/ninja2020/auth/passwords/request.blade.php +++ b/resources/views/portal/ninja2020/auth/passwords/request.blade.php @@ -24,7 +24,7 @@ @error('email')
{{ ctrans('texts.to_view_entity_password', ['entity' => $entity_type]) }}
+ +