Skip to content

Commit

Permalink
Merge pull request elkarte#3191 from emanuele45/user_agreement
Browse files Browse the repository at this point in the history
User agreement and privacy policy
  • Loading branch information
Spuds committed May 30, 2018
2 parents 798bb63 + 71b6bb4 commit ee87392
Show file tree
Hide file tree
Showing 24 changed files with 808 additions and 47 deletions.
34 changes: 34 additions & 0 deletions install/Install_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ private function action_checkFilesWritable()
'smileys',
'themes',
'agreement.txt',
'privacypolicy.txt',
'db_last_error.txt',
'Settings.php',
'Settings_bak.php'
Expand Down Expand Up @@ -816,6 +817,39 @@ private function action_databasePopulation()
array('variable')
);

// Better safe, than sorry, just in case the autoloader doesn't cope well with the upgrade
require_once(TMP_BOARDDIR . '/sources/subs/Agreement.class.php');
require_once(TMP_BOARDDIR . '/sources/subs/PrivacyPolicy.class.php');

$agreement = new \Agreement('english');
$success = $agreement->storeBackup();
$db->insert('replace',
$db_prefix . 'settings',
array(
'variable' => 'string-255', 'value' => 'string-65534',
),
array(
'agreementRevision', $success,
),
array('variable')
);

if (file_exists(TMP_BOARDDIR . '/privacypolicy.txt'))
{
$privacypol = new \PrivacyPolicy('english');
$success = $privacypol->storeBackup();
$db->insert('replace',
$db_prefix . 'settings',
array(
'variable' => 'string-255', 'value' => 'string-65534',
),
array(
'privacypolicyRevision', $success,
),
array('variable')
);
}

// Maybe we can auto-detect better cookie settings?
preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
if (!empty($matches))
Expand Down
34 changes: 34 additions & 0 deletions install/install_1-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,23 @@ public function table_log_activity()
);
}

public function table_log_agreement_accept()
{
return $this->table->db_create_table('{db_prefix}log_agreement_accept',
array(
array('name' => 'version', 'type' => 'varchar', 'size' => 20, 'default' => ''),
array('name' => 'id_member', 'type' => 'mediumint', 'size' => 10, 'unsigned' => true, 'default' => 0),
array('name' => 'accepted_date', 'type' => 'date', 'default' => '0001-01-01'),
array('name' => 'accepted_ip', 'type' => 'varchar', 'size' => 255, 'default' => ''),
),
array(
array('name' => 'version', 'columns' => array('version', 'id_member'), 'type' => 'primary'),
),
array(),
'ignore'
);
}

public function table_log_badbehavior()
{
return $this->table->db_create_table('{db_prefix}log_badbehavior',
Expand Down Expand Up @@ -2404,6 +2421,23 @@ public function table_postby_emails_filters()
);
}

public function table_log_privacy_policy_accept()
{
return $this->table->db_create_table('{db_prefix}log_privacy_policy_accept',
array(
array('name' => 'version', 'type' => 'varchar', 'size' => 20, 'default' => ''),
array('name' => 'id_member', 'type' => 'mediumint', 'size' => 10, 'unsigned' => true, 'default' => 0),
array('name' => 'accepted_date', 'type' => 'date', 'default' => '0001-01-01'),
array('name' => 'accepted_ip', 'type' => 'varchar', 'size' => 255, 'default' => ''),
),
array(
array('name' => 'version', 'columns' => array('version', 'id_member'), 'type' => 'primary'),
),
array(),
'ignore'
);
}

public function table_scheduled_tasks()
{
return $this->table->db_create_table('{db_prefix}scheduled_tasks',
Expand Down
63 changes: 63 additions & 0 deletions install/upgrade_1-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,4 +865,67 @@ public function update_settings()
)
);
}

public function agreement_logging_title()
{
return 'Introducing the logging of accepted agreement and privacy policy...';
}

public function agreement_logging()
{
return array(
array(
'debug_title' => 'Creating the tables...',
'function' => function()
{
$this->table->db_create_table('{db_prefix}log_agreement_accept',
array(
array('name' => 'version', 'type' => 'varchar', 'size' => 20, 'default' => ''),
array('name' => 'id_member', 'type' => 'mediumint', 'size' => 10, 'unsigned' => true, 'default' => 0),
array('name' => 'accepted_date', 'type' => 'date', 'default' => '0001-01-01'),
array('name' => 'accepted_ip', 'type' => 'varchar', 'size' => 255, 'default' => ''),
),
array(
array('name' => 'version', 'columns' => array('version', 'id_member'), 'type' => 'primary'),
),
array(),
'ignore'
);
$this->table->db_create_table('{db_prefix}log_privacy_policy_accept',
array(
array('name' => 'version', 'type' => 'varchar', 'size' => 20, 'default' => ''),
array('name' => 'id_member', 'type' => 'mediumint', 'size' => 10, 'unsigned' => true, 'default' => 0),
array('name' => 'accepted_date', 'type' => 'date', 'default' => '0001-01-01'),
array('name' => 'accepted_ip', 'type' => 'varchar', 'size' => 255, 'default' => ''),
),
array(
array('name' => 'version', 'columns' => array('version', 'id_member'), 'type' => 'primary'),
),
array(),
'ignore'
);
}
),
array(
'debug_title' => 'Preparing first status...',
'function' => function()
{
// Better safe, than sorry, just in case the autoloader doesn't cope well with the upgrade
require_once(SUBSDIR . '/Agreement.class.php');
require_once(SUBSDIR . '/PrivacyPolicy.class.php');

$agreement = new \Agreement('english');
$success = $agreement->storeBackup();
updateSettings(array('agreementRevision' => $success));

if (file_exists(BOARDDIR . '/privacypolicy.txt'))
{
$privacypol = new \PrivacyPolicy('english');
$success = $privacypol->storeBackup();
updateSettings(array('privacypolicyRevision' => $success));
}
}
)
);
}
}
Empty file added privacypolicy.txt
Empty file.
54 changes: 54 additions & 0 deletions sources/Load.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,40 @@ function loadUserSettings()
else
$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';

if ($user_info['is_guest'] === false)
{
$http_request = HttpReq::instance();
if (!empty($modSettings['force_accept_agreement']))
{
if (!empty($modSettings['agreementRevision']) && !empty($modSettings['requireAgreement']) && in_array($http_request->action, array('reminder', 'register')) === false)
{
if ($http_request->action !== 'profile' || $http_request->area !== 'deleteaccount')
{
$agreement = new \Agreement($user_info['language']);
if (false === $agreement->checkAccepted($id_member, $modSettings['agreementRevision']))
{
setOldUrl('agreement_url_redirect');
redirectexit('action=register;sa=agreement', true);
}
}
}
}
if (!empty($modSettings['force_accept_privacy_policy']))
{
if (!empty($modSettings['privacypolicyRevision']) && !empty($modSettings['requirePrivacypolicy']) && in_array($http_request->action, array('reminder', 'register')) === false)
{
if ($http_request->action !== 'profile' || $http_request->area !== 'deleteaccount')
{
$privacypol = new \PrivacyPolicy($user_info['language']);
if (false === $privacypol->checkAccepted($id_member, $modSettings['privacypolicyRevision']))
{
setOldUrl('agreement_url_redirect');
redirectexit('action=register;sa=privacypol', true);
}
}
}
}
}
call_integration_hook('integrate_user_info');
}

Expand Down Expand Up @@ -1620,6 +1654,26 @@ function loadTheme($id_theme = 0, $initialize = true)
'atom' => $scripturl . '?action=.xml;type=atom;limit=' . (!empty($modSettings['xmlnews_limit']) ? $modSettings['xmlnews_limit'] : 5)
);

if (!empty($_SESSION['agreement_accepted']))
{
$_SESSION['agreement_accepted'] = null;
$context['accepted_agreement'] = array(
'errors' => array(
'accepted_agreement' => $txt['agreement_accepted']
)
);
}

if (!empty($_SESSION['privacypolicy_accepted']))
{
$_SESSION['privacypolicy_accepted'] = null;
$context['accepted_agreement'] = array(
'errors' => array(
'accepted_privacy_policy' => $txt['privacypolicy_accepted']
)
);
}

theme()->loadThemeJavascript();

Hooks::instance()->newPath(array('$themedir' => $settings['theme_dir']));
Expand Down
29 changes: 18 additions & 11 deletions sources/Subs.php
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,21 @@ function obExit($header = null, $do_footer = null, $from_index = false, $from_fa
// Need user agent
$req = request();

setOldUrl();

// For session check verification.... don't switch browsers...
$_SESSION['USER_AGENT'] = $req->user_agent();

// Hand off the output to the portal, etc. we're integrated with.
call_integration_hook('integrate_exit', array($do_footer));

// Don't exit if we're coming from index.php; that will pass through normally.
if (!$from_index)
exit;
}

function setOldUrl($index = 'old_url')
{
// Remember this URL in case someone doesn't like sending HTTP_REFERER.
$invalid_old_url = array(
'action=dlattach',
Expand All @@ -945,17 +960,9 @@ function obExit($header = null, $do_footer = null, $from_index = false, $from_fa
}
}
if ($make_old === true)
$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];

// For session check verification.... don't switch browsers...
$_SESSION['USER_AGENT'] = $req->user_agent();

// Hand off the output to the portal, etc. we're integrated with.
call_integration_hook('integrate_exit', array($do_footer));

// Don't exit if we're coming from index.php; that will pass through normally.
if (!$from_index)
exit;
{
$_SESSION[$index] = $_SERVER['REQUEST_URL'];
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions sources/admin/Admin.controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ private function loadMenu()
'subsections' => array(
'register' => array($txt['admin_browse_register_new'], 'moderate_forum'),
'agreement' => array($txt['registration_agreement'], 'admin_forum'),
'privacypol' => array($txt['privacy_policy'], 'admin_forum'),
'reservednames' => array($txt['admin_reserved_set'], 'admin_forum'),
'settings' => array($txt['settings'], 'admin_forum'),
),
Expand Down

0 comments on commit ee87392

Please sign in to comment.