[Ivan Diaz] - OS-#39 - Add User/Ticket/Comment classes
This commit is contained in:
parent
e472984c0f
commit
953aa52584
|
@ -19,7 +19,7 @@ class SignUpController extends Controller {
|
|||
$userInstance = new User();
|
||||
$userInstance->setProperties(array(
|
||||
'email' => $email,
|
||||
'password' => User::hashPassword($password)
|
||||
'password' => Hashing::hashPassword($password)
|
||||
));
|
||||
|
||||
return $userInstance->store();
|
||||
|
|
|
@ -10,6 +10,11 @@ RedBean::setup('mysql:host='. $mysql_host .';dbname=' . $mysql_database, $mysql_
|
|||
\Slim\Slim::registerAutoLoader();
|
||||
$app = new \Slim\Slim();
|
||||
|
||||
// LOAD LIBRARIES
|
||||
include_once 'libs/Controller.php';
|
||||
include_once 'libs/ControllerGroup.php';
|
||||
include_once 'libs/Hashing.php';
|
||||
|
||||
// LOAD MODELS
|
||||
spl_autoload_register(function ($class) {
|
||||
$classPath = "models/{$class}.php";
|
||||
|
@ -20,9 +25,6 @@ spl_autoload_register(function ($class) {
|
|||
});
|
||||
|
||||
// LOAD CONTROLLERS
|
||||
include_once 'libs/Controller.php';
|
||||
include_once 'libs/ControllerGroup.php';
|
||||
|
||||
foreach (glob('controllers/*.php') as $controller) {
|
||||
include $controller;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
class FileUploader {
|
||||
private static $instance = null;
|
||||
|
||||
public static function getInstance() {
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new FileUploader();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct() {}
|
||||
|
||||
public function upload() {
|
||||
// TODO: Implement file upload features
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
class Hashing {
|
||||
public static function hashPassword($password) {
|
||||
return password_hash($password, PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
public static function verifyPassword($password, $hash) {
|
||||
return password_verify($password, $hash);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
class Comment extends DataStore {
|
||||
const TABLE = 'comment';
|
||||
|
||||
public static function getProps() {
|
||||
return array(
|
||||
'content',
|
||||
'file',
|
||||
'ticket',
|
||||
'author',
|
||||
'date'
|
||||
);
|
||||
}
|
||||
|
||||
protected function getDefaultProps() {
|
||||
return array();
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ use RedBeanPHP\Facade as RedBean;
|
|||
abstract class DataStore {
|
||||
protected $_bean;
|
||||
|
||||
abstract protected function getDefaultProperties();
|
||||
abstract protected function getDefaultProps();
|
||||
|
||||
public static function getDataStore($value, $property = 'id') {
|
||||
$bean = RedBean::findOne(static::TABLE, static::validateProp($property) . ' =:value', array(
|
||||
|
@ -21,7 +21,7 @@ abstract class DataStore {
|
|||
}
|
||||
else {
|
||||
$this->_bean = RedBean::dispense(static::TABLE);
|
||||
$defaultProperties = $this->getDefaultProperties();
|
||||
$defaultProperties = $this->getDefaultProps();
|
||||
|
||||
foreach ($defaultProperties as $PROP => $VALUE) {
|
||||
$this->_bean[$PROP] = $VALUE;
|
||||
|
@ -29,15 +29,9 @@ abstract class DataStore {
|
|||
}
|
||||
}
|
||||
|
||||
protected static function deleteDataStore($dataStore) {
|
||||
if ($dataStore instanceof DataStore) {
|
||||
RedBean::trash($dataStore->getBeanInstance());
|
||||
unset($dataStore);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
public function delete() {
|
||||
RedBean::trash($this->getBeanInstance());
|
||||
unset($this);
|
||||
}
|
||||
|
||||
public function getBeanInstance() {
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
class Ticket extends DataStore {
|
||||
const TABLE = 'ticket';
|
||||
|
||||
public static function getProps() {
|
||||
return array(
|
||||
'ticketId',
|
||||
'title',
|
||||
'content',
|
||||
'language',
|
||||
'department',
|
||||
'file',
|
||||
'date',
|
||||
'unread',
|
||||
'closed',
|
||||
'author',
|
||||
'owner',
|
||||
'ownComments'
|
||||
);
|
||||
}
|
||||
|
||||
protected function getDefaultProps() {
|
||||
return array();
|
||||
}
|
||||
}
|
|
@ -1,42 +1,35 @@
|
|||
<?php
|
||||
|
||||
class User extends DataStore {
|
||||
const TABLE = 'users';
|
||||
|
||||
public static function hashPassword($password) {
|
||||
return password_hash($password, PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
public static function verifyPassword($password, $hash) {
|
||||
return password_verify($password, $hash);
|
||||
}
|
||||
const TABLE = 'user';
|
||||
|
||||
public static function authenticate($userEmail, $userPassword) {
|
||||
$user = static::getUser($userEmail, 'email');
|
||||
$user = User::getUser($userEmail, 'email');
|
||||
|
||||
return ($user && static::verifyPassword($userPassword, $user->password)) ? $user : null;
|
||||
return ($user && Hashing::verifyPassword($userPassword, $user->password)) ? $user : null;
|
||||
}
|
||||
|
||||
public static function getProps() {
|
||||
return array(
|
||||
'email',
|
||||
'password'
|
||||
'password',
|
||||
'name',
|
||||
'verificationToken',
|
||||
'ownTickets'
|
||||
);
|
||||
}
|
||||
|
||||
public function getDefaultProperties() {
|
||||
return array();
|
||||
return array(
|
||||
'ownTickets' => []
|
||||
);
|
||||
}
|
||||
|
||||
public function addTicket($ticket) {
|
||||
$this->ownTickets[] = $ticket;
|
||||
}
|
||||
|
||||
public static function getUser($value, $property = 'id') {
|
||||
return parent::getDataStore($value, $property);
|
||||
}
|
||||
|
||||
public static function deleteUser($user) {
|
||||
parent::deleteDataStore($user);
|
||||
}
|
||||
|
||||
public function showUserDetails() {
|
||||
return $this->_user;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue