Skip to content

Commit

Permalink
refactor to avoid superglobal
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed Feb 21, 2024
1 parent c5195a3 commit 1154fec
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions lib/midcom/services/auth/frontend/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class midcom_services_auth_frontend_form implements midcom_services_auth_fronten
*/
private bool $auth_credentials_found = false;

private array $form_data = [];

public function has_login_data() : bool
{
return $this->auth_credentials_found;
Expand All @@ -37,6 +39,13 @@ public function has_login_data() : bool
*/
public function read_login_data(Request $request) : ?array
{
// Store the submitted form if the session expired, but user wants to save the data
foreach ($request->request->all() as $key => $value) {
if (!preg_match('/(username|password|frontend_form_submit)/', $key)) {
$this->form_data[$key] = base64_encode(json_encode($value));
}
}

if ( !$request->request->has('midcom_services_auth_frontend_form_submit')
|| !$request->request->has('username')
|| !$request->request->has('password')) {
Expand Down Expand Up @@ -71,19 +80,7 @@ public function read_login_data(Request $request) : ?array
*/
public function show_login_form()
{
// Store the submitted form if the session expired, but user wants to save the data
if (!empty($_POST)) {
$restored_form_data = [];

foreach ($_POST as $key => $value) {
if (preg_match('/(username|password|frontend_form_submit)/', $key)) {
continue;
}

$restored_form_data[$key] = base64_encode(json_encode($value));
}
midcom::get()->style->data['restored_form_data'] = $restored_form_data;
}
midcom::get()->style->data['restored_form_data'] = $this->form_data;

echo "<div id='midcom_login_form'>\n";
midcom::get()->style->show_midcom('midcom_services_auth_frontend_form');
Expand Down

0 comments on commit 1154fec

Please sign in to comment.