import v1.0.0-RC4 | 2009-05-20
This commit is contained in:
36
modules/default/controllers/AboutController.php
Normal file
36
modules/default/controllers/AboutController.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class AboutController extends Monkeys_Controller_Action
|
||||
{
|
||||
protected $_numCols = 1;
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$scriptsDir = $this->view->getScriptPath('about');
|
||||
|
||||
$locale = Zend_Registry::get('Zend_Locale');
|
||||
// render() changes _ to -
|
||||
$locale = str_replace('_', '-', $locale);
|
||||
$localeElements = explode('-', $locale);
|
||||
|
||||
if (file_exists("$scriptsDir/index-$locale.phtml")) {
|
||||
$view = "index-$locale";
|
||||
} else if (count($localeElements == 2)
|
||||
&& file_exists("$scriptsDir/index-".$localeElements[0].".phtml")) {
|
||||
$view = 'index-'.$localeElements[0];
|
||||
} else {
|
||||
$view = 'index-en';
|
||||
}
|
||||
|
||||
$this->render($view);
|
||||
}
|
||||
}
|
14
modules/default/controllers/ErrorController.php
Executable file
14
modules/default/controllers/ErrorController.php
Executable file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class ErrorController extends Monkeys_Controller_Error
|
||||
{
|
||||
}
|
111
modules/default/controllers/FeedbackController.php
Normal file
111
modules/default/controllers/FeedbackController.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class FeedbackController extends Monkeys_Controller_Action
|
||||
{
|
||||
protected $_numCols = 1;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
if ($this->user->role != User::ROLE_ADMIN && $this->underMaintenance) {
|
||||
return $this->_redirectForMaintenance();
|
||||
}
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$appSession = Zend_Registry::get('appSession');
|
||||
if (isset($appSession->feedbackForm)) {
|
||||
$form = $appSession->feedbackForm;
|
||||
unset($appSession->feedbackForm);
|
||||
} else {
|
||||
$form = new FeedbackForm(null, $this->view->base);
|
||||
}
|
||||
$this->view->form = $form;
|
||||
}
|
||||
|
||||
public function sendAction()
|
||||
{
|
||||
$form = new FeedbackForm(null, $this->view->base);
|
||||
$formData = $this->_request->getPost();
|
||||
$form->populate($formData);
|
||||
|
||||
if (!$form->isValid($formData)) {
|
||||
$appSession = Zend_Registry::get('appSession');
|
||||
$appSession->feedbackForm = $form;
|
||||
return $this->_forward('index', null, null);
|
||||
}
|
||||
|
||||
$mail = self::getMail(
|
||||
$form->getValue('name'),
|
||||
$form->getValue('email'),
|
||||
$form->getValue('feedback')
|
||||
);
|
||||
|
||||
try {
|
||||
$mail->send();
|
||||
$this->_helper->FlashMessenger->addMessage('Thank you for your interest. Your message has been routed.');
|
||||
} catch (Zend_Mail_Protocol_Exception $e) {
|
||||
$this->_helper->FlashMessenger->addMessage('Sorry, the feedback couldn\'t be delivered. Please try again later.');
|
||||
if ($this->_config->logging->level == Zend_Log::DEBUG) {
|
||||
$this->_helper->FlashMessenger->addMessage($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$this->_redirect('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Mail
|
||||
* @throws Zend_Mail_Protocol_Exception
|
||||
*/
|
||||
public static function getMail($name, $email, $feedback)
|
||||
{
|
||||
// can't use $this-_config 'cause it's a static function
|
||||
$configEmail = Zend_Registry::get('config')->email;
|
||||
|
||||
switch (strtolower($configEmail->transport)) {
|
||||
case 'smtp':
|
||||
Zend_Mail::setDefaultTransport(
|
||||
new Zend_Mail_Transport_Smtp(
|
||||
$configEmail->host,
|
||||
$configEmail->toArray()
|
||||
)
|
||||
);
|
||||
break;
|
||||
case 'mock':
|
||||
Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Mock());
|
||||
break;
|
||||
default:
|
||||
Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Sendmail());
|
||||
}
|
||||
|
||||
$mail = new Zend_Mail();
|
||||
$mail->setBodyText(<<<EOD
|
||||
Dear Administrator,
|
||||
|
||||
The community-id feedback form has just been used to send you the following:
|
||||
|
||||
Name: $name
|
||||
E-mail: $email
|
||||
Feedback:
|
||||
$feedback
|
||||
EOD
|
||||
);
|
||||
$mail->setFrom('support@community-id.org');
|
||||
$mail->addTo($configEmail->supportemail);
|
||||
$mail->setSubject('Community-ID feedback form');
|
||||
|
||||
return $mail;
|
||||
}
|
||||
}
|
64
modules/default/controllers/HistoryController.php
Executable file
64
modules/default/controllers/HistoryController.php
Executable file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class HistoryController extends Monkeys_Controller_Action
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$this->_helper->actionStack('index', 'login', 'users');
|
||||
}
|
||||
|
||||
public function listAction()
|
||||
{
|
||||
$this->_helper->viewRenderer->setNeverRender(true);
|
||||
|
||||
$histories = new Histories();
|
||||
$historiesRows = $histories->get(
|
||||
$this->user,
|
||||
$this->_getParam('startIndex'),
|
||||
$this->_getParam('results')
|
||||
);
|
||||
|
||||
$jsonObj = new StdClass();
|
||||
$jsonObj->recordsReturned = count($historiesRows);
|
||||
$jsonObj->totalRecords = $histories->getNumHistories($this->user);
|
||||
$jsonObj->startIndex = $this->_getParam('startIndex');
|
||||
$jsonObj->sort = null;
|
||||
$jsonObj->dir = 'asc';
|
||||
$jsonObj->records = array();
|
||||
|
||||
foreach ($historiesRows as $history) {
|
||||
$jsonObjSite = new StdClass();
|
||||
$jsonObjSite->id = $history->id;
|
||||
$jsonObjSite->date = $history->date;
|
||||
$jsonObjSite->site = $history->site;
|
||||
$jsonObjSite->ip = $history->ip;
|
||||
$jsonObjSite->result = $history->result;
|
||||
|
||||
$jsonObj->records[] = $jsonObjSite;
|
||||
}
|
||||
|
||||
echo Zend_Json::encode($jsonObj);
|
||||
}
|
||||
|
||||
public function clearAction()
|
||||
{
|
||||
$this->_helper->viewRenderer->setNeverRender(true);
|
||||
|
||||
$histories = new Histories();
|
||||
$histories->clear($this->user);
|
||||
|
||||
$json = new StdClass();
|
||||
$json->code = 200;
|
||||
|
||||
echo Zend_Json::encode($json);
|
||||
}
|
||||
}
|
58
modules/default/controllers/IdentityController.php
Normal file
58
modules/default/controllers/IdentityController.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class IdentityController extends Monkeys_Controller_Action
|
||||
{
|
||||
protected $_numCols = 1;
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
throw new Monkeys_BadUrlException($this->getRequest()->getRequestUri());
|
||||
}
|
||||
|
||||
public function idAction()
|
||||
{
|
||||
$currentUrl = Zend_OpenId::selfURL();
|
||||
|
||||
if ($this->_config->subdomain->enabled) {
|
||||
$protocol = $this->_getProtocol();
|
||||
preg_match('#(.*)\.'.$this->_config->subdomain->hostname.'#', $currentUrl, $matches);
|
||||
|
||||
$this->view->headLink()->headLink(array(
|
||||
'rel' => 'openid.server',
|
||||
'href' => "$protocol://"
|
||||
. ($this->_config->subdomain->use_www? 'www.' : '')
|
||||
. $this->_config->subdomain->hostname
|
||||
. '/openid/provider'
|
||||
));
|
||||
$this->view->headLink()->headLink(array(
|
||||
'rel' => 'openid2.provider',
|
||||
'href' => "$protocol://"
|
||||
. ($this->_config->subdomain->use_www? 'www.' : '')
|
||||
. $this->_config->subdomain->hostname
|
||||
. '/openid/provider'
|
||||
));
|
||||
} else {
|
||||
preg_match('#(.*)/identity/#', $currentUrl, $matches);
|
||||
|
||||
$this->view->headLink()->headLink(array(
|
||||
'rel' => 'openid.server',
|
||||
'href' => $matches[1] . '/openid/provider',
|
||||
));
|
||||
$this->view->headLink()->headLink(array(
|
||||
'rel' => 'openid2.provider',
|
||||
'href' => $matches[1] . '/openid/provider',
|
||||
));
|
||||
}
|
||||
|
||||
$this->view->idUrl = $currentUrl;
|
||||
}
|
||||
}
|
87
modules/default/controllers/IndexController.php
Normal file
87
modules/default/controllers/IndexController.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class IndexController extends Monkeys_Controller_Action
|
||||
{
|
||||
const NEWS_CONTENT_MAX_LENGTH = 100;
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$scriptsDir = $this->view->getScriptPaths();
|
||||
|
||||
$locale = Zend_Registry::get('Zend_Locale');
|
||||
// render() changes _ to -
|
||||
$locale = str_replace('_', '-', $locale);
|
||||
$localeElements = explode('-', $locale);
|
||||
|
||||
$view = false;
|
||||
foreach ($scriptsDir as $scriptDir) {
|
||||
if (file_exists($scriptDir."index/subheader-$locale.phtml")) {
|
||||
$view = "subheader-$locale";
|
||||
break;
|
||||
} else if (count($localeElements == 2)
|
||||
&& file_exists($scriptDir."index/subheader-".$localeElements[0].".phtml")) {
|
||||
$view = 'subheader-'.$localeElements[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$view) {
|
||||
$view = 'subheader-en';
|
||||
}
|
||||
|
||||
$this->getResponse()->insert('subHeader', $this->view->render("index/$view.phtml"));
|
||||
|
||||
$this->_helper->actionStack('index', 'login', 'users');
|
||||
|
||||
try {
|
||||
$feed = Zend_Feed::import($this->_config->news_feed->url);
|
||||
} catch (Zend_Exception $e) {
|
||||
// feed import failed
|
||||
$obj = new StdClass();
|
||||
$obj->link = array('href' => '');
|
||||
$obj->title = $this->view->translate('Could not retrieve news items');
|
||||
$obj->updated = '';
|
||||
$obj->content = '';
|
||||
$feed = array($obj);
|
||||
}
|
||||
|
||||
$this->view->news = array();
|
||||
$i = 0;
|
||||
foreach ($feed as $item) {
|
||||
if ($i++ >= $this->_config->news_feed->num_items) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (strlen($item->content) > self::NEWS_CONTENT_MAX_LENGTH) {
|
||||
$item->content = substr($item->content, 0, self::NEWS_CONTENT_MAX_LENGTH)
|
||||
. '...<br /><a class="readMore" href="'.$item->link['href'].'">' . $this->view->translate('Read More') . '</a>';
|
||||
}
|
||||
$this->view->news[] = $item;
|
||||
}
|
||||
|
||||
$view = false;
|
||||
foreach ($scriptsDir as $scriptDir) {
|
||||
if (file_exists($scriptDir."index/index-$locale.phtml")) {
|
||||
$view = "index-$locale";
|
||||
break;
|
||||
} else if (count($localeElements == 2)
|
||||
&& file_exists($scriptDir."index/index-".$localeElements[0].".phtml")) {
|
||||
$view = 'index-'.$localeElements[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$view) {
|
||||
$view = 'index-en';
|
||||
}
|
||||
|
||||
$this->render($view);
|
||||
}
|
||||
}
|
37
modules/default/controllers/LearnmoreController.php
Normal file
37
modules/default/controllers/LearnmoreController.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class LearnmoreController extends Monkeys_Controller_Action
|
||||
{
|
||||
protected $_numCols = 1;
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$scriptsDir = $this->view->getScriptPath('learnmore');
|
||||
|
||||
$locale = Zend_Registry::get('Zend_Locale');
|
||||
// render() changes _ to -
|
||||
$locale = str_replace('_', '-', $locale);
|
||||
$localeElements = explode('-', $locale);
|
||||
|
||||
if (file_exists("$scriptsDir/index-$locale.phtml")) {
|
||||
$view = "index-$locale";
|
||||
} else if (count($localeElements == 2)
|
||||
&& file_exists("$scriptsDir/index-".$localeElements[0].".phtml")) {
|
||||
$view = 'index-'.$localeElements[0];
|
||||
} else {
|
||||
$view = 'index-en';
|
||||
}
|
||||
|
||||
$this->render($view);
|
||||
}
|
||||
}
|
||||
|
35
modules/default/controllers/MaintenancemodeController.php
Normal file
35
modules/default/controllers/MaintenancemodeController.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class MaintenancemodeController extends Monkeys_Controller_Action
|
||||
{
|
||||
private $_settings;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
$this->_settings = new Settings();
|
||||
}
|
||||
|
||||
public function enableAction()
|
||||
{
|
||||
$this->_settings->set(Settings::MAINTENANCE_MODE, 1);
|
||||
|
||||
$this->_redirect('');
|
||||
}
|
||||
|
||||
public function disableAction()
|
||||
{
|
||||
$this->_settings->set(Settings::MAINTENANCE_MODE, 0);
|
||||
|
||||
$this->_redirect('');
|
||||
}
|
||||
}
|
130
modules/default/controllers/MessageusersController.php
Normal file
130
modules/default/controllers/MessageusersController.php
Normal file
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class MessageusersController extends Monkeys_Controller_Action
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$appSession = Zend_Registry::get('appSession');
|
||||
if (isset($appSession->messageUsersForm)) {
|
||||
$this->view->messageUsersForm = $appSession->messageUsersForm;
|
||||
unset($appSession->messageUsersForm);
|
||||
} else {
|
||||
$this->view->messageUsersForm = new MessageUsersForm();
|
||||
}
|
||||
|
||||
$this->_helper->actionStack('index', 'login', 'users');
|
||||
}
|
||||
|
||||
public function sendAction()
|
||||
{
|
||||
$form = new MessageUsersForm();
|
||||
$formData = $this->_request->getPost();
|
||||
|
||||
$form->populate($formData);
|
||||
if (!$form->isValid($formData)) {
|
||||
return $this->_redirectFaultyForm($form);
|
||||
}
|
||||
|
||||
$cc = $form->getValue('cc');
|
||||
$ccArr = array();
|
||||
if (trim($cc) != '') {
|
||||
$validator = new Zend_Validate_EmailAddress();
|
||||
$ccArr = explode(',', $cc);
|
||||
for ($i = 0; $i < count($ccArr); $i++) {
|
||||
$ccArr[$i] = trim($ccArr[$i]);
|
||||
if (!$validator->isValid($ccArr[$i])) {
|
||||
foreach ($validator->getMessages() as $messageId => $message) {
|
||||
$form->cc->addError($this->view->translate('CC field must be a comma-separated list of valid E-mails'));
|
||||
return $this->_redirectFaultyForm($form);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$mail = self::getMail(
|
||||
$form->getValue('subject'),
|
||||
$this->_getParam('messageType'),
|
||||
$this->_getParam('messageType') == 'plain'?
|
||||
$form->getValue('bodyPlain')
|
||||
: $form->getValue('bodyHTML')
|
||||
);
|
||||
|
||||
$mail->setSubject($form->getValue('subject'));
|
||||
if ($this->_getParam('messageType') == 'plain') {
|
||||
$mail->setBodyText($form->getValue('bodyPlain'));
|
||||
} else {
|
||||
$mail->setBodyHtml($form->getValue('bodyHTML'));
|
||||
}
|
||||
|
||||
$users = new Users();
|
||||
foreach ($users->getUsers() as $user) {
|
||||
$mail->addTo($user->email);
|
||||
}
|
||||
|
||||
foreach ($ccArr as $cc) {
|
||||
$mail->addCC($cc);
|
||||
}
|
||||
|
||||
try {
|
||||
$mail->send();
|
||||
$this->_helper->FlashMessenger->addMessage('Message has been sent');
|
||||
} catch (Zend_Mail_Protocol_Exception $e) {
|
||||
$this->_helper->FlashMessenger->addMessage('There was an error trying to send the message');
|
||||
if ($this->_config->logging->level == Zend_Log::DEBUG) {
|
||||
$this->_helper->FlashMessenger->addMessage($e->getMessage());
|
||||
|
||||
return $this->_redirectFaultyForm($form);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_redirect('');
|
||||
}
|
||||
|
||||
private function _redirectFaultyForm(Zend_Form $form)
|
||||
{
|
||||
$appSession = Zend_Registry::get('appSession');
|
||||
$appSession->messageUsersForm = $form;
|
||||
|
||||
return $this->_forward('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Mail
|
||||
* @throws Zend_Mail_Protocol_Exception
|
||||
*/
|
||||
public static function getMail()
|
||||
{
|
||||
// can't use $this->_config 'cause we're in a static function
|
||||
$configEmail = Zend_Registry::get('config')->email;
|
||||
switch (strtolower($configEmail->transport)) {
|
||||
case 'smtp':
|
||||
Zend_Mail::setDefaultTransport(
|
||||
new Zend_Mail_Transport_Smtp(
|
||||
$configEmail->host,
|
||||
$configEmail->toArray()
|
||||
)
|
||||
);
|
||||
break;
|
||||
case 'mock':
|
||||
Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Mock());
|
||||
break;
|
||||
default:
|
||||
Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Sendmail());
|
||||
}
|
||||
|
||||
$mail = new Zend_Mail('UTF-8');
|
||||
$mail->setFrom('support@community-id.org');
|
||||
|
||||
return $mail;
|
||||
}
|
||||
}
|
||||
|
178
modules/default/controllers/OpenidController.php
Normal file
178
modules/default/controllers/OpenidController.php
Normal file
@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class OpenidController extends Monkeys_Controller_Action
|
||||
{
|
||||
public function providerAction()
|
||||
{
|
||||
if (isset($_POST['action']) && $_POST['action'] == 'proceed') {
|
||||
return $this->_proceed();
|
||||
} else {
|
||||
Zend_OpenId::$exitOnRedirect = false;
|
||||
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNeverRender(true);
|
||||
|
||||
$server = $this->_getOpenIdProvider();
|
||||
$response = new Zend_Controller_Response_Http();
|
||||
$ret = $server->handle(null, new Zend_OpenId_Extension_Sreg(), $response);
|
||||
Zend_Registry::get('logger')->log("RET: ".print_r($ret, true), Zend_Log::DEBUG);
|
||||
Zend_Registry::get('logger')->log("RESPONSE: ".print_r($response->getHeaders(), true), Zend_Log::DEBUG);
|
||||
if (is_string($ret)) {
|
||||
echo $ret;
|
||||
} else if ($ret !== true) {
|
||||
header('HTTP/1.0 403 Forbidden');
|
||||
Zend_Registry::get('logger')->log("OpenIdController::providerAction: FORBIDDEN", Zend_Log::DEBUG);
|
||||
echo 'Forbidden';
|
||||
} elseif ($ret === true
|
||||
// Zend_OpenId is messy and can change the type of the response I initially sent >:|
|
||||
&& is_a($response, 'Zend_Controller_Response_Http'))
|
||||
|
||||
{
|
||||
$headers = $response->getHeaders();
|
||||
if (isset($headers[0]['name']) && $headers[0]['name'] == 'Location'
|
||||
// redirection to the Trust page is not logged
|
||||
&& strpos($headers[0]['value'], '/openid/trust') === false
|
||||
&& strpos($headers[0]['value'], '/openid/login') === false)
|
||||
{
|
||||
if (strpos($headers[0]['value'], 'openid.mode=cancel') !== false) {
|
||||
$this->_saveHistory($server, History::DENIED);
|
||||
} else {
|
||||
$this->_saveHistory($server, History::AUTHORIZED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function loginAction()
|
||||
{
|
||||
$appSession = Zend_Registry::get('appSession');
|
||||
if (isset($appSession->openidLoginForm)) {
|
||||
$this->view->form = $appSession->openidLoginForm;
|
||||
unset($appSession->openidLoginForm);
|
||||
} else {
|
||||
$this->view->form = new OpenidLoginForm();
|
||||
}
|
||||
$this->view->form->openIdIdentity->setValue(htmlspecialchars($_GET['openid_identity']));
|
||||
|
||||
$this->view->queryString = $_SERVER['QUERY_STRING'];
|
||||
}
|
||||
|
||||
public function authenticateAction()
|
||||
{
|
||||
$form = new OpenidLoginForm();
|
||||
$formData = $this->_request->getPost();
|
||||
$form->populate($formData);
|
||||
|
||||
if (!$form->isValid($formData)) {
|
||||
$appSession = Zend_Registry::get('appSession');
|
||||
$appSession->openidLoginForm = $form;
|
||||
return $this->_forward('login', null, null);
|
||||
}
|
||||
|
||||
$server = $this->_getOpenIdProvider();
|
||||
$server->login($form->getValue('openIdIdentity'), $form->getValue('password'));
|
||||
|
||||
// needed for unit tests
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNeverRender(true);
|
||||
|
||||
Zend_OpenId::redirect($this->view->base . '/openid/provider', $_GET);
|
||||
}
|
||||
|
||||
public function trustAction()
|
||||
{
|
||||
$server = $this->_getOpenIdProvider();
|
||||
$this->view->siteRoot = $server->getSiteRoot($_GET);
|
||||
$this->view->identityUrl = $server->getLoggedInUser($_GET);
|
||||
$this->view->queryString = $_SERVER['QUERY_STRING'];
|
||||
|
||||
$sreg = new Zend_OpenId_Extension_Sreg();
|
||||
$sreg->parseRequest($_GET);
|
||||
|
||||
$this->view->fields = array();
|
||||
$this->view->policyUrl = false;
|
||||
|
||||
$props = $sreg->getProperties();
|
||||
if (is_array($props) && count($props) > 0) {
|
||||
$personalInfoForm = new PersonalInfoForm(null, $this->user, $props);
|
||||
$this->view->fields = $personalInfoForm->getElements();
|
||||
|
||||
$policy = $sreg->getPolicyUrl();
|
||||
if (!empty($policy)) {
|
||||
$this->view->policyUrl = $policy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function _proceed()
|
||||
{
|
||||
// needed for unit tests
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNeverRender(true);
|
||||
|
||||
$server = $this->_getOpenIdProvider();
|
||||
|
||||
$sreg = new Zend_OpenId_Extension_Sreg();
|
||||
$sreg->parseRequest($_GET);
|
||||
$props = $sreg->getProperties();
|
||||
|
||||
$personalInfoForm = new PersonalInfoForm(null, $this->user, $props);
|
||||
$formData = $this->_request->getPost();
|
||||
$personalInfoForm->populate($formData);
|
||||
|
||||
// not planning on validating stuff here yet, but I call this
|
||||
// for the date element to be filled properly
|
||||
$personalInfoForm->isValid($formData);
|
||||
|
||||
$sreg->parseResponse($personalInfoForm->getValues());
|
||||
if (isset($_POST['allow'])) {
|
||||
if (isset($_POST['forever'])) {
|
||||
$server->allowSite($server->getSiteRoot($_GET), $sreg);
|
||||
}
|
||||
unset($_GET['openid_action']);
|
||||
|
||||
$this->_saveHistory($server, History::AUTHORIZED);
|
||||
|
||||
$server->respondToConsumer($_GET, $sreg);
|
||||
} else if (isset($_POST['deny'])) {
|
||||
if (isset($_POST['forever'])) {
|
||||
$server->denySite($server->getSiteRoot($_GET));
|
||||
}
|
||||
|
||||
$this->_saveHistory($server, History::DENIED);
|
||||
|
||||
Zend_OpenId::redirect($_GET['openid_return_to'], array('openid.mode'=>'cancel'));
|
||||
}
|
||||
}
|
||||
private function _saveHistory(Zend_OpenId_Provider $server, $result)
|
||||
{
|
||||
$histories = new Histories();
|
||||
$history = $histories->createRow();
|
||||
$history->user_id = $this->user->id;
|
||||
$history->date = date('Y-m-d H:i:s');
|
||||
$history->site = $server->getSiteRoot($_GET);
|
||||
$history->ip = $_SERVER['REMOTE_ADDR'];
|
||||
$history->result = $result;
|
||||
$history->save();
|
||||
}
|
||||
|
||||
private function _getOpenIdProvider()
|
||||
{
|
||||
$server = new Zend_OpenId_Provider($this->view->base . '/openid/login',
|
||||
$this->view->base . '/openid/trust',
|
||||
new OpenIdUser(),
|
||||
new Monkeys_OpenId_Provider_Storage_Database());
|
||||
|
||||
return $server;
|
||||
}
|
||||
}
|
32
modules/default/controllers/PrivacyController.php
Normal file
32
modules/default/controllers/PrivacyController.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class PrivacyController extends Monkeys_Controller_Action
|
||||
{
|
||||
protected $_numCols = 1;
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$locale = Zend_Registry::get('Zend_Locale');
|
||||
$localeElements = explode('_', $locale);
|
||||
|
||||
if (file_exists(APP_DIR . "/resources/$locale/privacy.txt")) {
|
||||
$file = APP_DIR . "/resources/$locale/privacy.txt";
|
||||
} else if (count($localeElements == 2)
|
||||
&& file_exists(APP_DIR . "/resources/".$localeElements[0]."/privacy.txt")) {
|
||||
$file = APP_DIR . "/resources/".$localeElements[0]."/privacy.txt";
|
||||
} else {
|
||||
$file = APP_DIR . "/resources/en/privacy.txt";
|
||||
}
|
||||
|
||||
$this->view->privacyPolicy = nl2br(file_get_contents($file));
|
||||
}
|
||||
}
|
121
modules/default/controllers/SitesController.php
Normal file
121
modules/default/controllers/SitesController.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class SitesController extends Monkeys_Controller_Action
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$this->_helper->actionStack('index', 'login', 'users');
|
||||
}
|
||||
|
||||
public function listAction()
|
||||
{
|
||||
$this->_helper->viewRenderer->setNeverRender(true);
|
||||
|
||||
$fields = new Fields();
|
||||
$sites = new Sites();
|
||||
$sitesRows = $sites->get(
|
||||
$this->user,
|
||||
$this->_getParam('startIndex'),
|
||||
$this->_getParam('results')
|
||||
);
|
||||
|
||||
$jsonObj = new StdClass();
|
||||
$jsonObj->recordsReturned = count($sitesRows);
|
||||
$jsonObj->totalRecords = $sites->getNumSites($this->user);
|
||||
$jsonObj->startIndex = $this->_getParam('startIndex');
|
||||
$jsonObj->sort = null;
|
||||
$jsonObj->dir = 'asc';
|
||||
$jsonObj->records = array();
|
||||
|
||||
foreach ($sitesRows as $site) {
|
||||
$jsonObjSite = new StdClass();
|
||||
$jsonObjSite->id = $site->id;
|
||||
$jsonObjSite->site = $site->site;
|
||||
|
||||
$trusted = unserialize($site->trusted);
|
||||
$jsonObjSite->trusted = (is_bool($trusted) && $trusted) || is_array($trusted);
|
||||
|
||||
if (is_array($trusted)
|
||||
&& isset($trusted['Zend_OpenId_Extension_Sreg'])
|
||||
&& count($trusted['Zend_OpenId_Extension_Sreg']) > 0)
|
||||
{
|
||||
$translatedTrusted = array();
|
||||
foreach ($trusted['Zend_OpenId_Extension_Sreg'] as $identifier => $value) {
|
||||
$translatedTrusted[$this->view->translate($fields->getFieldName($identifier))] = $value;
|
||||
}
|
||||
$jsonObjSite->infoExchanged = $translatedTrusted;
|
||||
} else {
|
||||
$jsonObjSite->infoExchanged = false;
|
||||
}
|
||||
|
||||
$jsonObj->records[] = $jsonObjSite;
|
||||
}
|
||||
|
||||
echo Zend_Json::encode($jsonObj);
|
||||
}
|
||||
|
||||
public function denyAction()
|
||||
{
|
||||
$this->_helper->viewRenderer->setNeverRender(true);
|
||||
|
||||
$sites = new Sites();
|
||||
$site = $sites->getRowInstance($this->_getParam('id'));
|
||||
if ($site->user_id != $this->user->id) {
|
||||
throw new Monkeys_AccessDeniedException();
|
||||
}
|
||||
|
||||
$site->trusted = serialize(false);
|
||||
$site->save();
|
||||
|
||||
$json = new StdClass();
|
||||
$json->code = 200;
|
||||
|
||||
echo Zend_Json::encode($json);
|
||||
}
|
||||
|
||||
public function allowAction()
|
||||
{
|
||||
$this->_helper->viewRenderer->setNeverRender(true);
|
||||
|
||||
$sites = new Sites();
|
||||
$site = $sites->getRowInstance($this->_getParam('id'));
|
||||
if ($site->user_id != $this->user->id) {
|
||||
throw new Monkeys_AccessDeniedException();
|
||||
}
|
||||
|
||||
$site->trusted = serialize(true);
|
||||
$site->save();
|
||||
|
||||
$json = new StdClass();
|
||||
$json->code = 200;
|
||||
|
||||
echo Zend_Json::encode($json);
|
||||
}
|
||||
|
||||
public function deleteAction()
|
||||
{
|
||||
$this->_helper->viewRenderer->setNeverRender(true);
|
||||
|
||||
$sites = new Sites();
|
||||
$site = $sites->getRowInstance($this->_getParam('id'));
|
||||
if ($site->user_id != $this->user->id) {
|
||||
throw new Monkeys_AccessDeniedException();
|
||||
}
|
||||
|
||||
$site->delete();
|
||||
|
||||
$json = new StdClass();
|
||||
$json->code = 200;
|
||||
|
||||
echo Zend_Json::encode($json);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user