Example #1
0
 public function __construct($username, $realname = 'Real Name', $email = '*****@*****.**', $groups = array())
 {
     $this->assertNotReal();
     $this->username = $username;
     $this->password = '******';
     $this->user = User::newFromName($this->username);
     $this->user->load();
     // In an ideal world we'd have a new wiki (or mock data store) for every single test.
     // But for now, we just need to create or update the user with the desired properties.
     // we particularly need the new password, since we just generated it randomly.
     // In core MediaWiki, there is no functionality to delete users, so this is the best we can do.
     if (!$this->user->isLoggedIn()) {
         // create the user
         $this->user = User::createNew($this->username, array("email" => $email, "real_name" => $realname));
         if (!$this->user) {
             throw new MWException("Error creating TestUser " . $username);
         }
     }
     // Update the user to use the password and other details
     $change = $this->setPassword($this->password) || $this->setEmail($email) || $this->setRealName($realname);
     // Adjust groups by adding any missing ones and removing any extras
     $currentGroups = $this->user->getGroups();
     foreach (array_diff($groups, $currentGroups) as $group) {
         $this->user->addGroup($group);
     }
     foreach (array_diff($currentGroups, $groups) as $group) {
         $this->user->removeGroup($group);
     }
     if ($change) {
         $this->user->saveSettings();
     }
 }
Example #2
0
function checkAccess($access = 'n', $mute = 'f', $target = '', $load_header = false)
{
    global $SETTINGS;
    $granted = false;
    if (empty($user)) {
        require_once 'includes/user.php';
        $user = new User();
    }
    if ($access == 'a') {
        $granted = $user->isLoggedIn() && $user->isAdmin();
    } else {
        $granted = $user->isLoggedIn();
    }
    if (!$granted) {
        if ($mute == 'f') {
            if ($load_header) {
                require_once "header.php";
            }
            $loginLink = $SETTINGS['path_mod'] . "login.php";
            if ($target != "") {
                $loginLink .= "\" target=\"_{$target}";
            }
            if ($access == 'n') {
                echo "<h2>" . T_("Protected Area") . "</h2>\n<p class=\"error\">" . T_("You are not logged in, or your session has expired") . ".</p><p>" . T_("Only registered users can access this page") . ".<br>\n" . sprintf(T_("Please <a href=\"%s\">login</a> into your account from the login page"), $loginLink) . ".</p>\n";
            } else {
                echo "<h2>" . T_("Protected Area") . "</h2>\n<p class=\"error\">" . T_("This is a protected area") . ".</p><p>" . T_("Only admin users can access this page") . ".<br>\n" . sprintf(T_("Please <a href=\"%s\">login</a> into your account from the login page"), $loginLink) . ".</p>\n";
            }
        }
    }
    return $granted;
}
  function testLoginLogout()
  {
    $user = new User();
    $user->set('name', 'whatever');

    $user->login();

    $this->assertTrue($user->isLoggedIn());

    $user->logout();

    $this->assertFalse($user->isLoggedIn());

    $this->assertFalse($user->get('name'));
  }
function fnForumIndexProtector(Title &$title, User &$user, $action, &$result)
{
    if ($user->isLoggedIn()) {
        #this doesnt apply to logged in users, bail, but keep going
        return true;
    }
    if ($action != 'edit' && $action != 'create') {
        #only kill editing actions (what else can anons even do?), bail, but keep going
        return true;
    }
    #this only applies to Forum:Index and Forum_talk:Index
    #check pagename
    if ($title->getText() != 'Index') {
        #wrong pagename, bail, but keep going
        return true;
    }
    $ns = $title->getNamespace();
    #check namespace(s)
    if ($ns == NS_FORUM || $ns == NS_FORUM_TALK) {
        #bingo bango, its a match!
        $result = array('protectedpagetext');
        Wikia::log(__METHOD__, __LINE__, "anon trying to edit forum:index, killing request");
        #bail, and stop the request
        return false;
    }
    return true;
}
Example #5
0
 /**
  * Sets up the session
  *
  * @param $title
  * @param $flashes
  * @param $restricted
  * @param $registered
  * @return array
  */
 static function init($title, $flashes, $restricted, $registered)
 {
     $page = [];
     $page['title'] = $title;
     $page['_SESSION'] = $_SESSION;
     $page['websiteTitle'] = $GLOBALS['websiteTitle'];
     $page['loggedin'] = User::isLoggedIn();
     if ($page['loggedin']) {
         $page['user'] = User::getUser();
     }
     // Redirect to login if the user requests a restricted page is not logged in
     if ($restricted && !User::isLoggedIn()) {
         self::setError('You must be logged in to access this page.');
         self::redirect('/login');
     }
     // Redirect to login if user's session has expired
     if ($restricted && self::hasExpired()) {
         self::destroySession();
         self::setError('Your session has expired, please log back in.');
         self::redirect('/login');
     } else {
         // extend the session
         self::setExpiry();
     }
     // If the page is a registered only page, and the person is not registered, redirect
     if ($registered && User::firstUse()) {
         self::setError('You must be Registered to view this page.');
         self::redirect('/register');
     }
     if ($flashes) {
         $page['flash'] = self::getFlashes();
     }
     $page['_SESSION']['options']['font-size'] = 'normal';
     return $page;
 }
Example #6
0
    /**
     * set data
     */
    public function setData()
    {
        $requestHelper = $this->controller->getRequestHelper();
        $class = $requestHelper->getParam('class');
        $viewMode = $requestHelper->getParam('mode');

        if (!in_array($viewMode, array(DisplayClass::EDIT, DisplayClass::VIEW))) {
            $viewMode = DisplayClass::VIEW;
        }

        $obj = Factory::loadObject($class, $requestHelper->getParam('LK'));
        if (is_null($obj)) {
            $obj = Factory::createObject($class);
        }
        $this->obj = $obj;

        $user = Flat::user();
        $dataPermission = DataPermission::createObject($obj);
        if (!User::isLoggedIn() || !$user->isEntitled($obj->getPermissionForViewMode($viewMode)) || !$dataPermission->isUserOccupant($user->getLogicalKey())) {
            $viewMode = DisplayClass::VIEW;
        }

        $formModel = new base_form_Model($obj, $viewMode);
        $formModel->setAjaxForm('base_ajax_save_Controller');
        $formModel->setMethod(base_form_Model::METHOD_POST);
        $formModel->addAction("&class=$class");
        $formModel->addAction("&caller=" . $this->controller->getCallerSection());
        $formModel->setId('inputData');
        $this->data = new base_form_View($formModel);
    }
Example #7
0
 public static function setupSiteInterfaceLocalization(Page $c = null)
 {
     $loc = \Localization::getInstance();
     if (!(\User::isLoggedIn() && Config::get('concrete.multilingual.keep_users_locale'))) {
         if (!$c) {
             $c = Page::getCurrentPage();
         }
         // don't translate dashboard pages
         $dh = \Core::make('helper/concrete/dashboard');
         if ($dh->inDashboard($c)) {
             return;
         }
         $locale = null;
         $ms = Section::getBySectionOfSite($c);
         if ($ms) {
             $locale = $ms->getLocale();
         }
         if (!$locale) {
             if (Config::get('concrete.multilingual.use_previous_locale') && Session::has('previous_locale')) {
                 $locale = Session::get('previous_locale');
             }
             if (!$locale) {
                 $ms = static::getPreferredSection();
                 if ($ms) {
                     $locale = $ms->getLocale();
                 }
             }
         }
         if ($locale) {
             $loc->setLocale($locale);
         }
     }
     Session::set('previous_locale', $loc->getLocale());
 }
Example #8
0
 public function on_start()
 {
     Loader::helper('ms_route', 'multisite');
     if (!User::isLoggedIn()) {
         Events::extend('on_before_render', 'MsRouter', 'render', 'packages/' . $this->pkgHandle . '/models/ms_router.php');
     }
 }
 function beforeroute()
 {
     $user = new User();
     if (!$user->isLoggedIn()) {
         Redirect::to("login");
     }
 }
Example #10
0
 public function home()
 {
     if (User::isLoggedIn()) {
         $this->set('apps', User::$me->getMyApps()->getAll());
         $this->set('authorized', User::$me->getAuthorizedApps()->getAll());
     }
 }
Example #11
0
 public static function setupSiteInterfaceLocalization(Page $c = null)
 {
     if (\User::isLoggedIn() && Config::get('concrete.multilingual.keep_users_locale')) {
         return;
     }
     if (!$c) {
         $c = Page::getCurrentPage();
     }
     // don't translate dashboard pages
     $dh = \Core::make('helper/concrete/dashboard');
     if ($dh->inDashboard($c)) {
         return;
     }
     $ms = Section::getBySectionOfSite($c);
     if (!is_object($ms)) {
         $ms = static::getPreferredSection();
     }
     if (!$ms) {
         return;
     }
     $locale = $ms->getLocale();
     if (strlen($locale)) {
         \Localization::changeLocale($locale);
     }
 }
 public function get()
 {
     if (User::isLoggedIn()) {
         header("Location:/Socio/home");
     } else {
         View::render("register_view");
     }
 }
Example #13
0
function protect_page_notLogin()
{
    $user = new User();
    if (!$user->isLoggedIn()) {
        Redirect::to('protect.php');
        exit;
    }
}
Example #14
0
 public function home()
 {
     $this->set('area', 'app');
     if (User::isLoggedIn()) {
         $this->set('apps', User::$me->getMyApps()->getAll());
         $this->set('authorized', User::$me->getAuthorizedApps()->getAll());
         $this->set('requesting', OAuthToken::getRequestTokensByIP()->getAll());
     }
 }
Example #15
0
 public static function checkAuthorisation()
 {
     require_once '../classes/User.php';
     $login = new User();
     if (!$login->isLoggedIn()) {
         echo "YOU ARE NOT AUTHORISED";
         exit;
     }
 }
Example #16
0
 public function assertLoggedIn()
 {
     if (!User::isLoggedIn()) {
         //create our payload
         $payload = array('type' => 'redirect', 'data' => $_SERVER['REQUEST_URI']);
         $payloadEncoded = base64_encode(serialize($payload));
         $this->forwardToUrl("/login/{$payloadEncoded}");
     }
 }
Example #17
0
 public function canEdit()
 {
     if (User::$me->isAdmin()) {
         return true;
     }
     if (User::isLoggedIn() && $this->get('user_id') == User::$me->id) {
         return true;
     }
     return false;
 }
Example #18
0
 public function get()
 {
     if (User::isLoggedIn()) {
         $arr = Post::where("user1", "=", Session::get("id") . " ORDER BY timestamp DESC");
         $users = User::all();
         View::render("home_view", array("arr" => $arr, "users" => $users));
     } else {
         header("Location:/Socio/login");
     }
 }
 /**
  * Get user object.
  *
  * @return User object: User object for autocreate user.
  */
 public static function user()
 {
     if (!self::$user) {
         $userName = wfMessage('babel-autocreate-user')->inContentLanguage()->plain();
         self::$user = User::newFromName($userName);
         if (self::$user && !self::$user->isLoggedIn()) {
             self::$user->addToDatabase();
         }
     }
     return self::$user;
 }
Example #20
0
 public final function __construct()
 {
     Slim::getInstance()->view('Slim\\View\\AdminLayout');
     if (!User::isLoggedIn() and Slim::getInstance()->request()->isGet()) {
         Slim::getInstance()->render('admin/login-form.php');
         exit;
     }
     if (!User::isLoggedIn()) {
         Slim::getInstance()->notFound();
     }
 }
 /**
  * Get a user object for doing edits, from a request-lifetime cache
  * False will be returned if the user name specified in the
  * 'double-redirect-fixer' message is invalid.
  *
  * @return User|bool
  */
 function getUser()
 {
     if (!self::$user) {
         $username = wfMessage('double-redirect-fixer')->inContentLanguage()->text();
         self::$user = User::newFromName($username);
         # User::newFromName() can return false on a badly configured wiki.
         if (self::$user && !self::$user->isLoggedIn()) {
             self::$user->addToDatabase();
         }
     }
     return self::$user;
 }
	protected function showSignup( $step ) {
		$header = new HtmlTag( 'h2' );
		$step_message = 'translate-fs-signup-title';
		$header->style( 'opacity', 0.4 )->content( wfMsg( $step_message ) );

		if ( $step ) {
			$this->out->addHtml( $header );
			return $step;
		}

		if ( $this->user->isLoggedIn() ) {
			$header->content( $header->content . wfMsg( 'translate-fs-pagetitle-done' ) );
			$this->out->addHtml( $header );
			return $step;
		} else {
			// Go straight to create account (or login) page
			$create = SpecialPage::getTitleFor( 'Userlogin' );
			$returnto = $this->getTitle()->getPrefixedText();
			$this->out->redirect( $create->getLocalUrl( array( 'returnto' => $returnto , 'type' => 'signup' ) ) );
		}
	}
Example #23
0
 function __construct($user = null)
 {
     parent::__construct($user);
     $this->_tableName = "student";
     if (parent::isLoggedIn()) {
         $this->_homework = new Homework();
         if ($this->findInfo($this->_data->id)) {
             $this->_isLoggedIn = true;
         } else {
             // echo "<script>alert('权限不足');location.href='admin.php';</script>";
         }
     }
 }
Example #24
0
 public function renderView()
 {
     if (User::isLoggedIn() && User::theUser()->isAdmin()) {
         $view = $this->getView();
         if (file_exists(ADMIN_VIEWS_PATH . $view . '.view.php')) {
             require_once ADMIN_VIEWS_PATH . $view . '.view.php';
         } else {
             require_once ADMIN_VIEWS_PATH . '404.view.php';
         }
     } else {
         require_once ADMIN_VIEWS_PATH . 'restricted.view.php';
     }
 }
Example #25
0
 /**
  * Watch or unwatch a page
  * @since 1.22
  * @param bool $watch Whether to watch or unwatch the page
  * @param Title $title Page to watch/unwatch
  * @param User $user User who is watching/unwatching
  * @return Status
  */
 public static function doWatchOrUnwatch($watch, Title $title, User $user)
 {
     if ($user->isLoggedIn() && $user->isWatched($title, User::IGNORE_USER_RIGHTS) != $watch) {
         // If the user doesn't have 'editmywatchlist', we still want to
         // allow them to add but not remove items via edits and such.
         if ($watch) {
             return self::doWatch($title, $user, User::IGNORE_USER_RIGHTS);
         } else {
             return self::doUnwatch($title, $user);
         }
     }
     return Status::newGood();
 }
Example #26
0
 public function home()
 {
     $this->setTitle("Slicer Engines");
     $this->set('area', 'slicers');
     if (User::isAdmin()) {
         $this->set('slicers', SliceEngine::getAllEngines()->getAll());
     } else {
         $this->set('slicers', SliceEngine::getPublicEngines()->getAll());
     }
     if (User::isLoggedIn()) {
         $this->set('configs', User::$me->getMySliceConfigs()->getAll());
     }
 }
Example #27
0
 public function __construct($username, $realname = 'Real Name', $email = '*****@*****.**', $groups = [])
 {
     $this->assertNotReal();
     $this->username = $username;
     $this->password = '******';
     $this->user = User::newFromName($this->username);
     $this->user->load();
     // In an ideal world we'd have a new wiki (or mock data store) for every single test.
     // But for now, we just need to create or update the user with the desired properties.
     // we particularly need the new password, since we just generated it randomly.
     // In core MediaWiki, there is no functionality to delete users, so this is the best we can do.
     if (!$this->user->isLoggedIn()) {
         // create the user
         $this->user = User::createNew($this->username, ["email" => $email, "real_name" => $realname]);
         if (!$this->user) {
             throw new MWException("Error creating TestUser " . $username);
         }
     }
     // Update the user to use the password and other details
     $this->setPassword($this->password);
     $change = $this->setEmail($email) || $this->setRealName($realname);
     // Adjust groups by adding any missing ones and removing any extras
     $currentGroups = $this->user->getGroups();
     foreach (array_diff($groups, $currentGroups) as $group) {
         $this->user->addGroup($group);
     }
     foreach (array_diff($currentGroups, $groups) as $group) {
         $this->user->removeGroup($group);
     }
     if ($change) {
         // Disable CAS check before saving. The User object may have been initialized from cached
         // information that may be out of whack with the database during testing. If tests were
         // perfectly isolated, this would not happen. But if it does happen, let's just ignore the
         // inconsistency, and just write the data we want - during testing, we are not worried
         // about data loss.
         $this->user->mTouched = '';
         $this->user->saveSettings();
     }
 }
Example #28
0
function login($user, $pxwd, $db)
{
    $newUser = new User($user, $pxwd, $db);
    if ($newUser->isLoggedIn()) {
        // If authentication successful, start user session...
        $_SESSION["user"] = $newUser;
    } else {
        // If authentication failed, destroy new user container...
        unset($newUser);
        // And redirect to login page
        header("Location: index.php?err=1");
    }
}
 public static function _authenticate()
 {
     if (User::isLoggedIn()) {
         $user = User::find(intval($_SESSION['userid']));
         $member = Member::find(intval($_SESSION['memberid']));
         $tools = Tool::find_all($user->role);
         $divisions = Division::find_all();
         Flight::render('layouts/auth', [], 'content');
         Flight::render('layouts/application', compact('user', 'member', 'tools', 'divisions'));
     } else {
         Flight::render('layouts/auth', [], 'content');
         Flight::render('layouts/application', compact('user', 'member', 'tools', 'divisions'));
     }
 }
Example #30
0
 public static function set($key, $value)
 {
     if (!User::isLoggedIn()) {
         throw new Exception("User is not logged in.");
     }
     $id = User::getUserID();
     self::$userConfig = null;
     if (is_null($value) || is_string($value) && strlen(trim($value)) == 0) {
         // Just remove the row and let the defaults take over
         return Db::execute("delete from zz_users_config where id = :id and locker = :key", array(":id" => $id, ":key" => $key));
     }
     $value = json_encode($value);
     return Db::execute("insert into zz_users_config (id, locker, content) values (:id, :key, :value)\n                                on duplicate key update content = :value", array(":id" => $id, ":key" => $key, ":value" => $value));
 }