2015-12-31 19:47:34 +01:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
2018-07-25 23:42:00 +02:00
|
|
|
class User {
|
2019-01-26 12:50:48 +01:00
|
|
|
protected $vars;
|
2015-12-31 19:47:34 +01:00
|
|
|
|
2018-07-25 23:42:00 +02:00
|
|
|
function __construct($username)
|
2015-12-31 19:47:34 +01:00
|
|
|
{
|
2018-08-03 18:59:23 +02:00
|
|
|
global $users;
|
2015-12-31 19:47:34 +01:00
|
|
|
|
2018-07-25 23:42:00 +02:00
|
|
|
$this->vars['username'] = $username;
|
|
|
|
|
|
|
|
if ($username===false) {
|
2018-08-03 18:59:23 +02:00
|
|
|
$row = $users->getDefaultFields();
|
2018-07-25 23:42:00 +02:00
|
|
|
} else {
|
2018-08-03 18:59:23 +02:00
|
|
|
if (Text::isEmpty($username) || !$users->exists($username)) {
|
2018-11-23 20:15:50 +01:00
|
|
|
$errorMessage = 'User not found in the database by username ['.$username.']';
|
2018-07-25 23:42:00 +02:00
|
|
|
Log::set(__METHOD__.LOG_SEP.$errorMessage);
|
|
|
|
throw new Exception($errorMessage);
|
|
|
|
}
|
2018-08-03 18:59:23 +02:00
|
|
|
$row = $users->getUserDB($username);
|
2018-07-25 23:42:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($row as $field=>$value) {
|
|
|
|
$this->setField($field, $value);
|
|
|
|
}
|
2015-12-31 19:47:34 +01:00
|
|
|
}
|
|
|
|
|
2018-07-25 23:42:00 +02:00
|
|
|
public function getValue($field)
|
2015-12-31 19:47:34 +01:00
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
if (isset($this->vars[$field])) {
|
|
|
|
return $this->vars[$field];
|
2015-12-31 19:47:34 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-25 23:42:00 +02:00
|
|
|
public function setField($field, $value)
|
|
|
|
{
|
|
|
|
$this->vars[$field] = $value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDB()
|
|
|
|
{
|
|
|
|
return $this->vars;
|
|
|
|
}
|
|
|
|
|
2015-12-31 19:47:34 +01:00
|
|
|
public function username()
|
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
return $this->getValue('username');
|
2015-12-31 19:47:34 +01:00
|
|
|
}
|
|
|
|
|
2018-07-28 18:33:37 +02:00
|
|
|
public function nickname()
|
|
|
|
{
|
|
|
|
return $this->getValue('nickname');
|
|
|
|
}
|
|
|
|
|
2015-12-31 19:47:34 +01:00
|
|
|
public function firstName()
|
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
return $this->getValue('firstName');
|
2015-12-31 19:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function lastName()
|
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
return $this->getValue('lastName');
|
2015-12-31 19:47:34 +01:00
|
|
|
}
|
2017-07-02 22:46:05 +02:00
|
|
|
|
|
|
|
public function tokenAuth()
|
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
return $this->getValue('tokenAuth');
|
2017-07-02 22:46:05 +02:00
|
|
|
}
|
2015-12-31 19:47:34 +01:00
|
|
|
|
|
|
|
public function role()
|
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
return $this->getValue('role');
|
2015-12-31 19:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function password()
|
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
return $this->getValue('password');
|
2015-12-31 19:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-09-07 02:14:57 +02:00
|
|
|
public function enabled()
|
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
$password = $this->getValue('password');
|
2016-09-07 02:14:57 +02:00
|
|
|
return $password != '!';
|
|
|
|
}
|
|
|
|
|
2015-12-31 19:47:34 +01:00
|
|
|
public function salt()
|
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
return $this->getValue('salt');
|
2015-12-31 19:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function email()
|
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
return $this->getValue('email');
|
2015-12-31 19:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function registered()
|
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
return $this->getValue('registered');
|
2015-12-31 19:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-02-14 01:15:19 +01:00
|
|
|
public function twitter()
|
2015-12-31 19:47:34 +01:00
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
return $this->getValue('twitter');
|
2015-12-31 19:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-02-14 01:15:19 +01:00
|
|
|
public function facebook()
|
2015-12-31 19:47:34 +01:00
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
return $this->getValue('facebook');
|
2015-12-31 19:47:34 +01:00
|
|
|
}
|
|
|
|
|
2017-10-02 23:17:32 +02:00
|
|
|
public function codepen()
|
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
return $this->getValue('codepen');
|
2017-10-02 23:17:32 +02:00
|
|
|
}
|
|
|
|
|
2016-02-14 01:15:19 +01:00
|
|
|
public function instagram()
|
2015-12-31 19:47:34 +01:00
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
return $this->getValue('instagram');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function github()
|
|
|
|
{
|
|
|
|
return $this->getValue('github');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function gitlab()
|
|
|
|
{
|
|
|
|
return $this->getValue('gitlab');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function linkedin()
|
|
|
|
{
|
|
|
|
return $this->getValue('linkedin');
|
2015-12-31 19:47:34 +01:00
|
|
|
}
|
|
|
|
|
2018-11-07 15:40:22 +01:00
|
|
|
public function mastodon()
|
|
|
|
{
|
|
|
|
return $this->getValue('mastodon');
|
|
|
|
}
|
|
|
|
|
2018-07-30 23:43:12 +02:00
|
|
|
public function profilePicture()
|
2016-01-02 23:51:12 +01:00
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
$filename = $this->getValue('username').'.png';
|
2018-07-30 23:43:12 +02:00
|
|
|
if (!file_exists(PATH_UPLOADS_PROFILES.$filename)) {
|
|
|
|
return false;
|
2016-01-02 23:51:12 +01:00
|
|
|
}
|
2018-07-31 18:36:22 +02:00
|
|
|
return DOMAIN_UPLOADS_PROFILES.$filename;
|
2016-01-02 23:51:12 +01:00
|
|
|
}
|
|
|
|
|
2015-12-31 19:47:34 +01:00
|
|
|
}
|