get_user() public méthode

Returns FALSE if no user is currently logged in.
public get_user ( ) : mixed
Résultat mixed
 /**
  * провкрка авторизации по конфигу
  * @return type
  * @throws HTTP_Exception_401
  */
 private function checkAuth()
 {
     if (!class_exists("Kohana_Auth")) {
         return;
     }
     $haveAccess = NULL;
     $authConfig = Kohana::$config->load("structure.kohana.auth");
     $authRoles = explode(",", $authConfig['roles']);
     if ($authConfig['enabled']) {
         $this->auth = Auth::instance();
         $user = $this->auth->get_user();
         if (!$user) {
             throw new HTTP_Exception_401();
         }
         $roles = $user->roles->find_all()->as_array();
         foreach ($roles as $userRole) {
             $userRoles[] = $userRole->name;
         }
         foreach ($userRoles as $currentUserRole) {
             if (in_array($currentUserRole, $authRoles)) {
                 $haveAccess = $currentUserRole;
             }
         }
         if (!$haveAccess) {
             throw new HTTP_Exception_401();
         }
     }
     return $haveAccess;
 }
Exemple #2
0
 /**
  * Gets the currently logged in user from the session (with auto_login check).
  * Returns FALSE if no user is currently logged in.
  *
  * @return  mixed
  */
 public function get_user($default = NULL)
 {
     $user = parent::get_user($default);
     if (!$user) {
         // check for "remembered" login
         $user = $this->auto_login();
     }
     return $user;
 }
Exemple #3
0
 /**
  * @param null $default
  *
  * @return mixed|Model_User
  */
 public function get_user($default = NULL)
 {
     if (!$this->current_user) {
         $user = parent::get_user($default = NULL);
         if ($user) {
             $this->current_user = Model_User::find_by_username($user->user_id);
         }
     }
     return $this->current_user;
 }