Various changes WIP

This commit is contained in:
kiswa 2016-05-22 11:07:16 +00:00
parent 464f664edd
commit 37690ee5af
7 changed files with 103 additions and 61 deletions

View File

@ -19,5 +19,6 @@
],
"autoload": {
"classmap": [ "controllers", "models" ]
}
},
"minimum-stability": "stable"
}

View File

@ -3,17 +3,18 @@ use RedBeanPHP\R;
use Firebase\JWT;
class Auth extends BaseController {
public function authenticate($request, $response, $args) {
if (!$request->hasHeader('Authorization') {
$apiJson = new ApiJson();
public function authenticate($request, $response, $args) {
if (!$request->hasHeader('Authorization')) {
return $response->withStatus(400); // Bad Request
}
$jwt = $response->getHeader('Authorization');
$jwt = $request->getHeader('Authorization');
// Validate token
// Issue new token with extended expiration
return $response->withJson(json_encode($jwt));
}
public function login($request, $response, $args) {
@ -26,7 +27,7 @@ class Auth extends BaseController {
return $this->jsonResponse($response);
}
if ($user->password !== $this->hashPassword($data->password, $user->salt) {
if (!password_verify($data->password, $user->password_hash)) {
$this->apiJson->addAlert('error', 'Invalid username or password.');
return $this->jsonResponse($response);
@ -43,16 +44,15 @@ class Auth extends BaseController {
$key = R::load('jwt', 1);
if ($key->id === 0) {
// Generate a JWT key by hashing the current time.
// This should make (effectively) every instance of TaskBoard
// have a unique secret key for JWTs.
$key->token = password_hash(strval(time()), PASSWORD_BCRYPT);
R::store($key);
}
return $key->token;
}
private function hashPassword($password, $salt) {
return password_hash($data->password, PASSWORD_BCRYPT,
array('salt' => $salt));
}
}

View File

@ -11,7 +11,6 @@ class User extends BaseModel {
public $id = 0;
public $security_level;
public $username = '';
public $salt = '';
public $password_hash = '';
public $email = '';
public $default_board_id = 0;
@ -32,7 +31,6 @@ class User extends BaseModel {
$bean->id = $this->id;
$bean->security_level = $this->security_level->getValue();
$bean->username = $this->username;
$bean->salt = $this->salt;
$bean->password_hash = $this->password_hash;
$bean->email = $this->email;
$bean->default_board_id = $this->default_board_id;
@ -73,7 +71,6 @@ class User extends BaseModel {
$this->id = (int) $obj->id;
$this->security_level = new SecurityLevel((int) $obj->security_level);
$this->username = $obj->username;
$this->salt = $obj->salt;
$this->password_hash = $obj->password_hash;
$this->email = $obj->email;
$this->default_board_id = (int) $obj->default_board_id;

View File

@ -18,12 +18,13 @@
<button>Change Password</button>
<button class="flat">Reset</button>
<h3 class="tall">Select Default Board</h3>
<select>
<option>None</option>
</select>
<h3>All Boards Options</h3>
<h3 class="tall">All Boards Options</h3>
<label>
Select default board:
<select class="autosize">
<option>None</option>
</select>
</label>
<label>
New tasks appear at column
<select class="autosize">
@ -95,8 +96,8 @@
<td>User</td>
<td>None</td>
<td>
<a href="">Edit</a>
<a href="">Remove</a>
<a href=""><i class="icon icon-edit"></i></a>
<a href=""><i class="icon icon-trash-empty"></i></a>
</td>
</tr>
<tr>
@ -105,8 +106,8 @@
<td>Board Administrator</td>
<td>None</td>
<td>
<a href="">Edit</a>
<a href="">Remove</a>
<a href=""><i class="icon icon-edit"></i></a>
<a href=""><i class="icon icon-trash-empty"></i></a>
</td>
</tr>
</tbody>
@ -124,28 +125,30 @@
<div class="row">
<h3>Current Boards</h3>
<label class="inline">
Sort By:
<select class="autosize">
<option>Board Name</option>
<option>Creation Date</option>
</select>
</label>
<label class="inline">
Filter By:
<select class="autosize">
<option>All Boards</option>
<option>Active</option>
<option>Inactive</option>
</select>
</label>
<label class="inline">
Show By User:
<select class="autosize">
<option>Any User</option>
<option>admin</option>
</select>
</label>
<div class="small right">
<label class="inline">
Sort By:
<select class="autosize">
<option>Board Name</option>
<option>Creation Date</option>
</select>
</label>
<label class="inline">
Filter By:
<select class="autosize">
<option>All Boards</option>
<option>Active</option>
<option>Inactive</option>
</select>
</label>
<label class="inline">
Show By User:
<select class="autosize">
<option>Any User</option>
<option>admin</option>
</select>
</label>
</div>
<table class="alternating">
<thead>
@ -169,25 +172,30 @@
</td>
<td>
<ul>
<li>Cat1</li>
<li>Cat2</li>
<li>Cat3</li>
<li>Cat1<span class="badge" title="Default Color" style="background-color:#debee8">&nbsp;</span></li>
<li>Cat2<span class="badge" title="Default Color" style="background-color:#bee7f4">&nbsp;</span></li>
<li>Cat3<span class="badge" title="Default Color" style="background-color:#ffffe0">&nbsp;</span></li>
</ul>
</td>
<td>
<ul>
<li>admin</li>
<li>other_guy</li>
</ul>
</td>
<td>
<a href="">Edit</a>
<a href="">Remove</a>
<a href=""><i class="icon icon-edit"></i></a>
<a href=""><i class="icon icon-trash-empty"></i></a>
<label><input type="checkbox" checked> Active</label>
</td>
</tr>
<tr>
<td><a href="boards/2">Other Board</a></td>
<td></td>
<td>
<ul>
<li>One<span class="badge">0</span></li>
</ul>
</td>
<td></td>
<td>
<ul>
@ -195,8 +203,8 @@
</ul>
</td>
<td>
<a href="">Edit</a>
<a href="">Remove</a>
<a href=""><i class="icon icon-edit"></i></a>
<a href=""><i class="icon icon-trash-empty"></i></a>
<label><input type="checkbox" checked> Active</label>
</td>
</tr>
@ -218,7 +226,7 @@
<tr>
<th>Board</th>
<th>Trigger</th>
<th>Actions</th>
<th>Action</th>
<th>Remove</th>
</tr>
</thead>
@ -227,13 +235,13 @@
<td>Example Board</td>
<td>Item assigned to user: admin</td>
<td>Set item color: #debee8</td>
<td><a href="#">Remove</a></td>
<td><a href="#"><i class="icon icon-trash-empty"></i></a></td>
</tr>
<tr>
<td>Example Board</td>
<td>Item moved to column: Col3</td>
<td>Set item color: #debee8</td>
<td><a href="#">Remove</a></td>
<td><a href="#"><i class="icon icon-trash-empty"></i></a></td>
</tr>
</tbody>
</table>

View File

@ -58,7 +58,6 @@ class DataMock {
$user->id = 1;
$user->security_level = SecurityLevel::BoardAdmin;
$user->username = 'tester';
$user->salt = 'salty1234';
$user->password_hash = 'hashpass1234';
$user->email = 'user@example.com';
$user->default_board_id = 1;
@ -162,6 +161,7 @@ class ContainerMock {
class RequestMock {
public $invalidPayload = false;
public $payload = null;
public $hasHeader = true;
public function getBody() {
if ($this->invalidPayload) {
@ -174,6 +174,10 @@ class RequestMock {
return json_encode(DataMock::getBoard());
}
public function hasHeader() {
return $this->hasHeader;
}
}
class ResponseMock {
@ -182,5 +186,9 @@ class ResponseMock {
return $apiJson;
}
public function withStatus($status) {
return $status;
}
}

View File

@ -0,0 +1,31 @@
<?php
class AuthTest extends PHPUnit_Framework_TestCase {
private $auth;
public static function setupBeforeClass() {
try {
RedBeanPHP\R::setup('sqlite:tests.db');
} catch (Exception $ex) { }
}
public function setUp() {
RedBeanPHP\R::nuke();
$this->auth = new Auth(new ContainerMock());
}
/**
* @group single
*/
public function testAuthenticate() {
$request = new RequestMock();
$request->hasHeader = false;
$actual = $this->auth->authenticate($request,
new ResponseMock(), null);
$this->assertTrue($actual === 400);
}
}

View File

@ -62,7 +62,6 @@ class UserTest extends PHPUnit_Framework_TestCase {
$this->assertTrue($bean->security_level ===
$user->security_level->getValue());
$this->assertTrue($bean->username === $user->username);
$this->assertTrue($bean->salt === $user->salt);
$this->assertTrue($bean->password_hash === $user->password_hash);
$this->assertTrue($bean->email === $user->email);
$this->assertTrue($bean->default_board_id === $user->default_board_id);
@ -74,7 +73,6 @@ class UserTest extends PHPUnit_Framework_TestCase {
$this->assertTrue($user->security_level->getValue() ===
SecurityLevel::User);
$this->assertTrue($user->username === '');
$this->assertTrue($user->salt === '');
$this->assertTrue($user->password_hash === '');
$this->assertTrue($user->email === '');
$this->assertTrue($user->default_board_id === 0);
@ -86,7 +84,6 @@ class UserTest extends PHPUnit_Framework_TestCase {
$this->assertTrue($user->security_level->getValue() ===
SecurityLevel::BoardAdmin);
$this->assertTrue($user->username === 'tester');
$this->assertTrue($user->salt === 'salty1234');
$this->assertTrue($user->password_hash === 'hashpass1234');
$this->assertTrue($user->email === 'user@example.com');
$this->assertTrue($user->default_board_id === 1);