Skip to content

Commit

Permalink
fixed undefined function in update hook and removed prefix from varia…
Browse files Browse the repository at this point in the history
…bles
  • Loading branch information
herbdool committed Oct 15, 2020
1 parent 2a6bd68 commit cae4249
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 59 deletions.
28 changes: 14 additions & 14 deletions config/ip_login.settings.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"_config_name": "ip_login.settings",
"_config_translatables": [
"ip_login_logged_back_in",
"ip_login_link_login_block",
"ip_login_link_login_page",
"ip_login_link_login_page_help"
"logged_back_in",
"link_login_block",
"link_login_page",
"link_login_page_help"
],
"ip_login_active_pages": "",
"ip_login_enabled": 1,
"ip_login_destination": "user",
"ip_login_logged_back_in" : "Account [user:name] does not have permission to log out once automatically logged in. You have been logged back in.",
"ip_login_link_login_block": "Log in automatically",
"ip_login_link_login_block_weight": -10,
"ip_login_link_login_page": "Log in automatically",
"ip_login_link_login_page_help": "Your computer's IP address has been matched and validated.",
"ip_login_link_login_page_weight": -10,
"ip_login_suppress_messages": 0
"active_pages": "",
"enabled": 1,
"destination": "user",
"logged_back_in" : "Account [user:name] does not have permission to log out once automatically logged in. You have been logged back in.",
"link_login_block": "Log in automatically",
"link_login_block_weight": -10,
"link_login_page": "Log in automatically",
"link_login_page_help": "Your computer's IP address has been matched and validated.",
"link_login_page_weight": -10,
"suppress_messages": 0
}
42 changes: 21 additions & 21 deletions ip_login.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -35,48 +35,48 @@ function ip_login_admin_settings() {
array('!link' => '/admin/people/ip_login')
)
);
$form['ip_login_enabled'] = array(
$form['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('IP Login enabled'),
'#description' => t('Check to enable IP Login, uncheck to disable. If unchecked no user will be able to login via IP address.'),
'#default_value' => config_get('ip_login.settings', 'ip_login_enabled')
'#default_value' => config_get('ip_login.settings', 'enabled')
);
$form['ip_login_suppress_messages'] = array(
$form['suppress_messages'] = array(
'#type' => 'checkbox',
'#title' => t('Suppress IP Login messages'),
'#description' => t('Check to prevent IP Login showing any login-related messages.'),
'#default_value' => config_get('ip_login.settings', 'ip_login_suppress_messages')
'#default_value' => config_get('ip_login.settings', 'suppress_messages')
);

$form['ip_login_destination'] = array(
$form['destination'] = array(
'#type' => 'textfield',
'#title' => t('Destination after successful login by IP'),
'#description' => t('<strong>Leave blank to send user back to their originally requested page</strong>, or enter the Backdrop path users should be redirected to when automatically logged in. For example "user" or "&lt;front&gt;" etc.'),
'#default_value' => config_get('ip_login.settings', 'ip_login_destination')
'#default_value' => config_get('ip_login.settings', 'destination')
);

$form['login_page'] = array(
'#type' => 'fieldset',
'#title' => t('Login page link'),
'#description' => t('A link with text from the <em>Login page link text</em> to log the user in automatically will be added to the login page unless it is blank.'),
);
$form['login_page']['ip_login_link_login_page'] = array(
$form['login_page']['link_login_page'] = array(
'#type' => 'textfield',
'#title' => t('Login page link text'),
'#description' => t('Text for link on login page. Blank to remove link, defaults to "Log in automatically"'),
'#default_value' => config_get('ip_login.settings', 'ip_login_link_login_page'),
'#default_value' => config_get('ip_login.settings', 'link_login_page'),
);
$form['login_page']['ip_login_link_login_page_help'] = array(
$form['login_page']['link_login_page_help'] = array(
'#type' => 'textfield',
'#title' => t('Login page help text'),
'#description' => t("Help text under IP Login link on login page. Defaults to 'Your computer's IP address has been matched and validated.' and will not appear if <em>Login page link text</em> is blank."),
'#default_value' => config_get('ip_login.settings', 'ip_login_link_login_page_help'),
'#default_value' => config_get('ip_login.settings', 'link_login_page_help'),
);
$form['login_page']['ip_login_link_login_page_weight'] = array(
$form['login_page']['link_login_page_weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#delta' => 20,
'#default_value' => config_get('ip_login.settings', 'ip_login_link_login_page_weight'),
'#default_value' => config_get('ip_login.settings', 'link_login_page_weight'),
'#description' => t('Optional. The position within the login page form for this link.'),
);

Expand All @@ -85,18 +85,18 @@ function ip_login_admin_settings() {
'#title' => t('Login block link'),
'#description' => t('A link with text from the <em>Login page link text</em> to log the user in automatically will be added to the login page unless it is blank.'),
);
$form['login_block']['ip_login_link_login_block'] = array(
$form['login_block']['link_login_block'] = array(
'#type' => 'textfield',
'#title' => t('Login blocks link text'),
'#description' => t('Text for link on "User login" and "Log in by IP link" blocks. Use blank to remove link, defaults to "Log in automatically"'),
'#default_value' => config_get('ip_login.settings', 'ip_login_link_login_block'),
'#default_value' => config_get('ip_login.settings', 'link_login_block'),
'#required' => FALSE,
);
$form['login_block']['ip_login_link_login_block_weight'] = array(
$form['login_block']['link_login_block_weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#delta' => 20,
'#default_value' => config_get('ip_login.settings', 'ip_login_link_login_block_weight'),
'#default_value' => config_get('ip_login.settings', 'link_login_block_weight'),
'#description' => t('Optional. The position within the login block form for this link.'),
);

Expand All @@ -107,11 +107,11 @@ function ip_login_admin_settings() {
'#description' => t('You can alter other messages here and include tokens listed below.'),
);
$message_default = 'Account [user:name] does not have permission to log out once automatically logged in. You have been logged back in.';
$form['other_messages']['ip_login_logged_back_in'] = array(
$form['other_messages']['logged_back_in'] = array(
'#type' => 'textarea',
'#title' => t('User automatically logged back after attempting logout without permission'),
'#description' => t('Text for the message "' . $message_default . '"'),
'#default_value' => config_get('ip_login.settings', 'ip_login_logged_back_in'),
'#default_value' => config_get('ip_login.settings', 'logged_back_in'),
'#cols' => 100,
'#rows' => 5,
'#required' => FALSE,
Expand All @@ -130,7 +130,7 @@ function ip_login_admin_settings() {
'#collapsible' => FALSE,
);
$access = user_access('use PHP for block visibility');
$pages = config_get('ip_login.settings', 'ip_login_active_pages');
$pages = config_get('ip_login.settings', 'active_pages');
if ($pages) {
$check_mode = substr($pages, 0, 1);
$pages = substr($pages, 1);
Expand Down Expand Up @@ -191,10 +191,10 @@ function ip_login_user_list() {
*/
function ip_login_admin_settings_submit($form, &$form_state) {
if ($form_state['values']['check_pages']) {
config_set('ip_login.settings', 'ip_login_active_pages', $form_state['values']['check_mode'] . $form_state['values']['check_pages']);
config_set('ip_login.settings', 'active_pages', $form_state['values']['check_mode'] . $form_state['values']['check_pages']);
}
else {
config_set('ip_login.settings', 'ip_login_active_pages', '');
config_set('ip_login.settings', 'active_pages', '');
}
}

Expand Down
23 changes: 12 additions & 11 deletions ip_login.install
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function ip_login_install() {
'!link' => l($t('Configure'), 'admin/config/people/ip_login'),
)));
}
config_set('ip_login.settings', 'ip_login_enabled', 1);
config_set('ip_login.settings', 'enabled', 1);
}

/**
Expand Down Expand Up @@ -66,22 +66,23 @@ function ip_login_uninstall() {
function ip_login_update_1000() {
// Migrate variables to config.
$config = config('ip_login.settings');
$config->set('', update_config_get('ip_login.settings', '', 0));
$config->set('', update_variable_get('ip_login_active_pages', ''));
$config->set('', update_variable_get('ip_login_enabled', 1));
$config->set('', update_variable_get('ip_login_destination', 'user'));
$config->set('', update_variable_get('ip_login_link_login_block', 'Log in automatically'));
$config->set('', update_variable_get('ip_login_link_login_block_weight', -10));
$config->set('', update_variable_get('ip_login_link_login_page', 'Log in automatically'));
$config->set('', update_variable_get('ip_login_link_login_page_help', "Your computer's IP address has been matched and validated."));
$config->set('', update_variable_get('ip_login_link_login_page_weight', -10));
$config->set('', update_variable_get('ip_login_suppress_messages', 0));
$config->set('active_pages', update_variable_get('ip_login_active_pages', ''));
$config->set('enabled', update_variable_get('ip_login_enabled', 1));
$config->set('destination', update_variable_get('ip_login_destination', 'user'));
$config->set('logged_back_in', update_variable_get('ip_login_logged_back_in', 'Account [user:name] does not have permission to log out once automatically logged in. You have been logged back in.'));
$config->set('link_login_block', update_variable_get('ip_login_link_login_block', 'Log in automatically'));
$config->set('link_login_block_weight', update_variable_get('ip_login_link_login_block_weight', -10));
$config->set('link_login_page', update_variable_get('ip_login_link_login_page', 'Log in automatically'));
$config->set('link_login_page_help', update_variable_get('ip_login_link_login_page_help', "Your computer's IP address has been matched and validated."));
$config->set('link_login_page_weight', update_variable_get('ip_login_link_login_page_weight', -10));
$config->set('suppress_messages', update_variable_get('ip_login_suppress_messages', 0));
$config->save();

// Delete variables.
update_variable_del('ip_login_active_pages');
update_variable_del('ip_login_enabled');
update_variable_del('ip_login_destination');
update_variable_del('ip_login_logged_back_in');
update_variable_del('ip_login_link_login_block');
update_variable_del('ip_login_link_login_block_weight');
update_variable_del('ip_login_link_login_page');
Expand Down
26 changes: 13 additions & 13 deletions ip_login.module
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function ip_login_boot() {
if ($user->uid != 0) return;

// skip rest of this if the admin has disabled IP login
if (!config_get('ip_login.settings', 'ip_login_enabled')) return;
if (!config_get('ip_login.settings', 'enabled')) return;

// Avoid settings cookies if not on an IP Login-enabled page to improve
// external caching support - http://drupal.org/node/1263234 thanks Vacilando
Expand Down Expand Up @@ -161,7 +161,7 @@ function ip_login_attempt_login() {
if ($matched_uid > 0) {
ip_login_login($matched_uid);
}
backdrop_goto(config_get('ip_login.settings', 'ip_login_destination'));
backdrop_goto(config_get('ip_login.settings', 'destination'));
}

/**
Expand Down Expand Up @@ -190,32 +190,32 @@ function ip_login_form_alter(&$form, &$form_state, $form_id) {
case 'user_login':
$matched_uid = ip_login_check(ip_address());
if ($matched_uid > 0) {
$link_text = t(config_get('ip_login.settings', 'ip_login_link_login_page'));
$link_text = t(config_get('ip_login.settings', 'link_login_page'));
if (backdrop_strlen($link_text)) { // hide if no link text
$link_help = t(config_get('ip_login.settings', 'ip_login_link_login_page_help'));
$link_help = t(config_get('ip_login.settings', 'link_login_page_help'));
$markup = '<br/>';
$markup .= '<ul class="item-list">';
$markup .= '<li><strong>' . l($link_text, ATTEMPT_IP_LOGIN, array('query' => array('ip_login_override_pages' => 'yes'))) . '</strong>';
if (backdrop_strlen($link_help)) $markup .= '<br/><small>' . filter_xss_admin($link_help) . '</small>';
$markup .= '</li></ul>';
$form['ip_login'] = array(
'#markup' => $markup,
'#weight' => config_get('ip_login.settings', 'ip_login_link_login_page_weight'),
'#weight' => config_get('ip_login.settings', 'link_login_page_weight'),
);
}
}
break;
case 'user_login_block':
$matched_uid = ip_login_check(ip_address());
if ($matched_uid > 0) {
$link_text = t(config_get('ip_login.settings', 'ip_login_link_login_block'));
$link_text = t(config_get('ip_login.settings', 'link_login_block'));
if (backdrop_strlen($link_text)) { // hide if no link text
$markup = '<ul class="item-list">';
$markup .= '<li><strong>' . l($link_text, ATTEMPT_IP_LOGIN, array('query' => array('ip_login_override_pages' => 'yes'))) . '</strong>';
$markup .= '</li></ul>';
$form['ip_login'] = array(
'#markup' => $markup,
'#weight' => config_get('ip_login.settings', 'ip_login_link_login_page_weight'),
'#weight' => config_get('ip_login.settings', 'link_login_page_weight'),
);
}
}
Expand Down Expand Up @@ -280,7 +280,7 @@ function ip_login_block_view($delta = '') {
if ($delta <> 'ip-login-link') return;
// build simple block
// @todo should be a hook_theme call
$link_text = t(config_get('ip_login.settings', 'ip_login_link_login_block'));
$link_text = t(config_get('ip_login.settings', 'link_login_block'));
$markup = '<div class="ip-login-available"><span class="ip-login-link">';
$markup .= l($link_text, ATTEMPT_IP_LOGIN, array('query' => array('ip_login_override_pages' => 'yes')));
$markup .= '</span></div>';
Expand Down Expand Up @@ -452,7 +452,7 @@ function ip_login_ip6_expand($ip) {
*/
function ip_login_check_path() {
if (!isset($_GET['ip_login_override_pages'])) {
$pages = config_get('ip_login.settings', 'ip_login_active_pages');
$pages = config_get('ip_login.settings', 'active_pages');
if ($pages) {
$page_match = FALSE;
// first char, if variable set, is 'check_mode' - remainder is paths to match or PHP
Expand Down Expand Up @@ -517,7 +517,7 @@ function ip_login_login($uid) {
// login by assigning account to global $user object
global $user;
$user = $account;
if (!config_get('ip_login.settings', 'ip_login_suppress_messages')) {
if (!config_get('ip_login.settings', 'suppress_messages')) {
// notify user - if messages not suppressed
$message = t(
'Welcome %name. You have been automatically logged into %sitename.',
Expand Down Expand Up @@ -558,7 +558,7 @@ function ip_login_login($uid) {
if (config_get('system.core', 'cache') && !isset($_GET['ip_login_no_cache'])) {
// make a url to reload page, remove newlines from the URL to avoid header injection attacks.
// use admin settings for destination if set.
$url = config_get('ip_login.settings', 'ip_login_destination');
$url = config_get('ip_login.settings', 'destination');
if (backdrop_strlen($url) == 0) $url = str_replace(array("\n", "\r"), '', $_GET["q"]);
if ($url == 'logout') $url = '<front>';
$url = url($url, array('query' => array('ip_login_no_cache=' . md5(time())), 'absolute' => TRUE));
Expand Down Expand Up @@ -608,12 +608,12 @@ function ip_login_user_logout() {
if (!$can_login_as_another_user) {
// @todo: it is possible that some other hook_user_logout() has been called already
// does this generate an undetermined state?
$message = t(config_get('ip_login.settings', 'ip_login_logged_back_in')
$message = t(config_get('ip_login.settings', 'logged_back_in')
);
$message = token_replace($message, array('user' => $user), array('clear' => TRUE));
backdrop_set_message($message, 'warning');
// show the login page
backdrop_goto(config_get('ip_login.settings', 'ip_login_destination'));
backdrop_goto(config_get('ip_login.settings', 'destination'));
}
}

Expand Down

0 comments on commit cae4249

Please sign in to comment.