Skip to content

Commit

Permalink
insert privacy consent note only one (#76)
Browse files Browse the repository at this point in the history
redo
  • Loading branch information
alikon authored and brianteeman committed Apr 17, 2018
1 parent 201fa6a commit c2190d6
Showing 1 changed file with 44 additions and 39 deletions.
83 changes: 44 additions & 39 deletions plugins/user/privacyconsent/privacyconsent.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,48 +202,53 @@ public function onUserAfterSave($data, $isNew, $result, $error)
return;
}

// Get the user's ID
$userId = ArrayHelper::getValue($data, 'id', 0, 'int');

// Get the user's IP address
$ip = $this->app->input->server->get('REMOTE_ADDR', '', 'string');

// Get the user agent string
$userAgent = $this->app->input->server->get('HTTP_USER_AGENT', '', 'string');

// Create the user note
$userNote = (object) array(
'user_id' => $userId,
'catid' => 0,
'subject' => Text::_('PLG_USER_PRIVACYCONSENT_SUBJECT'),
'body' => Text::sprintf('PLG_USER_PRIVACYCONSENT_BODY', $ip, $userAgent),
'state' => 1,
'created_time' => Factory::getDate()->toSql(),
);
$form = $this->app->input->post->get('jform', array(), 'array');

if (isset($form['privacyconsent']['privacy']) && ($form['privacyconsent']['privacy']))
{
// Get the user's ID
$userId = ArrayHelper::getValue($data, 'id', 0, 'int');

// Get the user's IP address
$ip = $this->app->input->server->get('REMOTE_ADDR', '', 'string');

// Get the user agent string
$userAgent = $this->app->input->server->get('HTTP_USER_AGENT', '', 'string');

// Create the user note
$userNote = (object) array(
'user_id' => $userId,
'catid' => 0,
'subject' => Text::_('PLG_USER_PRIVACYCONSENT_SUBJECT'),
'body' => Text::sprintf('PLG_USER_PRIVACYCONSENT_BODY', $ip, $userAgent),
'state' => 1,
'created_time' => Factory::getDate()->toSql(),
);

try
{
$this->db->insertObject('#__user_notes', $userNote);
}
catch (Exception $e)
{
// Do nothing if the save fails
}
try
{
$this->db->insertObject('#__user_notes', $userNote);
}
catch (Exception $e)
{
// Do nothing if the save fails
}

// Create the consent confirmation
$confirm = (object) array(
'user_id' => $userId,
'profile_key' => 'consent',
'profile_value' => 1
);
// Create the consent confirmation
$confirm = (object) array(
'user_id' => $userId,
'profile_key' => 'consent',
'profile_value' => 1
);

try
{
$this->db->insertObject('#__user_profiles', $confirm);
}
catch (Exception $e)
{
// Do nothing if the save fails
try
{
$this->db->insertObject('#__user_profiles', $confirm);
}
catch (Exception $e)
{
// Do nothing if the save fails
}
}

return true;
Expand Down

0 comments on commit c2190d6

Please sign in to comment.