/**
  * Set the user context for the Raven client
  */
 private static function setUserContext()
 {
     // Clear the user context
     self::$_client->context->user = null;
     // Check if the `AuthComponent` is in use for current request
     if (class_exists('AuthComponent')) {
         // Instantiate the user model to get valid field names
         $modelName = Configure::read('Sentry.user.model');
         $user = ClassRegistry::init(empty($modelName) ? 'User' : $modelName);
         // Check if the user is authenticated
         $id = AuthComponent::user($user->primaryKey);
         if ($id) {
             // Check custom username field (defaults to `displayField` on `User` model)
             $usernameField = Configure::read('Sentry.user.fieldMapping.username');
             if (empty($usernameField)) {
                 $usernameField = $user->displayField;
             }
             $extraUserData = array('username' => AuthComponent::user($usernameField));
             // Get user emails
             $emailField = Configure::read('Sentry.user.fieldMapping.email');
             $email = !empty($emailField) ? AuthComponent::user($emailField) : null;
             // Set the user context
             self::$_client->set_user_data($id, $email, $extraUserData);
         }
     }
 }
Exemple #2
0
 /**
  * Set logged in user into raven context
  *
  * @param null $userId
  * @param null $email
  * @param array|NULL $data
  *
  * @return null
  */
 public function setUserContext($userId = null, $email = null, array $data = null)
 {
     $this->raven->set_user_data($userId, $email, $data);
 }