Skip to content

Commit

Permalink
Dev WIP Auth plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Feb 5, 2015
1 parent 9147018 commit 714afd3
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 1,026 deletions.
2 changes: 2 additions & 0 deletions application/config/internal.php
Expand Up @@ -14,6 +14,8 @@
@date_default_timezone_set(@date_default_timezone_get());
$internalConfig = array(
'basePath' => __DIR__ . '/../',

'theme' => 'default',
'runtimePath' => dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'runtime',
'name' => 'LimeSurvey',
'defaultController' => 'surveys',
Expand Down
17 changes: 17 additions & 0 deletions application/controllers/DevController.php
@@ -0,0 +1,17 @@
<?php

class DevController extends CController {

public function actionIndex() {
$result = "";
$dir = __DIR__ . '/../../plugins';

$result .= print_r(App()->pluginManager->scanPlugins(), true);

// $plugins = \ls\pluginmanager\PluginConfig::findAll(true);

// App()->pluginManager->subscribe("test", function($event) { var_dump($event); });

$this->renderText('<pre>' . $result . '</pre>');
}
}
22 changes: 11 additions & 11 deletions application/controllers/PluginsController.php
Expand Up @@ -9,17 +9,17 @@ class PluginsController extends LSYii_Controller
* Stored dynamic properties set and unset via __get and __set.
* @var array of mixed.
*/
protected $properties = array();

public function __get($property)
{
return $this->properties[$property];
}

public function __set($property, $value)
{
$this->properties[$property] = $value;
}
// protected $properties = array();
//
// public function __get($property)
// {
// return $this->properties[$property];
// }
//
// public function __set($property, $value)
// {
// $this->properties[$property] = $value;
// }

public function _init()
{
Expand Down
29 changes: 29 additions & 0 deletions application/controllers/UsersController.php
@@ -0,0 +1,29 @@
<?php
use ls\pluginmanager\PluginEvent;
class UsersController extends LSYii_Controller
{

public $layout = 'minimal';


public function accessRules()
{
// Note the order; rules are numerically indexed and we want to
// parents rules to be executed only if ours dont apply.
return array_merge([
['allow' ,'actions' => 'login'],
['allow' , 'actions' => 'logout', 'users' => '@'],
], parent::accessRules());
}

public function actionLogin() {
// Get all active auth plugins.
$event = new PluginEvent('newLoginForm');
$event->dispatch();
$loginForms = $event->get('forms');
return $this->render('login', ['loginForms' => $loginForms]);
}

}

?>
2 changes: 1 addition & 1 deletion application/core/LSWebUser.php
@@ -1,5 +1,5 @@
<?php
Yii::import('application.helpers.Hash', true);
use Cake\Utility\Hash;

class LSWebUser extends CWebUser
{
Expand Down
9 changes: 9 additions & 0 deletions application/core/plugins/Authdb/AuthDb.php
Expand Up @@ -48,6 +48,13 @@ protected function getOnePass()

public function eventNewLoginForm(PluginEvent $event)
{
$event->set('forms.' . $this->name, [
'serverkey' => array(
'type' => 'string',
'label' => 'Key to use for username e.g. PHP_AUTH_USER, LOGON_USER, REMOTE_USER. See phpinfo in global settings.',
'default' => 'REMOTE_USER',
) ]);
return;
$sUserName='';
$sPassword='';
if (Yii::app()->getConfig("demoMode") === true && Yii::app()->getConfig("demoModePrefill") === true)
Expand All @@ -63,6 +70,8 @@ public function eventNewLoginForm(PluginEvent $event)

public function eventNewUserSession(PluginEvent $event)
{


// Do nothing if this user is not Authdb type
$identity = $event->get('identity');
if ($identity->plugin != __CLASS__) {
Expand Down
14 changes: 12 additions & 2 deletions application/core/plugins/Authwebserver/AuthWebServer.php
Expand Up @@ -29,6 +29,16 @@ public function init()
{
}

public function eventNewLoginForm(PluginEvent $event)
{
$event->set('forms.' . $this->name, [
'serverkey' => array(
'type' => 'string',
'label' => 'Key to use for username e.g. PHP_AUTH_USER, LOGON_USER, REMOTE_USER. See phpinfo in global settings.',
'default' => 'REMOTE_USER',
) ]);
return;
}
public function eventBeforeLogin(PluginEvent $event)
{
// normal login through webserver authentication
Expand Down Expand Up @@ -66,10 +76,10 @@ public function eventBeforeLogin(PluginEvent $event)
}
}

public function eventNewUserSession()
public function eventNewUserSession(PluginEvent $event)
{
// Do nothing if this user is not Authwebserver type
$identity = $this->getEvent()->get('identity');
$identity = $event->get('identity');
if ($identity->plugin != 'Authwebserver')
{
return;
Expand Down
3 changes: 2 additions & 1 deletion application/core/plugins/Authwebserver/limesurvey.json
Expand Up @@ -11,7 +11,8 @@
},
"events" : [
"beforeLogin",
"newUserSession"
"newUserSession",
"newLoginForm"
],
"apiVersion" : "1.0"
}

0 comments on commit 714afd3

Please sign in to comment.