Be able to disable the login form for specific users

This commit is contained in:
Frederic Guillot 2015-02-07 23:28:17 -05:00
parent 607d9dc794
commit 00b9508d81
25 changed files with 148 additions and 69 deletions

View File

@ -30,9 +30,14 @@ class Database extends Base
*/
public function authenticate($username, $password)
{
$user = $this->db->table(User::TABLE)->eq('username', $username)->eq('is_ldap_user', 0)->findOne();
$user = $this->db
->table(User::TABLE)
->eq('username', $username)
->eq('disable_login_form', 0)
->eq('is_ldap_user', 0)
->findOne();
if ($user && password_verify($password, $user['password'])) {
if (is_array($user) && password_verify($password, $user['password'])) {
$this->userSession->refresh($user);
$this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id']));
return true;

View File

@ -66,6 +66,7 @@ class ReverseProxy extends Base
'username' => $login,
'is_admin' => REVERSE_PROXY_DEFAULT_ADMIN === $login,
'is_ldap_user' => 1,
'disable_login_form' => 1,
));
}
}

View File

@ -341,7 +341,7 @@ class User extends Base
if ($this->request->isPost()) {
$values = $this->request->getValues();
$values = $this->request->getValues() + array('disable_login_form' => 0);
if ($this->userSession->isAdmin()) {
$values += array('is_admin' => 0);

View File

@ -713,4 +713,5 @@ return array(
// 'Show/hide projects' => '',
// 'Show/hide subtasks' => '',
// 'Show/hide tasks' => '',
// 'Disable login form' => '',
);

View File

@ -713,4 +713,5 @@ return array(
// 'Show/hide projects' => '',
// 'Show/hide subtasks' => '',
// 'Show/hide tasks' => '',
// 'Disable login form' => '',
);

View File

@ -713,4 +713,5 @@ return array(
// 'Show/hide projects' => '',
// 'Show/hide subtasks' => '',
// 'Show/hide tasks' => '',
// 'Disable login form' => '',
);

View File

@ -713,4 +713,5 @@ return array(
// 'Show/hide projects' => '',
// 'Show/hide subtasks' => '',
// 'Show/hide tasks' => '',
// 'Disable login form' => '',
);

View File

@ -715,4 +715,5 @@ return array(
'Show/hide projects' => 'Afficher/cacher les projets',
'Show/hide subtasks' => 'Afficher/cacher les sous-tâches',
'Show/hide tasks' => 'Afficher/cacher les tâches',
'Disable login form' => 'Désactiver le formulaire d\'authentification',
);

View File

@ -713,4 +713,5 @@ return array(
// 'Show/hide projects' => '',
// 'Show/hide subtasks' => '',
// 'Show/hide tasks' => '',
// 'Disable login form' => '',
);

View File

@ -713,4 +713,5 @@ return array(
// 'Show/hide projects' => '',
// 'Show/hide subtasks' => '',
// 'Show/hide tasks' => '',
// 'Disable login form' => '',
);

View File

@ -713,4 +713,5 @@ return array(
// 'Show/hide projects' => '',
// 'Show/hide subtasks' => '',
// 'Show/hide tasks' => '',
// 'Disable login form' => '',
);

View File

@ -713,4 +713,5 @@ return array(
// 'Show/hide projects' => '',
// 'Show/hide subtasks' => '',
// 'Show/hide tasks' => '',
// 'Disable login form' => '',
);

View File

@ -713,4 +713,5 @@ return array(
// 'Show/hide projects' => '',
// 'Show/hide subtasks' => '',
// 'Show/hide tasks' => '',
// 'Disable login form' => '',
);

View File

@ -713,4 +713,5 @@ return array(
// 'Show/hide projects' => '',
// 'Show/hide subtasks' => '',
// 'Show/hide tasks' => '',
// 'Disable login form' => '',
);

View File

@ -713,4 +713,5 @@ return array(
// 'Show/hide projects' => '',
// 'Show/hide subtasks' => '',
// 'Show/hide tasks' => '',
// 'Disable login form' => '',
);

View File

@ -713,4 +713,5 @@ return array(
// 'Show/hide projects' => '',
// 'Show/hide subtasks' => '',
// 'Show/hide tasks' => '',
// 'Disable login form' => '',
);

View File

@ -713,4 +713,5 @@ return array(
// 'Show/hide projects' => '',
// 'Show/hide subtasks' => '',
// 'Show/hide tasks' => '',
// 'Disable login form' => '',
);

View File

@ -5,7 +5,12 @@ namespace Schema;
use PDO;
use Core\Security;
const VERSION = 43;
const VERSION = 44;
function version_44($pdo)
{
$pdo->exec('ALTER TABLE users ADD COLUMN disable_login_form TINYINT(1) DEFAULT 0');
}
function version_43($pdo)
{

View File

@ -5,7 +5,12 @@ namespace Schema;
use PDO;
use Core\Security;
const VERSION = 24;
const VERSION = 25;
function version_25($pdo)
{
$pdo->exec("ALTER TABLE users ADD COLUMN disable_login_form BOOLEAN DEFAULT '1'");
}
function version_24($pdo)
{
@ -13,17 +18,17 @@ function version_24($pdo)
$rq->execute(array('subtask_restriction', '0'));
$rq->execute(array('subtask_time_tracking', '0'));
$pdo->exec("
$pdo->exec('
CREATE TABLE subtask_time_tracking (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL,
subtask_id INTEGER NOT NULL,
start INTEGER DEFAULT 0,
end INTEGER DEFAULT 0,
"user_id" INTEGER NOT NULL,
"subtask_id" INTEGER NOT NULL,
"start" INTEGER DEFAULT 0,
"end" INTEGER DEFAULT 0,
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY(subtask_id) REFERENCES task_has_subtasks(id) ON DELETE CASCADE
)
");
');
}
function version_23($pdo)

View File

@ -5,7 +5,12 @@ namespace Schema;
use Core\Security;
use PDO;
const VERSION = 42;
const VERSION = 43;
function version_43($pdo)
{
$pdo->exec('ALTER TABLE users ADD COLUMN disable_login_form INTEGER DEFAULT 0');
}
function version_42($pdo)
{

View File

@ -26,9 +26,13 @@
<?= $this->formLabel(t('Language'), 'language') ?>
<?= $this->formSelect('language', $languages, $values, $errors) ?><br/>
<?php if ($this->userSession->isAdmin()): ?>
<?= $this->formCheckbox('is_admin', t('Administrator'), 1, isset($values['is_admin']) && $values['is_admin'] == 1 ? true : false) ?><br/>
<?php endif ?>
<div class="alert alert-error">
<?= $this->formCheckbox('disable_login_form', t('Disable login form'), 1, isset($values['disable_login_form']) && $values['disable_login_form'] == 1) ?><br/>
<?php if ($this->userSession->isAdmin()): ?>
<?= $this->formCheckbox('is_admin', t('Administrator'), 1, isset($values['is_admin']) && $values['is_admin'] == 1) ?><br/>
<?php endif ?>
</div>
<div class="form-actions">
<input type="submit" value="<?= t('Save') ?>" class="btn btn-blue"/>

View File

@ -4,7 +4,7 @@
"fguillot/simple-validator": "0.0.1",
"swiftmailer/swiftmailer": "@stable",
"fguillot/json-rpc": "0.0.1",
"fguillot/picodb": "0.0.2",
"fguillot/picodb": "dev-master",
"erusev/parsedown": "1.5.1",
"lusitanian/oauth": "0.3.5",
"pimple/pimple": "~3.0",

27
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "671bd4694072aed17a542db8f08db217",
"hash": "fdd9fc2aa1f8bdbc3e21d06ff0c7b184",
"packages": [
{
"name": "erusev/parsedown",
@ -84,7 +84,7 @@
},
{
"name": "fguillot/picodb",
"version": "v0.0.2",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/fguillot/picoDb.git",
@ -393,17 +393,17 @@
},
{
"name": "symfony/console",
"version": "v2.6.3",
"version": "v2.6.4",
"target-dir": "Symfony/Component/Console",
"source": {
"type": "git",
"url": "https://github.com/symfony/Console.git",
"reference": "6ac6491ff60c0e5a941db3ccdc75a07adbb61476"
"reference": "e44154bfe3e41e8267d7a3794cd9da9a51cfac34"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Console/zipball/6ac6491ff60c0e5a941db3ccdc75a07adbb61476",
"reference": "6ac6491ff60c0e5a941db3ccdc75a07adbb61476",
"url": "https://api.github.com/repos/symfony/Console/zipball/e44154bfe3e41e8267d7a3794cd9da9a51cfac34",
"reference": "e44154bfe3e41e8267d7a3794cd9da9a51cfac34",
"shasum": ""
},
"require": {
@ -446,21 +446,21 @@
],
"description": "Symfony Console Component",
"homepage": "http://symfony.com",
"time": "2015-01-06 17:50:02"
"time": "2015-01-25 04:39:26"
},
{
"name": "symfony/event-dispatcher",
"version": "v2.6.3",
"version": "v2.6.4",
"target-dir": "Symfony/Component/EventDispatcher",
"source": {
"type": "git",
"url": "https://github.com/symfony/EventDispatcher.git",
"reference": "40ff70cadea3785d83cac1c8309514b36113064e"
"reference": "f75989f3ab2743a82fe0b03ded2598a2b1546813"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/40ff70cadea3785d83cac1c8309514b36113064e",
"reference": "40ff70cadea3785d83cac1c8309514b36113064e",
"url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/f75989f3ab2743a82fe0b03ded2598a2b1546813",
"reference": "f75989f3ab2743a82fe0b03ded2598a2b1546813",
"shasum": ""
},
"require": {
@ -504,13 +504,13 @@
],
"description": "Symfony EventDispatcher Component",
"homepage": "http://symfony.com",
"time": "2015-01-05 14:28:40"
"time": "2015-02-01 16:10:57"
}
],
"packages-dev": [
{
"name": "symfony/stopwatch",
"version": "v2.6.3",
"version": "v2.6.4",
"target-dir": "Symfony/Component/Stopwatch",
"source": {
"type": "git",
@ -560,6 +560,7 @@
"minimum-stability": "stable",
"stability-flags": {
"swiftmailer/swiftmailer": 0,
"fguillot/picodb": 20,
"symfony/console": 0
},
"prefer-stable": false,

View File

@ -229,13 +229,13 @@ class ProjectDuplicationTest extends Base
$this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
$this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
$this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {});
$this->container['dispatcher']->addListener(Task::EVENT_CREATE, function() {});
$this->assertEquals(2, $pd->duplicate(1, array('category', 'action', 'swimlane', 'task')));
$this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'swimlane', 'task')));
$project = $p->getByName('P1 (Clone)');
$this->assertNotFalse($project);
$project_id = $project['id'];
// Check if Swimlanes have been duplicated
$swimlanes = $s->getAll(2);
$swimlanes = $s->getAll($project_id);
$this->assertCount(3, $swimlanes);
$this->assertEquals(4, $swimlanes[0]['id']);
@ -244,37 +244,59 @@ class ProjectDuplicationTest extends Base
$this->assertEquals('S2', $swimlanes[1]['name']);
$this->assertEquals(6, $swimlanes[2]['id']);
$this->assertEquals('S3', $swimlanes[2]['name']);
$new_default = $s->getDefault(2);
$new_default = $s->getDefault($project_id);
$this->assertEquals('New Default', $new_default['default_swimlane']);
// Check if Tasks have been duplicated
$tasks = $tf->getAll(2);
$tasks = $tf->getAll($project_id);
$this->assertCount(3, $tasks);
$this->assertEquals(4, $tasks[0]['id']);
// $this->assertEquals(4, $tasks[0]['id']);
$this->assertEquals('T1', $tasks[0]['title']);
$this->assertEquals(5, $tasks[1]['id']);
// $this->assertEquals(5, $tasks[1]['id']);
$this->assertEquals('T2', $tasks[1]['title']);
$this->assertEquals(6, $tasks[2]['id']);
// $this->assertEquals(6, $tasks[2]['id']);
$this->assertEquals('T3', $tasks[2]['title']);
// Drop project
unset($tasks);
unset($swimlanes);
unset($new_default);
$p->remove($project_id);
$p->remove(2);
$this->assertFalse($p->exists($project_id));
$this->assertCount(0, $s->getAll($project_id));
$this->assertCount(0, $tf->getAll($project_id));
}
$this->assertFalse($p->exists(2));
$this->assertCount(0, $s->getAll(2));
$this->assertCount(0, $tf->getAll(2));
public function testCloneProjectWithSwimlanes()
{
$p = new Project($this->container);
$pd = new ProjectDuplication($this->container);
$s = new Swimlane($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
// Check duplication with Swimlanes only
$this->assertEquals(2, $pd->duplicate(1, array('category', 'action', 'swimlane')));
$this->assertEquals(1, $p->create(array('name' => 'P1')));
// Check if Swimlanes have been duplicated
$swimlanes = $s->getAll(2);
// create initial swimlanes
$this->assertEquals(1, $s->create(1, 'S1'));
$this->assertEquals(2, $s->create(1, 'S2'));
$this->assertEquals(3, $s->create(1, 'S3'));
$default_swimlane1 = $s->getDefault(1);
$default_swimlane1['default_swimlane'] = 'New Default';
$this->assertTrue($s->updateDefault($default_swimlane1));
//create initial tasks
$this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
$this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
$this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
$this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'swimlane')));
$project = $p->getByName('P1 (Clone)');
$this->assertNotFalse($project);
$project_id = $project['id'];
$swimlanes = $s->getAll($project_id);
$this->assertCount(3, $swimlanes);
$this->assertEquals(4, $swimlanes[0]['id']);
@ -283,38 +305,55 @@ class ProjectDuplicationTest extends Base
$this->assertEquals('S2', $swimlanes[1]['name']);
$this->assertEquals(6, $swimlanes[2]['id']);
$this->assertEquals('S3', $swimlanes[2]['name']);
$new_default = $s->getDefault(2);
$new_default = $s->getDefault($project_id);
$this->assertEquals('New Default', $new_default['default_swimlane']);
// Check if Tasks have NOT been duplicated
$this->assertCount(0, $tf->getAll(2));
$this->assertCount(0, $tf->getAll($project_id));
}
// Drop project
unset($tasks);
unset($swimlanes);
unset($new_default);
public function testCloneProjectWithTasks()
{
$p = new Project($this->container);
$pd = new ProjectDuplication($this->container);
$s = new Swimlane($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$p->remove(2);
$this->assertEquals(1, $p->create(array('name' => 'P1')));
$this->assertFalse($p->exists(2));
$this->assertCount(0, $s->getAll(2));
$this->assertCount(0, $tf->getAll(2));
// create initial swimlanes
$this->assertEquals(1, $s->create(1, 'S1'));
$this->assertEquals(2, $s->create(1, 'S2'));
$this->assertEquals(3, $s->create(1, 'S3'));
// Check duplication with Tasks only
$this->assertEquals(2, $pd->duplicate(1, array('category', 'action', 'task')));
$default_swimlane1 = $s->getDefault(1);
$default_swimlane1['default_swimlane'] = 'New Default';
$this->assertTrue($s->updateDefault($default_swimlane1));
//create initial tasks
$this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
$this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
$this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
$this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'task')));
$project = $p->getByName('P1 (Clone)');
$this->assertNotFalse($project);
$project_id = $project['id'];
// Check if Swimlanes have NOT been duplicated
$this->assertCount(0, $s->getAll(2));
$this->assertCount(0, $s->getAll($project_id));
// Check if Tasks have been duplicated
$tasks = $tf->getAll(2);
$tasks = $tf->getAll($project_id);
$this->assertCount(3, $tasks);
$this->assertEquals(4, $tasks[0]['id']);
//$this->assertEquals(4, $tasks[0]['id']);
$this->assertEquals('T1', $tasks[0]['title']);
$this->assertEquals(5, $tasks[1]['id']);
//$this->assertEquals(5, $tasks[1]['id']);
$this->assertEquals('T2', $tasks[1]['title']);
$this->assertEquals(6, $tasks[2]['id']);
//$this->assertEquals(6, $tasks[2]['id']);
$this->assertEquals('T3', $tasks[2]['title']);
}
}

View File

@ -97,7 +97,7 @@ class ProjectTest extends Base
$project = $p->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals($now, $project['last_modified']);
$this->assertEquals($now, $project['last_modified'], 'Wrong Timestamp', 1);
sleep(1);
$this->assertTrue($p->updateModificationDate(1));