/**
  * Log user authentication
  *
  * @param CUser $user The user logging-in
  *
  * @return void
  */
 static function logAuth(CUser $user)
 {
     if (!self::authReady() || $user->dont_log_connection) {
         return;
     }
     global $rootName;
     $session_name = preg_replace("/[^a-z0-9]/i", "", $rootName);
     $app = CAppUI::$instance;
     $auth = new self();
     $auth->user_id = $user->_id;
     $auth->previous_user_id = null;
     $auth->auth_method = $app->auth_method;
     $auth->datetime_login = CMbDT::dateTime();
     $auth->id_address = $app->ip;
     $auth->session_id = session_id();
     // Screen size
     $cookie = CValue::cookie("{$session_name}-uainfo");
     $uainfo = stripslashes($cookie);
     if ($uainfo) {
         $uainfo = json_decode($uainfo, true);
         if (isset($uainfo["screen"])) {
             $screen = $uainfo["screen"];
             $auth->screen_width = (int) $screen[0];
             $auth->screen_height = (int) $screen[1];
         }
     }
     // User agent
     $user_agent_string = CValue::read($_SERVER, "HTTP_USER_AGENT");
     if ($user_agent_string) {
         $user_agent = CUserAgent::createFromUA($user_agent_string);
         $auth->user_agent_id = $user_agent->_id;
     }
     $auth->store();
 }