Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insert privacy consent note only one #76

Merged
merged 1 commit into from
Apr 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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