Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.78 KB | None | 0 0
  1. <?php
  2. namespace My\ModelBundle\Entity;
  3.  
  4. use Doctrine\ORM\EntityManager;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Symfony\Component\Security\Core\User\AdvancedUserInterface;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Symfony\Component\Security\Core\User\AccountInterface;
  9. use Symfony\Component\Security\Core\User\AdvancedAccountInterface;
  10. use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
  11. use My\ModelBundle\Entity\SocialEntity;
  12.  
  13. /**
  14.  * @orm:Entity(repositoryClass="FSC\ModelBundle\Entity\Repository\UserRepository")
  15.  * @orm:Table(name="users")
  16.  */
  17. class User extends SocialEntity implements AdvancedUserInterface
  18. {
  19.     //EN CAS D'AJOUT DE NOUVELLES VALEURS PENSER A LES RAJOUTER DANS LES ASSETS
  20.     const USER_FEET_RIGHTHANDED     = "right-handed";
  21.     const USER_FEET_LEFTHANDED      = "left-handed";
  22.     const USER_FEET_AMBIDEXTROUS    = "ambidextrous";
  23.    
  24.     const USER_POSITION_DEFENDER    = "defender";
  25.     const USER_POSITION_ATTACKERS   = "attackers";
  26.     const USER_POSITION_GOALKEEPER  = "goalkeeper";
  27.     const USER_POSITION_MIDFIELDERS = "midfielders";
  28.     const USER_POSITION_ARBITER     = "arbiter";
  29.        
  30.     /**
  31.      * @orm:Id
  32.      * @orm:Column(type="integer")
  33.      * @orm:generatedValue(strategy="AUTO")
  34.      */
  35.     private $id;
  36.  
  37.    
  38.     /**
  39.      * @orm:Column(type="string", nullable=true)
  40.      * @assert:NotBlank(groups="register")
  41.      * @assert:MinLength(2)
  42.      * @assert:MaxLength(30)
  43.      */
  44.     private $pseudo;
  45.    
  46.     /**
  47.      * @orm:Column(type="string",  nullable=true)
  48.      * @assert:MinLength(2)
  49.      * @assert:MaxLength(40)
  50.      */
  51.     private $licence;
  52.    
  53.     /**
  54.      * @orm:Column(type="string",  nullable=true)
  55.      * @assert:NotBlank(groups="register")
  56.      * @assert:MinLength(2)
  57.      * @assert:MaxLength(40)
  58.      */
  59.     private $firstname;
  60.  
  61.     /**
  62.      * @orm:Column(type="string",  nullable=true)
  63.      * @assert:NotBlank(groups="register")
  64.      * @assert:MinLength(2)
  65.      * @assert:MaxLength(40)
  66.      */
  67.     private $lastname;
  68.  
  69.     /**
  70.      * @orm:Column(type="string", unique=true)
  71.      * @assert:Email(message="Your Email adress is not valid")
  72.      * @assert:NotBlank(groups={"register", "forgotPassword"})
  73.      */
  74.     private $email;
  75.    
  76.     /**
  77.      * @orm:Column(type="string")
  78.      * @assert:NotBlank(groups="register")
  79.      * @assert:Choice(
  80.      *     choices = { "male", "female" }
  81.      * )
  82.      */
  83.     protected $gender;
  84.    
  85.     /**
  86.      * @orm:Column(type="string")
  87.      */
  88.     protected $salt;
  89.    
  90.     /**
  91.      * @orm:Column(type="string")
  92.      */
  93.     protected $algorithm;
  94.     /**
  95.      * @assert:NotBlank(groups="changePassword")
  96.      * @assert:MinLength(6)
  97.      */
  98.     private $oldPassword;
  99.    
  100.     /**
  101.      * @orm:Column(type="string", nullable=false)
  102.      * @assert:NotBlank(groups={"register", "resetPassword"})
  103.      * @assert:MinLength(6)
  104.      */
  105.     private $password;
  106.  
  107.     /**
  108.      * @orm:Column(type="datetime")
  109.      */
  110.     private $birthday;
  111.  
  112.     /**
  113.      * @orm:Column(type="float",  nullable=true)
  114.      */
  115.     private $weight;
  116.  
  117.     /**
  118.      * @orm:Column(type="float",  nullable=true)
  119.      */
  120.     private $height;
  121.  
  122.     /**
  123.      * @orm:Column(type="string",  nullable=true)
  124.      * @assert:Choice(
  125.      *     choices = { "right-handed", "left-handed", "ambidextrous"}
  126.      * )
  127.      */
  128.     private $feet;
  129.    
  130.     /**
  131.      * position de jeu du joueur  / attaquan, defenseur
  132.      * @orm:Column(type="string",  nullable=true)
  133.      * @assert:Choice(
  134.      *     choices = { "defender", "attackers", "goalkeeper", "midfielders", "arbiter"}
  135.      * )
  136.      */
  137.     private $position;
  138.    
  139.     /**
  140.      * @orm:Column(type="string",  nullable=true)
  141.      */
  142.     private $url;
  143.  
  144.     /**
  145.      * @orm:Column(type="text",  nullable=true)
  146.      */
  147.     private $description;
  148.  
  149.     /**
  150.      * @orm:Column(type="boolean")
  151.      */
  152.     private $enabled;
  153.    
  154.     /**
  155.      * @orm:Column(type="boolean")
  156.      */
  157.     protected $locked;
  158.  
  159.     /**
  160.      * @orm:Column(type="boolean")
  161.      */
  162.     protected $expired;
  163.    
  164.     /**
  165.      * @orm:Column(type="string", nullable=true, name="confirmation_code")
  166.      */
  167.     private $confirmationCode;
  168.    
  169.     /**
  170.      * @orm:Column(type="datetime", nullable=true, name="last_login")
  171.      */
  172.     private $lastLogin;
  173.    
  174.     /**
  175.      * @orm:Column(type="string", nullable=true, unique=true, name="temp_email")
  176.      * @assert:Email(message="Your Email adress is not valid")
  177.      * @assert:NotBlank(groups="changeEmail")
  178.      */
  179.     private $tempEmail;
  180.    
  181.     /**
  182.      * @orm:Column(type="boolean")
  183.      * @assert:true
  184.      */
  185.     private $cgu;
  186.  
  187.     protected $em;
  188.    
  189.     public function __construct(EntityManager $em)
  190.     {
  191.         parent::__construct();
  192.         $this->em       = $em;
  193.         $this->enabled  = false;
  194.         $this->locked   = false;
  195.         $this->expired  = false;
  196.         $this->salt     = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
  197.         $this->algorithm = 'sha512';
  198.         //generate a licence for the user
  199.         $this->generateLicence();
  200.         //generate the confirmation code
  201.         $this->generateConfirmationCode();
  202.     }
  203.    
  204.    
  205.     //Update the user
  206.     public function updateUser(User $user)
  207.     {
  208.         $this->em->persist($user);
  209.         $this->em->flush();
  210.        
  211.     }
  212.    
  213.     protected function getEm()
  214.     {
  215.         return $this->get('doctrine.orm.default_entity_manager');
  216.     }
  217.    
  218.     /**
  219.      * Methodes de UserInterface
  220.      */
  221.     public function getRoles()
  222.     {
  223.         return array('ROLE_USER'); 
  224.     }
  225.    
  226.     public function equals(UserInterface $user)
  227.     {
  228.         return true;    //A implementer si besoin
  229.     }
  230.    
  231.     public function eraseCredentials()
  232.     {
  233.            
  234.     }
  235.    
  236.     public function getSalt()
  237.     {
  238.         return $this->salt;
  239.     }
  240.    
  241.     public function setSalt($salt)
  242.     {
  243.         $this->salt = $salt;
  244.     }
  245.  
  246.     public function getAlgorithm()
  247.     {
  248.         return $this->algorithm;
  249.     }
  250.    
  251.     public function setAlgorithm($algorithm)
  252.     {
  253.         $this->algorithm = $algorithm;
  254.     }
  255.    
  256.     /**
  257.      * Checks whether the user is enabled.
  258.      * Implements AdvancedUserInterface
  259.      *
  260.      * @return Boolean true if the user is enabled, false otherwise
  261.      */
  262.     public function isEnabled()
  263.     {
  264.         return $this->enabled;
  265.     }
  266.    
  267.     public function isExpired()
  268.     {
  269.         return !$this->isAccountNonExpired();
  270.     }
  271.  
  272.     public function isLocked()
  273.     {
  274.         return $this->locked;
  275.     }
  276.     /**
  277.      * @param bool $boolean
  278.      */
  279.     public function setEnabled($boolean)
  280.     {
  281.         $this->enabled = $boolean;
  282.     }
  283.     /**
  284.      * Fin methodes UserInterface
  285.      */
  286.    
  287.     /**
  288.      * Checks whether the user is locked.
  289.      * Implements AdvancedAccountInterface
  290.      *
  291.      * @return Boolean true if the user is not locked, false otherwise
  292.      */
  293.     public function isAccountNonLocked()
  294.     {
  295.         return !$this->locked;
  296.     }
  297.    
  298.     /**
  299.      * @var boolean
  300.      */
  301.     protected $credentialsExpired;
  302.  
  303.     /**
  304.      * @var DateTime
  305.      */
  306.     protected $credentialsExpireAt;
  307.    
  308.     /**
  309.      * @var DateTime
  310.      */
  311.     protected $expiresAt;
  312.     /**
  313.      * Checks whether the user's account has expired.
  314.      * Implements AdvancedAccountInterface
  315.      *
  316.      * @return Boolean true if the user's account is non expired, false otherwise
  317.      */
  318.     public function isAccountNonExpired()
  319.     {
  320.         if (true === $this->expired) {
  321.             return false;
  322.         }
  323.  
  324.         if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
  325.             return false;
  326.         }
  327.  
  328.         return true;
  329.     }
  330.    
  331.     /**
  332.      * Checks whether the user's credentials (password) has expired.
  333.      * Implements AdvancedAccountInterface
  334.      *
  335.      * @return Boolean true if the user's credentials are non expired, false otherwise
  336.      */
  337.     public function isCredentialsNonExpired()
  338.     {
  339.         if (true === $this->credentialsExpired) {
  340.             return false;
  341.         }
  342.  
  343.         if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
  344.             return false;
  345.         }
  346.  
  347.         return true;
  348.     }
  349.  
  350.     public function isCredentialsExpired()
  351.     {
  352.         return !$this->isCredentialsNonExpired();
  353.     }
  354.    
  355.     /**
  356.      * @return the $gender
  357.      */
  358.     public function getGender() {
  359.         return $this->gender;
  360.     }
  361.  
  362.     /**
  363.      * @param $gender the $gender to set
  364.      */
  365.     public function setGender($gender) {
  366.         $this->gender = $gender;
  367.     }
  368.  
  369.    
  370.     /**
  371.      * Get username
  372.      * @return the user email
  373.      */
  374.     public function getUsername()
  375.     {
  376.         return $this->email;
  377.     }
  378.    
  379.     /**
  380.      * Set Username
  381.      *
  382.      * @param string $username
  383.      */
  384.     public function setUsername($username)
  385.     {
  386.         $this->email = $username;
  387.     }
  388.    
  389.     /**
  390.      * @return the $pseudo
  391.      */
  392.     public function getPseudo() {
  393.         return $this->pseudo;
  394.     }
  395.  
  396.     /**
  397.      * @param $pseudo the $pseudo to set
  398.      */
  399.     public function setPseudo($pseudo) {
  400.         $this->pseudo = $pseudo;
  401.     }
  402.  
  403.     /**
  404.      * Set firstname
  405.      *
  406.      * @param string $firstname
  407.      */
  408.     public function setFirstname($firstname)
  409.     {
  410.         $this->firstname = $firstname;
  411.     }
  412.  
  413.     /**
  414.      * Get firstname
  415.      *
  416.      * @return string $firstname
  417.      */
  418.     public function getFirstname()
  419.     {
  420.         return $this->firstname;
  421.     }
  422.  
  423.     /**
  424.      * Set lastname
  425.      *
  426.      * @param string $lastname
  427.      */
  428.     public function setLastname($lastname)
  429.     {
  430.         $this->lastname = $lastname;
  431.     }
  432.  
  433.     /**
  434.      * Get lastname
  435.      *
  436.      * @return string $lastname
  437.      */
  438.     public function getLastname()
  439.     {
  440.         return $this->lastname;
  441.     }
  442.  
  443.     /**
  444.      * Set email
  445.      *
  446.      * @param string $email
  447.      */
  448.     public function setEmail($email)
  449.     {
  450.         $this->email = $email;
  451.     }
  452.  
  453.     /**
  454.      * Get email
  455.      *
  456.      * @return string $email
  457.      */
  458.     public function getEmail()
  459.     {
  460.         return $this->email;
  461.     }
  462.  
  463.     /**
  464.      * Set passwd
  465.      *
  466.      * @param string $passwd
  467.      */
  468.     public function setPassword($password)
  469.     {
  470.         $this->password = $password;
  471.     }
  472.  
  473.     /**
  474.      * Get passwd
  475.      *
  476.      * @return string $passwd
  477.      */
  478.     public function getPassword()
  479.     {
  480.         return $this->password;
  481.     }
  482.    
  483.     public function getPlainPassword()
  484.     {
  485.         return $this->plainPassword;
  486.     }
  487.     /**
  488.      * Set birthday
  489.      *
  490.      * @param datetime $birthday
  491.      */
  492.     public function setBirthday($birthday)
  493.     {
  494.         $this->birthday = $birthday;
  495.     }
  496.  
  497.     /**
  498.      * Get birthday
  499.      *
  500.      * @return datetime $birthday
  501.      */
  502.     public function getBirthday()
  503.     {
  504.         return $this->birthday;
  505.     }
  506.  
  507.     /**
  508.      * Set weight
  509.      *
  510.      * @param float $weight
  511.      */
  512.     public function setWeight($weight)
  513.     {
  514.         $this->weight = $weight;
  515.     }
  516.  
  517.     /**
  518.      * Get weight
  519.      *
  520.      * @return float $weight
  521.      */
  522.     public function getWeight()
  523.     {
  524.         return $this->weight;
  525.     }
  526.  
  527.     /**
  528.      * Set height
  529.      *
  530.      * @param float $height
  531.      */
  532.     public function setHeight($height)
  533.     {
  534.         $this->height = $height;
  535.     }
  536.  
  537.     /**
  538.      * Get height
  539.      *
  540.      * @return float $height
  541.      */
  542.     public function getHeight()
  543.     {
  544.         return $this->height;
  545.     }
  546.  
  547.     /**
  548.      * Set url
  549.      *
  550.      * @param string $url
  551.      */
  552.     public function setUrl($url)
  553.     {
  554.         $this->url = $url;
  555.     }
  556.  
  557.     /**
  558.      * Get url
  559.      *
  560.      * @return string $url
  561.      */
  562.     public function getUrl()
  563.     {
  564.         return $this->url;
  565.     }
  566.  
  567.     /**
  568.      * Set description
  569.      *
  570.      * @param text $description
  571.      */
  572.     public function setDescription($description)
  573.     {
  574.         $this->description = $description;
  575.     }
  576.  
  577.     /**
  578.      * Get description
  579.      *
  580.      * @return text $description
  581.      */
  582.     public function getDescription()
  583.     {
  584.         return $this->description;
  585.     }
  586.  
  587.     /**
  588.      * Set licence
  589.      *
  590.      * @param string $licence
  591.      */
  592.     public function setLicence($licence)
  593.     {
  594.         $this->licence = $licence;
  595.     }
  596.  
  597.     /**
  598.      * Get licence
  599.      *
  600.      * @return string $licence
  601.      */
  602.     public function getLicence()
  603.     {
  604.         return $this->licence;
  605.     }
  606.    
  607.     /**
  608.      * @recaptcha:True
  609.      */
  610.     private $recaptcha;
  611.    
  612.     public function getRecaptcha() {
  613.         return $this->recaptcha;
  614.     }
  615.     public function setRecaptcha($recaptcha) {
  616.         $this->recaptcha = $recaptcha;
  617.     }
  618.    
  619.     /**
  620.      * Generate the confirmation Code
  621.      */
  622.     public function generateConfirmationCode()
  623.     {
  624.        $this->confirmationCode =  md5(microtime(TRUE)*100000);
  625.        
  626.     }
  627.     /**
  628.      * Generate the confirmation Code
  629.      * based on FOSUserBundle
  630.      */
  631.     public function generateLicence()
  632.     {
  633.         $this->licence = 'FSC'.rand();
  634.     }
  635.    
  636.    
  637.     /**
  638.      * @return the $tempEmail
  639.      */
  640.     public function getTempEmail() {
  641.         return $this->tempEmail;
  642.     }
  643.  
  644.     /**
  645.      * @param $tempEmail the $tempEmail to set
  646.      */
  647.     public function setTempEmail($tempEmail) {
  648.         $this->tempEmail = $tempEmail;
  649.     }
  650.     /**
  651.      * @return the $lastLogin
  652.      */
  653.     public function getLastLogin() {
  654.         return $this->lastLogin;
  655.     }
  656.  
  657.     /**
  658.      * @param $lastLogin the $lastLogin to set
  659.      */
  660.     public function setLastLogin(\DateTime $time) {
  661.         $this->lastLogin = $time;
  662.     }
  663.     /**
  664.      * @return the $cgu
  665.      */
  666.     public function getCgu() {
  667.         return $this->cgu;
  668.     }
  669.  
  670.     /**
  671.      * @param $cgu the $cgu to set
  672.      */
  673.     public function setCgu($cgu) {
  674.         $this->cgu = $cgu;
  675.     }
  676.    
  677.     /**
  678.      * @return the $confirmationCode
  679.      */
  680.     public function getConfirmationCode() {
  681.         return $this->confirmationCode;
  682.     }
  683.  
  684.     /**
  685.      * @param $confirmationCode the $confirmationCode to set
  686.      */
  687.     public function setConfirmationCode($confirmationCode) {
  688.         $this->confirmationCode = $confirmationCode;
  689.     }
  690.     /**
  691.      * @return the $oldPassword
  692.      */
  693.     public function getOldPassword() {
  694.         return $this->oldPassword;
  695.     }
  696.  
  697.     /**
  698.      * @param $oldPassword the $oldPassword to set
  699.      */
  700.     public function setOldPassword($oldPassword) {
  701.         $this->oldPassword = $oldPassword;
  702.     }
  703.     /**
  704.      * @return the $feet
  705.      */
  706.     public function getFeet() {
  707.         return $this->feet;
  708.     }
  709.  
  710.     /**
  711.      * @param $feet the $feet to set
  712.      */
  713.     public function setFeet($feet) {
  714.         $this->feet = $feet;
  715.     }
  716.  
  717.     /**
  718.      * @return the $position
  719.      */
  720.     public function getPosition() {
  721.         return $this->position;
  722.     }
  723.  
  724.     /**
  725.      * @param $position the $position to set
  726.      */
  727.     public function setPosition($position) {
  728.         $this->position = $position;
  729.     }
  730.  
  731.     /**
  732.      * Fonction permettant de tester si une demande d'amis éxiste déja entre le user connecter et celui courant
  733.      * Fonction utilisé dans les templates afin de tester l'affichage des liens de demande d'amis
  734.      */
  735.     public function friendRequestExist($userDest){
  736.         return $this->getEm()->getRepository('FSCModelBundle:Link')->friendRequestExist($this,$userDest);
  737.     }
  738. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement