2014-02-21 09:25:10 +00:00
|
|
|
<?php
|
|
|
|
namespace Entity;
|
|
|
|
|
2017-01-24 00:17:50 +00:00
|
|
|
use \Doctrine\ORM\Mapping as ORM;
|
|
|
|
use \Doctrine\Common\Collections\ArrayCollection;
|
2014-02-21 09:25:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Table(name="users")
|
2017-01-17 08:46:43 +00:00
|
|
|
* @Entity(repositoryClass="Entity\Repository\UserRepository")
|
2016-10-06 06:03:00 +00:00
|
|
|
* @HasLifecycleCallbacks
|
2014-02-21 09:25:10 +00:00
|
|
|
*/
|
2016-05-02 08:18:32 +00:00
|
|
|
class User extends \App\Doctrine\Entity
|
2014-02-21 09:25:10 +00:00
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->roles = new ArrayCollection;
|
2015-05-22 07:26:49 +00:00
|
|
|
|
2016-10-06 06:03:00 +00:00
|
|
|
$this->created_at = time();
|
|
|
|
$this->updated_at = time();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @PrePersist
|
|
|
|
*/
|
|
|
|
public function preSave()
|
|
|
|
{
|
|
|
|
$this->updated_at = time();
|
2014-02-21 09:25:10 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 00:17:50 +00:00
|
|
|
/**
|
|
|
|
* @Column(name="uid", type="integer")
|
|
|
|
* @Id
|
|
|
|
* @GeneratedValue(strategy="AUTO")
|
|
|
|
*/
|
|
|
|
protected $id;
|
|
|
|
|
|
|
|
/** @Column(name="email", type="string", length=100, nullable=true) */
|
|
|
|
protected $email;
|
|
|
|
|
2014-08-05 03:49:54 +00:00
|
|
|
public function getAvatar($size = 50)
|
|
|
|
{
|
2016-05-02 08:18:32 +00:00
|
|
|
return \App\Service\Gravatar::get($this->email, $size, 'identicon');
|
2014-08-05 03:49:54 +00:00
|
|
|
}
|
2014-02-21 09:25:10 +00:00
|
|
|
|
2017-01-24 00:17:50 +00:00
|
|
|
/** @Column(name="auth_password", type="string", length=255, nullable=true) */
|
|
|
|
protected $auth_password;
|
|
|
|
|
2016-09-27 20:39:54 +00:00
|
|
|
public function verifyPassword($password)
|
|
|
|
{
|
|
|
|
return password_verify($password, $this->auth_password);
|
|
|
|
}
|
|
|
|
|
2014-02-21 09:25:10 +00:00
|
|
|
public function getAuthPassword()
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAuthPassword($password)
|
|
|
|
{
|
2017-01-24 00:17:50 +00:00
|
|
|
if (trim($password))
|
2015-07-22 15:05:16 +00:00
|
|
|
$this->auth_password = password_hash($password, \PASSWORD_DEFAULT);
|
2015-07-22 18:04:10 +00:00
|
|
|
|
|
|
|
return $this;
|
2014-02-21 09:25:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function generateRandomPassword()
|
|
|
|
{
|
2017-01-24 00:17:50 +00:00
|
|
|
$this->setAuthPassword(md5('APP_EXTERNAL_'.mt_rand()));
|
2014-02-21 09:25:10 +00:00
|
|
|
}
|
2017-01-24 00:17:50 +00:00
|
|
|
|
|
|
|
/** @Column(name="name", type="string", length=100, nullable=true) */
|
|
|
|
protected $name;
|
|
|
|
|
|
|
|
/** @Column(name="timezone", type="string", length=100, nullable=true) */
|
|
|
|
protected $timezone;
|
|
|
|
|
|
|
|
/** @Column(name="locale", type="string", length=25, nullable=true) */
|
|
|
|
protected $locale;
|
|
|
|
|
|
|
|
/** @Column(name="theme", type="string", length=25, nullable=true) */
|
|
|
|
protected $theme;
|
|
|
|
|
|
|
|
/** @Column(name="created_at", type="integer") */
|
|
|
|
protected $created_at;
|
|
|
|
|
|
|
|
/** @Column(name="updated_at", type="integer") */
|
|
|
|
protected $updated_at;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ManyToMany(targetEntity="Role", inversedBy="users")
|
|
|
|
* @JoinTable(name="user_has_role",
|
|
|
|
* joinColumns={@JoinColumn(name="user_id", referencedColumnName="uid", onDelete="CASCADE")},
|
|
|
|
* inverseJoinColumns={@JoinColumn(name="role_id", referencedColumnName="id", onDelete="CASCADE")}
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
protected $roles;
|
2016-09-28 03:28:49 +00:00
|
|
|
}
|