protected function body()
 {
     if (!$this->userHasPrivileges(User::lecturesManageAll, User::lecturesManageOwn, User::groupsManageAll, User::groupsManageOwn)) {
         return;
     }
     $lite = $this->getParams('lite');
     $user = User::instance();
     $displayAll = $user->hasPrivileges(User::lecturesManageAll) || $lite;
     /**
      * @var $problems \Problem[]
      */
     $problems = Repositories::getEntityManager()->createQuery("SELECT p, l FROM \\Problem p JOIN p.lecture l WHERE p.deleted = false AND (:displayAll = true OR l.owner = :userid)")->setParameter('displayAll', $displayAll)->setParameter('userid', $user->getId())->getResult();
     foreach ($problems as $problem) {
         $row = array($problem->getId(), $problem->getName());
         if (!$lite) {
             $row[] = $problem->getDescription();
             if ($problem->getPlugin()) {
                 $row[] = $problem->getPlugin()->getId();
             } else {
                 $row[] = "";
             }
             $row[] = $problem->getConfig();
         }
         $row[] = $problem->getLecture()->getId();
         if (!$lite) {
             $row[] = $problem->getLecture()->getName();
             $row[] = $problem->getLecture()->getDescription();
         }
         $this->addRowToOutput($row);
     }
 }
Example #2
0
 public static function getUser()
 {
     if (User::$instance == null) {
         User::$instance = new User();
     }
     return User::$instance;
 }
Example #3
0
 public static function getInstance()
 {
     if (null == self::$instance) {
         self::$instance = new User();
     }
     return self::$instance;
 }
Example #4
0
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #5
0
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         User::$instance = new User();
     }
     return self::$instance;
 }
Example #6
0
 protected function body()
 {
     if (!User::instance()->logout()) {
         return $this->stop('logout unsuccessful');
     }
     return true;
 }
 public function isMatch($URL)
 {
     //Check if we're forcing a new URL
     $forcingNewAnalysis = $URL == $this->getNewAnalysisURL();
     //Are they matching the URL?
     $isMatchingURL = $URL == $this->getURL() || $forcingNewAnalysis;
     //Are they logged in?
     $isLoggedIn = $this->user->isLoggedIn();
     if ($isMatchingURL && $isLoggedIn) {
         //Only start considering if it's a match here as we need to query the database after this.
         $dbh = Engine::getDatabase();
         //If this user exists in the database, they have used our application
         //before and an analysis would have been created on authentication
         $this->userExists = $dbh->query("SELECT * FROM Users WHERE User_ID=" . $this->user->id)->fetch(PDO::FETCH_ASSOC) != null;
         if (!$forcingNewAnalysis && $this->userExists) {
             ob_clean();
             header("Location: " . Engine::getRemoteAbsolutePath((new Account())->getURL()));
             exit;
         }
         if (!$this->userExists) {
             $dbh->exec("INSERT INTO Users (User_ID, Name, Email) VALUES ('" . User::instance()->id . "', '" . User::instance()->name . "', '" . User::instance()->email . "')");
         }
         //Otherwise, we are a new user and we don't need to force a new analysis
         return true;
     } else {
         if ($isMatchingURL && !$isLoggedIn) {
             //Go back home as we're not authenticated.
             require 'login.php';
         } else {
             //Wasn't a match at all.
             return false;
         }
     }
 }
Example #8
0
 public static function newInstance()
 {
     if (!self::$instance instanceof self) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 protected function body()
 {
     if (!$this->userHasPrivileges(User::usersPrivPresets)) {
         return false;
     }
     $privilegeGroups = array('users', 'subscriptions', 'plugins', 'assignments', 'submissions', 'lectures', 'groups', 'other');
     $inputs = array_merge(array('name' => array('isAlphaNumeric', 'isNotEmpty')), array_combine($privilegeGroups, array_pad(array(), count($privilegeGroups), array())));
     if (!$this->isInputValid($inputs)) {
         return false;
     }
     $id = $this->getParams('id');
     $name = $this->getParams('name');
     $privileges = array();
     foreach ($privilegeGroups as $i => $group) {
         $value = $this->getParams($group);
         $privileges = array_merge($privileges, $value != '' ? explode(';', $value) : array());
     }
     if (count($privileges)) {
         $privileges = array_combine($privileges, array_pad(array(), count($privileges), true));
     }
     $privileges = User::instance()->packPrivileges($privileges);
     if ($id === null || $id === '') {
         $usertype = new \UserType();
         $usertype->setName($name);
         $usertype->setPrivileges($privileges);
         Repositories::persistAndFlush($usertype);
     } else {
         /** @var \UserType $usertype */
         $usertype = Repositories::findEntity(Repositories::UserType, $id);
         $usertype->setName($name);
         $usertype->setPrivileges($privileges);
         Repositories::persistAndFlush($usertype);
     }
     return true;
 }
 function get_list($gid)
 {
     $data = array('action' => 'list', 'name' => $this->name, 'role' => User::instance()->get_role());
     Event::run('steamcore.aclcheck', $data);
     // which model are we using? one passed through or the default?
     $model = steamcore::get_controls_model($this->gallery);
     $controller = URI::segment(1);
     $tdata = array();
     $page = Input::instance()->get('page', 0);
     $num = 18;
     $offset = 0;
     $limit = 18;
     if ($page) {
         $offset = $num * $page - $num;
     }
     $where = array();
     if (isset($gid) and is_numeric($gid)) {
         $where = array('galleries_id' => $gid);
     }
     // query the model
     $data['query'] = $model->where($where)->limit($limit, $offset)->find_all();
     $data['controller'] = $controller;
     $total = $model->count_last_query();
     $data['pagination'] = '';
     if ($total > $num) {
         $data['pagination'] = Pagination::factory(array('style' => 'digg', 'items_per_page' => $num, 'query_string' => 'page', 'total_items' => $total));
     }
     // merge any passed data and the data returned from the model
     $tdata = array_merge($tdata, $data);
     // return the result
     return $tdata;
 }
Example #11
0
 /**
  * Template loading and setup routine.
  */
 public function __construct()
 {
     parent::__construct();
     $this->obj_session = Session::instance();
     $this->obj_user_lib = User::instance();
     // checke request is ajax
     $this->ajax_request = request::is_ajax();
     if ($this->auto_render == TRUE) {
         Event::add('system.post_controller', array($this, '_render'));
     }
     //$session = Session::instance();
     $user = array();
     $user = $this->obj_session->get('USER');
     //var_dump($_SESSION);
     if (!empty($user)) {
         $this->_user = $this->obj_user_lib->get_user_by_uid($user['id']);
     }
     unset($user);
     $data = array();
     $data['site_config'] = Kohana::config('site_config.site');
     $host = $_SERVER['HTTP_HOST'];
     $dis_site_config = Kohana::config('distribution_site_config');
     if (array_key_exists($host, $dis_site_config) == true && isset($dis_site_config[$host])) {
         $data['site_config']['site_title'] = $dis_site_config[$host]['site_name'];
         $data['site_config']['keywords'] = $dis_site_config[$host]['keywords'];
         $data['site_config']['description'] = $dis_site_config[$host]['description'];
     }
     $this->_site_config = $data;
 }
Example #12
0
 public static function singleton()
 {
     if (self::$instance === NULL) {
         self::$instance = new User();
     }
     return self::$instance;
 }
 protected function body()
 {
     if (!$this->userHasPrivileges(User::groupsJoinPublic, User::groupsJoinPrivate, User::groupsRequest)) {
         return false;
     }
     $user = User::instance();
     $displayPublic = $user->hasPrivileges(User::groupsJoinPublic);
     $displayPrivate = $user->hasPrivileges(User::groupsJoinPrivate, User::groupsRequest);
     /**
      * @var $groups \Group[]
      * @var $subscriptions \Subscription[]
      */
     $subscriptions = Repositories::getRepository(Repositories::Subscription)->findBy(array('user' => $user->getId()));
     $subscriptionGroupIds = array_map(function ($subscription) {
         /** @var $subscription \Subscription */
         return $subscription->getGroup()->getId();
     }, $subscriptions);
     $conditions = array('deleted' => false);
     if (!$displayPrivate) {
         $conditions['type'] = 'public';
     }
     if (!$displayPublic) {
         $conditions['type'] = 'private';
     }
     $groups = Repositories::getRepository(Repositories::Group)->findBy($conditions);
     foreach ($groups as $group) {
         if (in_array($group->getId(), $subscriptionGroupIds)) {
             continue;
         }
         $row = array($group->getId(), $group->getName(), $group->getDescription(), $group->getType(), $group->getLecture()->getId(), $group->getLecture()->getName(), $group->getLecture()->getDescription());
         $this->addRowToOutput($row);
     }
     return true;
 }
Example #14
0
File: User.php Project: lmcro/fcms
 /**
  * getInstance 
  * 
  * @return object
  */
 public static function getInstance($error, $db)
 {
     if (!isset(self::$instance)) {
         self::$instance = new User($error, $db);
     }
     return self::$instance;
 }
 function tearDown()
 {
     clearTestingDbTables();
     $user = User::instance();
     $user->logout();
     $this->metadata_component->tally();
     $this->controller->tally();
 }
Example #16
0
 public static function instance()
 {
     if (!isset(self::$instance)) {
         $class = __CLASS__;
         self::$instance = new $class();
     }
     return self::$instance;
 }
 function __construct()
 {
     if (!User::instance()->id) {
         url::redirect('/auth/login');
     }
     Acl::instance()->redirect(User::instance()->get_role(), 'admin', null, '/auth/login');
     parent::__construct();
 }
 function __construct()
 {
     Event::add('steamcore.aclcheck', array('acl_listeners', 'redirect'));
     $data = array('action' => 'admin', 'name' => null, 'role' => User::instance()->get_role());
     Event::run('steamcore.aclcheck', $data);
     Assets::instance()->add_css('admin');
     parent::__construct();
 }
 function teardown()
 {
     global $CONF;
     // Clean up email
     $user = User::instance($CONF['default_user']);
     $user->email = '';
     $user->update();
     $user->save_data('saved_searches', new QueryList());
 }
 /**
  * Returns an array of all tests that can be viewed, edited and deleted by the logged-in user.
  *
  * @return \Xtest[] tests that can be edited by the active user
  */
 public static function GetTestsVisibleToUser()
 {
     $repository = Repositories::getRepository(Repositories::Xtest);
     if (User::instance()->hasPrivileges(User::lecturesManageAll)) {
         return $repository->findAll();
     } else {
         return Repositories::getEntityManager()->createQuery("SELECT x FROM \\Xtest x JOIN x.lecture l WHERE l.owner = :ownerId")->setParameter('ownerId', User::instance()->getId())->getResult();
     }
 }
Example #21
0
 public function __construct($autoload = false)
 {
     if (\Auth::instance()->logged_in()) {
         $this->user = User::instance(\Auth::instance()->get_user()->id);
     } else {
         $this->user = User::instance();
     }
     return $this->user;
 }
Example #22
0
 public function json()
 {
     if (!User::instance()->id) {
         echo '0';
     }
     $arr = array('id' => '', 'identity' => '', 'country_id' => '', 'email' => '', 'role' => '', 'company' => '', 'first_name' => '', 'last_name' => '', 'address1' => '', 'address2' => '', 'city' => '', 'postcode' => '', 'telephone' => '', 'mobile' => '', 'fax' => '', 'sex' => '', 'looking_for' => '');
     $data = array_intersect_key(User::instance()->get_user()->as_array(), $arr);
     echo json_encode($data);
 }
Example #23
0
 /**
  * construct - gets user data
  *
  * @author Andy Bennett
  */
 function __construct()
 {
     $auth_data = Session::instance()->get('auth_data', false);
     if (!is_object($this->user) and $auth_data !== false) {
         $this->user = $auth_data;
     }
     // Singleton instance
     self::$instance = $this;
 }
 function tearDown()
 {
     $_SERVER = $this->server;
     $this->stats_ip->tally();
     $this->stats_referer->tally();
     $this->stats_search_phrase->tally();
     $this->stats_register->tally();
     User::instance()->logout();
     $this->_cleanUp();
 }
Example #25
0
 public function run($template)
 {
     $authenticatePageURL = Engine::getRemoteAbsolutePath((new Analyse())->getURL());
     $FacebookAuthenticationURL = User::instance()->getFacebookAuthURL($authenticatePageURL);
     $title = "<b>Login</b> with <b>Facebook</b>";
     if (User::instance()->isLoggedIn()) {
         $FacebookAuthenticationURL = $authenticatePageURL;
         $title = "<b>Continue</b> as " . User::instance()->name . "<b></b>";
     }
     $this->loginButton = "<a class=\"fblogin\" style='margin: 0.5em auto;' href=\"{$FacebookAuthenticationURL}\"><i class=\"fa fa-facebook\"></i><span>{$title}</span></a>";
 }
 protected function body()
 {
     if (!$this->userHasPrivileges()) {
         return false;
     }
     // This means the user is not logged in.
     $user = User::instance();
     $user->refresh();
     $this->setOutput('timeout', $user->getTimeout());
     return true;
 }
 /**
  * undocumented function
  *
  * @param string $acl 
  * @return void
  * @author Andy Bennett
  */
 public static function check_acl($acl)
 {
     if (Kohana::find_file('libraries', 'Acl')) {
         $acl = (string) $acl;
         // if no role is specified return true
         if (empty($acl)) {
             return true;
         }
         return Acl::instance()->check(User::instance()->get_role(), null, $acl);
     }
 }
 /**
  * constructor; check acl, set display
  *
  * @author Andy Bennett
  */
 public function __construct()
 {
     parent::__construct();
     $this->setup['status_states'] = 2;
     if (!User::instance()->id) {
         url::redirect('/auth/login');
     }
     Acl::instance()->redirect(User::instance()->get_role(), 'admin', null, '/auth/login');
     $tpl = (request::is_ajax() or isset($_GET['ajax'])) ? 'template-ajax' : 'template-admin';
     Display::instance()->set_template($tpl);
     Assets::instance()->add_css('admin');
 }
 protected function body()
 {
     if (!$this->userHasPrivileges(User::assignmentsSubmit)) {
         return false;
     }
     $ratings = Repositories::getEntityManager()->createQuery("SELECT s, SUM(s.rating) AS rating, a, g.id FROM \\Submission s JOIN s.assignment a JOIN a.group g WHERE s.user = :userId AND s.status = 'graded' GROUP BY g, g.name")->setParameter('userId', User::instance()->getId())->getResult();
     foreach ($ratings as $rating) {
         /** @var \Group $group */
         $group = Repositories::findEntity(Repositories::Group, (int) $rating["id"]);
         $this->addRowToOutput([User::instance()->getName(), User::instance()->getEmail(), $rating["id"], $rating["rating"], $group->getName(), $group->getDescription(), $group->getLecture()->getName(), $group->getLecture()->getDescription()]);
     }
     return true;
 }
Example #30
0
 /**
  * Initializes plugin variables and sets up WordPress hooks/actions.
  */
 protected function __construct()
 {
     $this->plugin_path = trailingslashit(dirname(dirname(__FILE__)));
     $this->plugin_dir = trailingslashit(basename($this->plugin_path));
     $this->plugin_url = plugins_url($this->plugin_dir);
     $this->register_theme_directory();
     //debug('hi');
     self::$user = User::instance();
     self::$content = Content::instance();
     //self::$flash = Flash::instance();
     add_action('init', array($this, 'load_text_domain'), 1);
     $this->add_hooks();
 }