Ejemplo n.º 1
0
 public function __construct()
 {
     // parent::__construct();
     session_start();
     $this->db = $GLOBALS['db'];
     $this->title(setting('title'));
     $this->set('traq', $this);
     // Is this an overlay request?
     if (Request::$headers->has('X-Overlay')) {
         $this->isOverlay = true;
         $this->layout = false;
     }
     // Are we on a project page?
     if ($projectSlug = Request::$properties->get('pslug')) {
         $this->currentProject = Project::where('slug = ?')->setParameter(0, $projectSlug)->fetch();
     }
     // Is the user logged in?
     if (isset($_COOKIE['traq']) && ($sessionHash = $_COOKIE['traq'])) {
         $user = User::select('u.*', 'g.is_admin')->leftJoin('u', PREFIX . 'usergroups', 'g', 'g.id = u.group_id');
         // Project role
         if ($this->currentProject) {
             $user->addSelect('r.project_role_id')->leftJoin('u', PREFIX . 'user_roles', 'r', 'r.user_id = u.id');
         }
         // By session
         if ($sessionHash) {
             $user->where('u.login_hash = :login_hash')->setParameter('login_hash', $sessionHash);
         }
         // By API key
         // if ($apiKey) {
         // }
         $this->currentUser = $user->fetch();
     }
     // Set current user
     $GLOBALS['currentUser'] = $this->currentUser;
     $this->set('currentUser', $this->currentUser);
     // Set current project
     $GLOBALS['currentProject'] = $this->currentProject;
     $this->set('currentProject', $this->currentProject);
     // Set title
     if ($this->currentProject) {
         $this->title($this->currentProject['name']);
     }
     // Check permission
     $this->before('*', function () use($projectSlug) {
         // Check if project exists
         if ($projectSlug && !$this->currentProject || $projectSlug && !$this->hasPermission('view')) {
             return $this->show404();
         }
     });
     $this->before('*', function () {
         if ($this->currentUser && $this->currentUser['password_ver'] == 'sha1' && Request::$properties->get('controller') != 'Traq\\Controllers\\UserCP' && Request::$properties->get('controller') != 'Traq\\Controllers\\Sessions') {
             return $this->redirectTo('usercp_password');
         }
     });
 }
Ejemplo n.º 2
0
 /**
  * Dashboard index page.
  */
 public function indexAction()
 {
     // Check for update
     $lastUpdateCheck = Setting::find('setting', 'last_update_check');
     if ($lastUpdateCheck->value <= time() - 86400) {
         $this->checkForUpdate();
         $lastUpdateCheck->value = time();
         $lastUpdateCheck->save();
     }
     // Get information
     $info = ['users' => User::select('id')->rowCount(), 'newestUser' => User::select('id', 'name')->orderBy('id', 'DESC')->execute()->fetch(), 'projects' => User::select('id')->rowCount()];
     // Issues
     $info['tickets'] = ['open' => Ticket::select('id')->where('is_closed = ?')->setParameter(0, 0)->rowCount(), 'closed' => Ticket::select('id')->where('is_closed = ?')->setParameter(0, 1)->rowCount()];
     return $this->render('admin/dashboard/index.phtml', $info);
 }
Ejemplo n.º 3
0
 /**
  * Always call this when defining `__construct()` in sub-classes.
  */
 public function __construct()
 {
     $this->db = ConnectionManager::getConnection();
     // Modal?
     if (Request::$headers->has('X-Modal')) {
         $this->isModal = Request::$headers->get('X-Modal') == true;
     }
     // Get current project.
     if (Request::$properties->has('pslug')) {
         $this->currentProject = Project::find('slug', Request::$properties->get('pslug')) ?: null;
         $GLOBALS['current_project'] = $this->currentProject;
         $this->before('*', function () {
             if (!$this->hasPermission('view', $this->currentProject)) {
                 return $this->show404();
             }
         });
     } else {
         $GLOBALS['current_project'] = null;
     }
     // Get current user.
     if ($sessionHash = Request::$cookies->get('traq')) {
         if ($this->currentProject) {
             $user = User::select('u.*')->addSelect('pur.project_role_id')->leftJoin('u', UserRole::tableName(), 'pur', 'pur.project_id = :project_id AND pur.user_id = u.id');
             $user->where('u.session_hash = :session_hash');
             $user->setParameter('project_id', $this->currentProject['id']);
             $user->setParameter('session_hash', $sessionHash);
             $this->currentUser = $user->fetch() ?: null;
         } else {
             $this->currentUser = User::find('session_hash', $sessionHash) ?: null;
         }
         $GLOBALS['current_user'] = $this->currentUser;
     } else {
         $GLOBALS['current_user'] = null;
     }
     $GLOBALS['permissions'] = Permission::getPermissions($this->currentUser, $this->currentProject);
     // Add Traq as first breadcrumb.
     $this->addCrumb(setting('title'), $this->generateUrl('root'));
     // Check if the user has permission to view the current project
     if (isset($this->currentProject)) {
         $this->before('*', function () {
             if (!$this->hasPermission('view')) {
                 return $this->show403();
             }
         });
     }
     // If the user has a `sha1` hashed password, require them to change it because
     // as of Traq 4.1, only mcrypt passwords will work.
     if ($this->currentUser['password_ver'] == 'sha1') {
         $this->before('*', function () {
             if (Request::$properties['controller'] != 'Traq\\Controllers\\UserCP' && Request::$properties['controller'] != 'Traq\\Controllers\\Sessions') {
                 return $this->redirectTo('usercp_password');
             }
         });
     }
 }
Ejemplo n.º 4
0
/**
 * Get the anonymous user.
 *
 * @return User
 */
function anonymous_user()
{
    static $anonymousUser;
    if (!$anonymousUser) {
        $anonymousUser = User::select('u.*', 'g.is_admin')->leftJoin('u', PREFIX . 'usergroups', 'g', 'g.id = u.group_id')->where('u.id = :id')->setParameter('id', setting('anonymous_user_id'))->fetch();
    }
    return $anonymousUser;
}