2015-10-29 00:47:40 +01:00
|
|
|
<?php
|
2016-07-04 02:32:34 +02:00
|
|
|
use RedBeanPHP\Facade as RedBean;
|
2015-11-01 22:43:35 +01:00
|
|
|
|
2017-04-21 05:34:20 +02:00
|
|
|
/**
|
|
|
|
* @api {OBJECT} User User
|
2022-01-04 17:24:06 +01:00
|
|
|
* @apiVersion 4.11.0
|
2017-04-21 05:34:20 +02:00
|
|
|
* @apiGroup Data Structures
|
|
|
|
* @apiParam {String} email The email of the user.
|
|
|
|
* @apiParam {Number} id The id of the user.
|
|
|
|
* @apiParam {String} name The name of the user.
|
2017-05-11 21:37:03 +02:00
|
|
|
* @apiParam {Boolean} verified Indicates if the user has verified the email.
|
2020-05-13 00:22:51 +02:00
|
|
|
* @apiParam {Boolean} notRegistered Indicates if the user had logged at least one time.
|
2019-02-03 20:47:29 +01:00
|
|
|
* @apiParam {[CustomField](#api-Data_Structures-ObjectCustomfield)[]} customfields Indicates the values for custom fields.
|
2017-04-21 05:34:20 +02:00
|
|
|
*/
|
|
|
|
|
2015-11-03 01:55:59 +01:00
|
|
|
class User extends DataStore {
|
2016-07-04 02:32:34 +02:00
|
|
|
const TABLE = 'user';
|
2020-05-13 00:22:51 +02:00
|
|
|
public $ticketNumber = null;
|
2016-02-02 22:41:10 +01:00
|
|
|
public static function authenticate($userEmail, $userPassword) {
|
2016-05-15 00:08:30 +02:00
|
|
|
$user = User::getUser($userEmail, 'email');
|
2016-02-02 22:41:10 +01:00
|
|
|
|
2020-05-13 00:22:51 +02:00
|
|
|
return ($user && Hashing::verifyPassword($userPassword, $user->password) && !$user->notRegistered) ? $user : new NullDataStore();
|
2016-02-02 22:41:10 +01:00
|
|
|
}
|
|
|
|
|
2016-01-15 03:45:22 +01:00
|
|
|
public static function getProps() {
|
2016-08-04 05:59:04 +02:00
|
|
|
return [
|
2016-01-15 03:45:22 +01:00
|
|
|
'email',
|
2016-05-15 00:08:30 +02:00
|
|
|
'password',
|
|
|
|
'name',
|
2016-11-30 07:33:46 +01:00
|
|
|
'signupDate',
|
|
|
|
'tickets',
|
2016-12-22 07:07:06 +01:00
|
|
|
'sharedTicketList',
|
2018-09-28 00:46:30 +02:00
|
|
|
'verificationToken',
|
2019-02-03 20:47:29 +01:00
|
|
|
'disabled',
|
2020-05-13 00:22:51 +02:00
|
|
|
'xownCustomfieldvalueList',
|
2020-07-21 11:52:34 +02:00
|
|
|
'notRegistered',
|
|
|
|
'sharedUserList',
|
|
|
|
'supervisedrelation'
|
2016-08-04 05:59:04 +02:00
|
|
|
];
|
2015-11-01 22:43:35 +01:00
|
|
|
}
|
|
|
|
|
2016-05-15 01:22:46 +02:00
|
|
|
public function getDefaultProps() {
|
2016-09-25 06:16:10 +02:00
|
|
|
return [];
|
2016-01-15 03:45:22 +01:00
|
|
|
}
|
|
|
|
|
2016-05-15 00:08:30 +02:00
|
|
|
public static function getUser($value, $property = 'id') {
|
|
|
|
return parent::getDataStore($value, $property);
|
2015-10-29 00:47:40 +01:00
|
|
|
}
|
2016-12-29 06:50:53 +01:00
|
|
|
|
2019-09-20 21:58:21 +02:00
|
|
|
public function canManageTicket(Ticket $ticket){
|
2020-05-13 00:22:51 +02:00
|
|
|
$ticketNumberInstanceValidation = true;
|
2020-07-21 11:52:34 +02:00
|
|
|
$ticketOfSupervisedUser = false;
|
|
|
|
|
2020-05-13 00:22:51 +02:00
|
|
|
if($this->ticketNumber) {
|
|
|
|
$ticketNumberInstanceValidation = $this->ticketNumber == $ticket->ticketNumber;
|
|
|
|
}
|
2020-07-21 11:52:34 +02:00
|
|
|
if($this->supervisedrelation){
|
|
|
|
foreach( $this->supervisedrelation->sharedUserList as $user){
|
|
|
|
if($ticket->isAuthor($user)) $ticketOfSupervisedUser = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (($ticket->isAuthor($this) || $ticketOfSupervisedUser) && $ticketNumberInstanceValidation);
|
2019-09-20 21:58:21 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 21:45:55 +02:00
|
|
|
public function toArray($minimal = false) {
|
|
|
|
if($minimal) {
|
|
|
|
return [
|
|
|
|
'id' => $this->id,
|
|
|
|
'name' => $this->name,
|
|
|
|
'email' => $this->email,
|
|
|
|
'isStaff' => 0
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-12-29 06:50:53 +01:00
|
|
|
return [
|
|
|
|
'email' => $this->email,
|
|
|
|
'id' => $this->id,
|
2017-01-10 17:19:36 +01:00
|
|
|
'name' => $this->name,
|
2018-09-28 00:46:30 +02:00
|
|
|
'verified' => !$this->verificationToken,
|
2019-02-03 20:47:29 +01:00
|
|
|
'disabled' => $this->disabled,
|
|
|
|
'customfields' => $this->xownCustomfieldvalueList->toArray(),
|
2020-07-21 11:52:34 +02:00
|
|
|
'notRegistered' => $this->notRegistered,
|
|
|
|
'supervisedrelation' => $this->supervisedrelation
|
2016-12-29 06:50:53 +01:00
|
|
|
];
|
|
|
|
}
|
2015-10-29 00:47:40 +01:00
|
|
|
}
|