You are here

function event_log_track_auth_form_submit in Events Log Track 8

Same name and namespace in other branches
  1. 8.2 event_log_track_auth/event_log_track_auth.module \event_log_track_auth_form_submit()

Event log callback for the user authentication event log.

Return value

array Return an associative array of data to insert in database.

1 string reference to 'event_log_track_auth_form_submit'
event_log_track_auth_event_log_track_handlers in event_log_track_auth/event_log_track_auth.module
Implements hook_event_log_track_handlers().

File

event_log_track_auth/event_log_track_auth.module, line 30
Logs user authentication in the event_log_track module.

Code

function event_log_track_auth_form_submit($form, $form_state, $form_id) {
  $account = \Drupal::currentUser();
  $log = NULL;
  switch ($form_id) {
    case 'user_login_form':
      $log = array(
        'operation' => 'login',
        'description' => t('%user (uid %uid)', array(
          '%user' => $account
            ->getUsername(),
          '%uid' => $account
            ->id(),
        )),
        'ref_numeric' => $account
          ->id(),
        'ref_char' => $account
          ->getUsername(),
      );
      break;
    case 'user_pass':
      $log = array(
        'operation' => 'request password',
        'description' => t('%user (uid %uid)', array(
          '%user' => $form_state
            ->getValue('name'),
          '%uid' => $form_state
            ->getValue('account')
            ->id(),
        )),
        'ref_numeric' => $form_state
          ->getValue('account')
          ->id(),
        'ref_char' => $form_state
          ->getValue('name'),
      );
      break;
  }
  return $log;
}