Esempio n. 1
0
	public static function modules()
	{
		$session = UserSession::get();
		if ($session)
		{
			$user = $session->user();
			if (!Acl::isAllowed($user->username, 'admin'))
			{
				return null;
			}
		}
		else
		{
			return null;
		}	
		
		CoOrg::loadPluginInfo('admin');
		$modules = array();
		foreach (self::$_modules as $m)
		{
			if ($m->isAllowed($user))
			{
				$modules[] = $m;
			}
		}
		usort($modules, array('Admin', 'cmpModule'));
		return $modules;
	}
Esempio n. 2
0
	public function save($subject, $body, $commentOn,
	                     $name = null, $email = null, $website = null)
	{
		$commentClass = $this->_commentClass;
		$comment = new $commentClass;
		$comment->title = $subject;
		$comment->comment = $body;
		
		if (UserSession::get())
		{
			$comment->author = UserSession::get()->user();
			$comment->spamStatus = PropertySpamStatus::OK;
		}
		else
		{
			$publicProfile = new AnonProfile;
			$publicProfile->name = $name;
			$publicProfile->email = $email;
			$publicProfile->website = $website;
			$publicProfile->IP = Session::IP();
			$comment->anonAuthor = $publicProfile;
			
			if ($this->checkSpamStatus($comment, $publicProfile) === false)
			{
				$this->newComment = $comment;
				$this->commentRequests = $this->_commentRequests;
				$this->renderErrorSave($commentOn);
				return;
			}
		}
		if ($comment->spamStatus != PropertySpamStatus::SPAM)
		{
			try
			{
				$commentOn->comments[] = $comment;
				if ($comment->spamStatus == PropertySpamStatus::OK)
				{
					$this->notice(t('Your comment has been posted'));
				}
				$this->beforeSuccess($commentOn, $comment);
				$this->redirectOnSuccess($commentOn);
			}
			catch (ValidationException $e)
			{
				$this->error(t('Your comment was not posted'));
				$this->newComment = $comment;
				$this->commentRequests = $this->_commentRequests;
				$this->renderErrorSave($commentOn);
			}
		}
		else
		{
			$this->notice(t('Your comment has been marked as spam, and will not appear'));
			$this->redirectOnSuccess($commentOn);
		}
	}
	protected function renderErrorSave($commentOn)
	{
		if ($this->_captcha)
		{
			$this->commentCaptcha = $this->_captcha;
		}
		else if (!UserSession::get())
		{
			$this->commentCaptcha = Mollom::refresh();
		}
		parent::renderErrorSave($commentOn);
	}
	public function testLoginAndLogout()
	{
		$session = new UserSession('Nathan', 'nathan');
		$session->save();
		
		$this->assertNotNull(UserSession::get());
		$this->assertEquals('Nathan', UserSession::get()->username);
		$user = UserSession::get()->user();
		$this->assertEquals('Nathan', $user->username);
		$this->assertEquals('*****@*****.**', $user->email);
		
		$session->delete();
		
		$this->assertNull(UserSession::get());
	}
Esempio n. 5
0
	public function run($widgetParams, $orient, $request)
	{
		if (UserSession::get() &&
		    Acl::isAllowed(UserSession::get()->username, 'admin'))
		{
			if (substr($request, 0, strpos($request, '/')) == 'admin')
			{
				$this->menu = Admin::modules();
			}
			else
			{
				$this->menu = array(new FakeAdminModule);
			}
			return $this->render('widgets/admin-menu');
		}
	}
Esempio n. 6
0
	public function setUp()
	{
		parent::setUp();
		I18n::setLanguage('');
		Session::destroy();
		if ($s = UserSession::get())
		{
			$s->delete();
		}
		Session::$site = 'http://www.test.info/';
		Session::$referrer = 'http://www.test.info/some/part/of/the/site';
		unlink(COORG_TEST_CONFIG);
		copy(COORG_TEST_CONFIG_CLEAN, COORG_TEST_CONFIG);
		$config = new Config(COORG_TEST_CONFIG);
		$config->set('site/title', 'The Site');
		$config->set('defaultLanguage', '');
		CoOrg::init($config, 'app', 'plugins');
		CoOrgSmarty::clearAll();
		Header::$redirect = '__none__';
	}
	/**
	 * @Acl allow :loggedIn
	*/
	public function update($firstName, $lastName, $birthDate, $gender,
	                       $intrests, $biography, $website, $from = null)
	{
		$profile = UserSession::get()->user()->profile;
		$profile->firstName = $firstName;
		$profile->lastName = $lastName;
		$profile->birthDate = $birthDate;
		$profile->gender = $gender;
		$profile->intrests = $intrests;
		$profile->biography = $biography;
		$profile->website = $website;
		$avatar = Session::getFileUpload('avatar');
		$profile->avatar = $avatar;
		
		try
		{
			$avatar->setAutoStore($profile->username, $profile->avatar_extension);
			$profile->save();
			$this->notice(t('Profile updated'));
			if ($from)
			{
				$this->redirect($from);
			}
			else
			{
				$this->redirect('user/profile/show', $profile->username);
			}
		}
		catch (ValidationException $e)
		{
			$avatar->persist();
			$this->error(t('Profile not updated'));
			$this->from = $from;
			$this->profile = $profile;
			$this->render('profile/edit');
		}
	}
Esempio n. 8
0
	/**
	 * @post
	 * @before get $year $month $day $id $fromLanguage
	 * @Acl allow blog-translator
	 * @Acl owns $:_blog
	*/
	public function translateSave($year, $month, $day, $id, $fromLanguage,
	                              $title, $text, $language)
	{
		$original = $this->_blog;

		try
		{
			$t = $original->translate(UserSession::get()->username, $title, $text, $language);
			$this->notice(t('Your translation of the blog is saved'));
			if ($language == CoOrg::getLanguage())
			{
				$this->redirect('blog/show', $year, $month, $day, $t->ID);
			}
			else
			{
				$this->redirect('blog/show', $year, $month, $day, $t->ID, $language);
			}
		}
		catch (ValidationException $e)
		{
			$this->error(t('Blog translation is not saved'));
			$this->originalBlog = $original;
			$blog = new Blog($title, '', $text, '');
			$blog->language = $language;
			$this->translatedBlog = $blog;
			$this->render('translate');
		}
	}
	/**
	 * @before find $ID
	*/
	public function update($ID, $title, $language, $content, $redirect = null, $preview = null)
	{
		$this->_page->title = $title;
		$this->_page->content = $content;
		$this->_page->lastEditorID = UserSession::get()->username;
		if ($preview)
		{
			$this->preview = 'true';
			$this->page = $this->_page;
			if ($redirect) $this->redirect = $redirect;
			$this->render('admin/edit');
		}
		else
		{
			try
			{
				$this->_page->save();
				$this->notice(t('Page updated'));
				if ($redirect)
				{
					$this->redirect($redirect);
				}
				else
				{
					$this->redirect('page/show', $ID);
				}
			}
			catch (ValidationException $e)
			{
				$this->page = $this->_page;
				if ($redirect) $this->redirect = $redirect;
				$this->error(t('Page is not saved'));
				$this->render('admin/edit');
			}
		}
	}
Esempio n. 10
0
	public function logout()
	{
		$session = UserSession::get();
		if ($session != null)
		{
			$session->delete();
		}
		
		$this->notice(t('You are now logged out'));
		$this->redirect('/');
	}
Esempio n. 11
0
	public function out()
	{
		if ($this->_allowed === null)
		{
			$this->_allowed = $this->_onlyDenied;
		}
		if (!$this->_allowed && !UserSession::get())
		{
			$this->error('You should be logged in to view this page');
			$this->redirect = $this->coorgRequest;
			$this->render('login');
			return false;
		}
		else if (!$this->_allowed)
		{
			$this->error('You don\'t have the rights to view this page');
			$this->redirect('/');
			return false;
		}
		return true;
	}