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 {
|
|
|
|
private $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-07-25 23:42:00 +02:00
|
|
|
global $dbUsers;
|
2015-12-31 19:47:34 +01:00
|
|
|
|
2018-07-25 23:42:00 +02:00
|
|
|
$this->vars['username'] = $username;
|
|
|
|
|
|
|
|
if ($username===false) {
|
|
|
|
$row = $dbUsers->getDefaultFields();
|
|
|
|
} else {
|
|
|
|
if (Text::isEmpty($username) || !$dbUsers->exists($username)) {
|
|
|
|
$errorMessage = 'User not found in database by username ['.$username.']';
|
|
|
|
Log::set(__METHOD__.LOG_SEP.$errorMessage);
|
|
|
|
throw new Exception($errorMessage);
|
|
|
|
}
|
|
|
|
$row = $dbUsers->getUserDB($username);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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 googlePlus()
|
2015-12-31 19:47:34 +01:00
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
return $this->getValue('googlePlus');
|
2015-12-31 19:47:34 +01: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
|
|
|
}
|
|
|
|
|
2016-01-02 23:51:12 +01:00
|
|
|
public function profilePicture($absolute=true)
|
|
|
|
{
|
2018-07-25 23:42:00 +02:00
|
|
|
$filename = $this->getValue('username').'.png';
|
2016-01-02 23:51:12 +01:00
|
|
|
|
2016-09-22 04:12:29 +02:00
|
|
|
if( !file_exists(PATH_UPLOADS_PROFILES.$filename) ) {
|
|
|
|
return '#';
|
|
|
|
}
|
|
|
|
|
2016-01-02 23:51:12 +01:00
|
|
|
if($absolute) {
|
|
|
|
return HTML_PATH_UPLOADS_PROFILES.$filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $filename;
|
|
|
|
}
|
|
|
|
|
2015-12-31 19:47:34 +01:00
|
|
|
}
|