You are here

function event_log_track_auth_form_submit in Events Log Track 8.2

Same name and namespace in other branches
  1. 8 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 = [
        'operation' => 'login',
        'description' => t('%user (uid %uid)', [
          '%user' => $account
            ->getUsername(),
          '%uid' => $account
            ->id(),
        ]),
        'ref_numeric' => $account
          ->id(),
        'ref_char' => $account
          ->getUsername(),
      ];
      break;
    case 'user_pass':
      $uid = 0;
      $account = $form_state
        ->getValue('account');
      if (isset($account)) {
        $uid = $account
          ->id();
      }
      $log = [
        'operation' => 'request password',
        'description' => t('%user (uid %uid)', [
          '%user' => $form_state
            ->getValue('name'),
          '%uid' => $uid,
        ]),
        'ref_numeric' => $uid,
        'ref_char' => $form_state
          ->getValue('name'),
      ];
      break;
  }
  return $log;
}