opensupports/server/models/User.php

54 lines
1.4 KiB
PHP
Raw Normal View History

<?php
use RedBeanPHP\Facade as RedBean;
2017-04-21 05:34:20 +02:00
/**
* @api {OBJECT} User User
2018-09-20 22:19:47 +02:00
* @apiVersion 4.3.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.
2017-04-21 05:34:20 +02:00
*/
class User extends DataStore {
const TABLE = 'user';
public static function authenticate($userEmail, $userPassword) {
$user = User::getUser($userEmail, 'email');
return ($user && Hashing::verifyPassword($userPassword, $user->password)) ? $user : new NullDataStore();
}
public static function getProps() {
return [
'email',
'password',
'name',
2016-11-30 07:33:46 +01:00
'signupDate',
'tickets',
'sharedTicketList',
2018-09-28 00:46:30 +02:00
'verificationToken',
'disabled'
];
}
2016-05-15 01:22:46 +02:00
public function getDefaultProps() {
return [];
}
public static function getUser($value, $property = 'id') {
return parent::getDataStore($value, $property);
}
public function toArray() {
return [
'email' => $this->email,
'id' => $this->id,
'name' => $this->name,
2018-09-28 00:46:30 +02:00
'verified' => !$this->verificationToken,
'disabled' => $this->disabled
];
}
}