uiplog.module in User IP Log 8
Same filename and directory in other branches
User IP Log module file.
File
uiplog.moduleView source
<?php
/**
* @file
* User IP Log module file.
*/
/**
* Implements hook_form_FORM_ID_alter().
*/
function uiplog_form_user_admin_settings_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$form['uiplog_user_delete_log'] = array(
'#type' => 'radios',
'#title' => t('Delete User IP addresses logged on account delete?'),
'#default_value' => \Drupal::config('uiplog.settings')
->get('uiplog_user_delete_log'),
'#options' => array(
1 => t('Yes'),
0 => t('No'),
),
'#description' => t('"Yes" to delete IP addresses logging pertaining to user on their account delete. "No" to retain all.'),
);
$form['#submit'][] = 'uiplog_user_delete_form_submit';
}
/**
* submit handler for uiplog_user_delete_log.
*/
function uiplog_user_delete_form_submit(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
\Drupal::configFactory()
->getEditable('uiplog.settings')
->set('uiplog_user_delete_log', $form_state
->getValue('uiplog_user_delete_log'))
->save();
}
/**
* Implements hook_user_login().
*/
function uiplog_user_login($account) {
_uiplog_log_ip($account
->id());
}
/**
* Implements hook_user_insert().
*/
function uiplog_user_insert($account) {
$user = \Drupal::currentUser();
if (!$user
->id()) {
_uiplog_log_ip($account
->id());
}
}
/**
* Implements hook_user_delete()
*/
function uiplog_user_delete($account) {
if (\Drupal::state()
->get('uiplog_user_delete_log') == 1) {
db_delete('uiplog')
->condition('uid', $account
->id())
->execute();
}
}
/**
* Inserts user ip into uiplog table.
*/
function _uiplog_log_ip($uid) {
$ip_address = \Drupal::request()
->getClientIp();
if (filter_var($ip_address, FILTER_VALIDATE_IP)) {
db_insert('uiplog')
->fields(array(
'ip' => $ip_address,
'uid' => $uid,
'timestamp' => REQUEST_TIME,
))
->execute();
}
}
Functions
Name![]() |
Description |
---|---|
uiplog_form_user_admin_settings_alter | Implements hook_form_FORM_ID_alter(). |
uiplog_user_delete | Implements hook_user_delete() |
uiplog_user_delete_form_submit | submit handler for uiplog_user_delete_log. |
uiplog_user_insert | Implements hook_user_insert(). |
uiplog_user_login | Implements hook_user_login(). |
_uiplog_log_ip | Inserts user ip into uiplog table. |