Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace My\ModelBundle\Entity;
- use Doctrine\ORM\EntityManager;
- use Doctrine\Common\Collections\ArrayCollection;
- use Symfony\Component\Security\Core\User\AdvancedUserInterface;
- use Symfony\Component\Security\Core\User\UserInterface;
- use Symfony\Component\Security\Core\User\AccountInterface;
- use Symfony\Component\Security\Core\User\AdvancedAccountInterface;
- use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
- use My\ModelBundle\Entity\SocialEntity;
- /**
- * @orm:Entity(repositoryClass="FSC\ModelBundle\Entity\Repository\UserRepository")
- * @orm:Table(name="users")
- */
- class User extends SocialEntity implements AdvancedUserInterface
- {
- //EN CAS D'AJOUT DE NOUVELLES VALEURS PENSER A LES RAJOUTER DANS LES ASSETS
- const USER_FEET_RIGHTHANDED = "right-handed";
- const USER_FEET_LEFTHANDED = "left-handed";
- const USER_FEET_AMBIDEXTROUS = "ambidextrous";
- const USER_POSITION_DEFENDER = "defender";
- const USER_POSITION_ATTACKERS = "attackers";
- const USER_POSITION_GOALKEEPER = "goalkeeper";
- const USER_POSITION_MIDFIELDERS = "midfielders";
- const USER_POSITION_ARBITER = "arbiter";
- /**
- * @orm:Id
- * @orm:Column(type="integer")
- * @orm:generatedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @orm:Column(type="string", nullable=true)
- * @assert:NotBlank(groups="register")
- * @assert:MinLength(2)
- * @assert:MaxLength(30)
- */
- private $pseudo;
- /**
- * @orm:Column(type="string", nullable=true)
- * @assert:MinLength(2)
- * @assert:MaxLength(40)
- */
- private $licence;
- /**
- * @orm:Column(type="string", nullable=true)
- * @assert:NotBlank(groups="register")
- * @assert:MinLength(2)
- * @assert:MaxLength(40)
- */
- private $firstname;
- /**
- * @orm:Column(type="string", nullable=true)
- * @assert:NotBlank(groups="register")
- * @assert:MinLength(2)
- * @assert:MaxLength(40)
- */
- private $lastname;
- /**
- * @orm:Column(type="string", unique=true)
- * @assert:Email(message="Your Email adress is not valid")
- * @assert:NotBlank(groups={"register", "forgotPassword"})
- */
- private $email;
- /**
- * @orm:Column(type="string")
- * @assert:NotBlank(groups="register")
- * @assert:Choice(
- * choices = { "male", "female" }
- * )
- */
- protected $gender;
- /**
- * @orm:Column(type="string")
- */
- protected $salt;
- /**
- * @orm:Column(type="string")
- */
- protected $algorithm;
- /**
- * @assert:NotBlank(groups="changePassword")
- * @assert:MinLength(6)
- */
- private $oldPassword;
- /**
- * @orm:Column(type="string", nullable=false)
- * @assert:NotBlank(groups={"register", "resetPassword"})
- * @assert:MinLength(6)
- */
- private $password;
- /**
- * @orm:Column(type="datetime")
- */
- private $birthday;
- /**
- * @orm:Column(type="float", nullable=true)
- */
- private $weight;
- /**
- * @orm:Column(type="float", nullable=true)
- */
- private $height;
- /**
- * @orm:Column(type="string", nullable=true)
- * @assert:Choice(
- * choices = { "right-handed", "left-handed", "ambidextrous"}
- * )
- */
- private $feet;
- /**
- * position de jeu du joueur / attaquan, defenseur
- * @orm:Column(type="string", nullable=true)
- * @assert:Choice(
- * choices = { "defender", "attackers", "goalkeeper", "midfielders", "arbiter"}
- * )
- */
- private $position;
- /**
- * @orm:Column(type="string", nullable=true)
- */
- private $url;
- /**
- * @orm:Column(type="text", nullable=true)
- */
- private $description;
- /**
- * @orm:Column(type="boolean")
- */
- private $enabled;
- /**
- * @orm:Column(type="boolean")
- */
- protected $locked;
- /**
- * @orm:Column(type="boolean")
- */
- protected $expired;
- /**
- * @orm:Column(type="string", nullable=true, name="confirmation_code")
- */
- private $confirmationCode;
- /**
- * @orm:Column(type="datetime", nullable=true, name="last_login")
- */
- private $lastLogin;
- /**
- * @orm:Column(type="string", nullable=true, unique=true, name="temp_email")
- * @assert:Email(message="Your Email adress is not valid")
- * @assert:NotBlank(groups="changeEmail")
- */
- private $tempEmail;
- /**
- * @orm:Column(type="boolean")
- * @assert:true
- */
- private $cgu;
- protected $em;
- public function __construct(EntityManager $em)
- {
- parent::__construct();
- $this->em = $em;
- $this->enabled = false;
- $this->locked = false;
- $this->expired = false;
- $this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
- $this->algorithm = 'sha512';
- //generate a licence for the user
- $this->generateLicence();
- //generate the confirmation code
- $this->generateConfirmationCode();
- }
- //Update the user
- public function updateUser(User $user)
- {
- $this->em->persist($user);
- $this->em->flush();
- }
- protected function getEm()
- {
- return $this->get('doctrine.orm.default_entity_manager');
- }
- /**
- * Methodes de UserInterface
- */
- public function getRoles()
- {
- return array('ROLE_USER');
- }
- public function equals(UserInterface $user)
- {
- return true; //A implementer si besoin
- }
- public function eraseCredentials()
- {
- }
- public function getSalt()
- {
- return $this->salt;
- }
- public function setSalt($salt)
- {
- $this->salt = $salt;
- }
- public function getAlgorithm()
- {
- return $this->algorithm;
- }
- public function setAlgorithm($algorithm)
- {
- $this->algorithm = $algorithm;
- }
- /**
- * Checks whether the user is enabled.
- * Implements AdvancedUserInterface
- *
- * @return Boolean true if the user is enabled, false otherwise
- */
- public function isEnabled()
- {
- return $this->enabled;
- }
- public function isExpired()
- {
- return !$this->isAccountNonExpired();
- }
- public function isLocked()
- {
- return $this->locked;
- }
- /**
- * @param bool $boolean
- */
- public function setEnabled($boolean)
- {
- $this->enabled = $boolean;
- }
- /**
- * Fin methodes UserInterface
- */
- /**
- * Checks whether the user is locked.
- * Implements AdvancedAccountInterface
- *
- * @return Boolean true if the user is not locked, false otherwise
- */
- public function isAccountNonLocked()
- {
- return !$this->locked;
- }
- /**
- * @var boolean
- */
- protected $credentialsExpired;
- /**
- * @var DateTime
- */
- protected $credentialsExpireAt;
- /**
- * @var DateTime
- */
- protected $expiresAt;
- /**
- * Checks whether the user's account has expired.
- * Implements AdvancedAccountInterface
- *
- * @return Boolean true if the user's account is non expired, false otherwise
- */
- public function isAccountNonExpired()
- {
- if (true === $this->expired) {
- return false;
- }
- if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
- return false;
- }
- return true;
- }
- /**
- * Checks whether the user's credentials (password) has expired.
- * Implements AdvancedAccountInterface
- *
- * @return Boolean true if the user's credentials are non expired, false otherwise
- */
- public function isCredentialsNonExpired()
- {
- if (true === $this->credentialsExpired) {
- return false;
- }
- if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
- return false;
- }
- return true;
- }
- public function isCredentialsExpired()
- {
- return !$this->isCredentialsNonExpired();
- }
- /**
- * @return the $gender
- */
- public function getGender() {
- return $this->gender;
- }
- /**
- * @param $gender the $gender to set
- */
- public function setGender($gender) {
- $this->gender = $gender;
- }
- /**
- * Get username
- * @return the user email
- */
- public function getUsername()
- {
- return $this->email;
- }
- /**
- * Set Username
- *
- * @param string $username
- */
- public function setUsername($username)
- {
- $this->email = $username;
- }
- /**
- * @return the $pseudo
- */
- public function getPseudo() {
- return $this->pseudo;
- }
- /**
- * @param $pseudo the $pseudo to set
- */
- public function setPseudo($pseudo) {
- $this->pseudo = $pseudo;
- }
- /**
- * Set firstname
- *
- * @param string $firstname
- */
- public function setFirstname($firstname)
- {
- $this->firstname = $firstname;
- }
- /**
- * Get firstname
- *
- * @return string $firstname
- */
- public function getFirstname()
- {
- return $this->firstname;
- }
- /**
- * Set lastname
- *
- * @param string $lastname
- */
- public function setLastname($lastname)
- {
- $this->lastname = $lastname;
- }
- /**
- * Get lastname
- *
- * @return string $lastname
- */
- public function getLastname()
- {
- return $this->lastname;
- }
- /**
- * Set email
- *
- * @param string $email
- */
- public function setEmail($email)
- {
- $this->email = $email;
- }
- /**
- * Get email
- *
- * @return string $email
- */
- public function getEmail()
- {
- return $this->email;
- }
- /**
- * Set passwd
- *
- * @param string $passwd
- */
- public function setPassword($password)
- {
- $this->password = $password;
- }
- /**
- * Get passwd
- *
- * @return string $passwd
- */
- public function getPassword()
- {
- return $this->password;
- }
- public function getPlainPassword()
- {
- return $this->plainPassword;
- }
- /**
- * Set birthday
- *
- * @param datetime $birthday
- */
- public function setBirthday($birthday)
- {
- $this->birthday = $birthday;
- }
- /**
- * Get birthday
- *
- * @return datetime $birthday
- */
- public function getBirthday()
- {
- return $this->birthday;
- }
- /**
- * Set weight
- *
- * @param float $weight
- */
- public function setWeight($weight)
- {
- $this->weight = $weight;
- }
- /**
- * Get weight
- *
- * @return float $weight
- */
- public function getWeight()
- {
- return $this->weight;
- }
- /**
- * Set height
- *
- * @param float $height
- */
- public function setHeight($height)
- {
- $this->height = $height;
- }
- /**
- * Get height
- *
- * @return float $height
- */
- public function getHeight()
- {
- return $this->height;
- }
- /**
- * Set url
- *
- * @param string $url
- */
- public function setUrl($url)
- {
- $this->url = $url;
- }
- /**
- * Get url
- *
- * @return string $url
- */
- public function getUrl()
- {
- return $this->url;
- }
- /**
- * Set description
- *
- * @param text $description
- */
- public function setDescription($description)
- {
- $this->description = $description;
- }
- /**
- * Get description
- *
- * @return text $description
- */
- public function getDescription()
- {
- return $this->description;
- }
- /**
- * Set licence
- *
- * @param string $licence
- */
- public function setLicence($licence)
- {
- $this->licence = $licence;
- }
- /**
- * Get licence
- *
- * @return string $licence
- */
- public function getLicence()
- {
- return $this->licence;
- }
- /**
- * @recaptcha:True
- */
- private $recaptcha;
- public function getRecaptcha() {
- return $this->recaptcha;
- }
- public function setRecaptcha($recaptcha) {
- $this->recaptcha = $recaptcha;
- }
- /**
- * Generate the confirmation Code
- */
- public function generateConfirmationCode()
- {
- $this->confirmationCode = md5(microtime(TRUE)*100000);
- }
- /**
- * Generate the confirmation Code
- * based on FOSUserBundle
- */
- public function generateLicence()
- {
- $this->licence = 'FSC'.rand();
- }
- /**
- * @return the $tempEmail
- */
- public function getTempEmail() {
- return $this->tempEmail;
- }
- /**
- * @param $tempEmail the $tempEmail to set
- */
- public function setTempEmail($tempEmail) {
- $this->tempEmail = $tempEmail;
- }
- /**
- * @return the $lastLogin
- */
- public function getLastLogin() {
- return $this->lastLogin;
- }
- /**
- * @param $lastLogin the $lastLogin to set
- */
- public function setLastLogin(\DateTime $time) {
- $this->lastLogin = $time;
- }
- /**
- * @return the $cgu
- */
- public function getCgu() {
- return $this->cgu;
- }
- /**
- * @param $cgu the $cgu to set
- */
- public function setCgu($cgu) {
- $this->cgu = $cgu;
- }
- /**
- * @return the $confirmationCode
- */
- public function getConfirmationCode() {
- return $this->confirmationCode;
- }
- /**
- * @param $confirmationCode the $confirmationCode to set
- */
- public function setConfirmationCode($confirmationCode) {
- $this->confirmationCode = $confirmationCode;
- }
- /**
- * @return the $oldPassword
- */
- public function getOldPassword() {
- return $this->oldPassword;
- }
- /**
- * @param $oldPassword the $oldPassword to set
- */
- public function setOldPassword($oldPassword) {
- $this->oldPassword = $oldPassword;
- }
- /**
- * @return the $feet
- */
- public function getFeet() {
- return $this->feet;
- }
- /**
- * @param $feet the $feet to set
- */
- public function setFeet($feet) {
- $this->feet = $feet;
- }
- /**
- * @return the $position
- */
- public function getPosition() {
- return $this->position;
- }
- /**
- * @param $position the $position to set
- */
- public function setPosition($position) {
- $this->position = $position;
- }
- /**
- * Fonction permettant de tester si une demande d'amis éxiste déja entre le user connecter et celui courant
- * Fonction utilisé dans les templates afin de tester l'affichage des liens de demande d'amis
- */
- public function friendRequestExist($userDest){
- return $this->getEm()->getRepository('FSCModelBundle:Link')->friendRequestExist($this,$userDest);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement