4
0
mirror of https://github.com/AzuraCast/AzuraCast.git synced 2024-06-14 21:26:37 +00:00
AzuraCast/src/Entity/User.php

97 lines
2.4 KiB
PHP
Raw Normal View History

2014-02-21 09:25:10 +00:00
<?php
namespace Entity;
use \Doctrine\ORM\Mapping as ORM;
use \Doctrine\Common\Collections\ArrayCollection;
2014-02-21 09:25:10 +00:00
/**
* @Table(name="users")
* @Entity(repositoryClass="Entity\Repository\UserRepository")
* @HasLifecycleCallbacks
2014-02-21 09:25:10 +00:00
*/
class User extends \App\Doctrine\Entity
2014-02-21 09:25:10 +00:00
{
public function __construct()
{
$this->roles = new ArrayCollection;
$this->created_at = time();
$this->updated_at = time();
}
/**
* @PrePersist
*/
public function preSave()
{
$this->updated_at = time();
2014-02-21 09:25:10 +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)
{
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
/** @Column(name="auth_password", type="string", length=255, nullable=true) */
protected $auth_password;
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)
{
if (trim($password))
$this->auth_password = password_hash($password, \PASSWORD_DEFAULT);
return $this;
2014-02-21 09:25:10 +00:00
}
public function generateRandomPassword()
{
$this->setAuthPassword(md5('APP_EXTERNAL_'.mt_rand()));
2014-02-21 09:25:10 +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;
}