Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.14 KB | None | 0 0
  1. $loggedAs = $this->getUser();
  2. $avatar_profile = $loggedAs->getAvatarPath();
  3. $em = $this->getDoctrine()->getManager();
  4.  
  5. $form = $this->createForm(ProfileModificationType::class, $loggedAs);
  6. $form->handleRequest($request);
  7.  
  8. if ($form->isSubmitted() && $form->isValid()) {
  9. /**
  10. * @var UploadedFile $file
  11. */
  12. $file = $form->get('avatarPath')->getData();
  13. if ($file != NULL) {
  14. $fileName = md5(uniqid()) . '.' . $file->guessExtension();
  15.  
  16. $file->move(
  17. $this->getParameter('image_directory'), $fileName
  18. );
  19. $loggedAs->setAvatarPath($fileName);
  20. } else {
  21. $loggedAs->setAvatarPath($avatar_profile);
  22. }
  23. $loggedAs->setSalt(md5(uniqid()));
  24.  
  25. $loggedAs->setPassword($encoder->encodePassword($loggedAs, $loggedAs->getPassword()));
  26. $em->flush();
  27.  
  28. $this->get('session')->getFlashBag()->add('success', "Votre compte a été modifié");
  29.  
  30. ->add('avatarPath', FileType::class, array(
  31. 'data_class' => null,
  32. 'required' => false,
  33. 'label' => 'Avatar',
  34. 'constraints' => array(
  35. new AssertImage(array(
  36. 'maxHeight' => 600,
  37. 'maxWidth' => 600,
  38. 'maxSize' => 1000000,
  39. 'maxHeightMessage' => 'Longeur maximale de 600Px',
  40. 'maxWidthMessage' => 'Largeur maximale de 600Px',
  41. 'maxSizeMessage' => 'Taille maximale de 1Mo',
  42. ))),
  43. 'invalid_message' => 'Cette valeur est invalide',
  44. ));
  45.  
  46. public static function loadValidatorMetadata(ClassMetadata $metadata)
  47. {
  48. $metadata->addPropertyConstraint('avatarPath', new AssertImage(array(
  49. 'maxHeight' => 600,
  50. 'maxWidth' => 600,
  51. 'maxSize' => 1000000,
  52. 'maxHeightMessage' => 'Longeur maximale de 600Px',
  53. 'maxWidthMessage' => 'Largeur maximale de 600Px',
  54. 'maxSizeMessage' => 'Taille maximale de 1Mo',
  55. )));
  56. }
  57.  
  58. /**
  59. * @var string
  60. *
  61. * @ORMColumn(name="avatar_path", type="string", length=255, nullable=false)
  62. */
  63. private $avatarPath;
  64.  
  65. /**
  66. * Profile
  67. *
  68. * @UniqueEntity(fields="email", message="Cette adresse mail est déjà
  69. utilisée")
  70. * @ORMTable(name="profile", uniqueConstraints=
  71. {@ORMUniqueConstraint(name="UNIQ_8157AA0FE7927C74", columns=
  72. {"email"})})
  73. *
  74. @ORMEntity(repositoryClass="AppBundleRepositoryProfileRepository")
  75. */
  76. class Profile implements UserInterface, Serializable
  77. {
  78. const ROLE_USER = 'ROLE_USER';
  79. const ROLE_ADMIN = 'ROLE_ADMIN';
  80.  
  81. /**
  82. * @var integer
  83. *
  84. * @ORMColumn(name="id", type="integer", nullable=false)
  85. * @ORMId
  86. * @ORMGeneratedValue(strategy="IDENTITY")
  87. */
  88. private $id;
  89.  
  90. /**
  91. * @var string
  92. *
  93. * @ORMColumn(name="salt", type="string", length=40)
  94. */
  95. private $salt;
  96.  
  97. /**
  98. * @var string
  99. *
  100. * @ORMColumn(name="stripe_customer_id", type="string", length=100, nullable=true)
  101. */
  102. private $stripeCustomerId;
  103.  
  104. /**
  105. * @var string
  106. *
  107. * @ORMColumn(name="first_name", type="string", length=25, nullable=false)
  108. */
  109. private $firstName;
  110.  
  111. /**
  112. * @var string
  113. *
  114. * @ORMColumn(name="second_name", type="string", length=25, nullable=false)
  115. */
  116. private $secondName;
  117.  
  118. /**
  119. * @var string
  120. *
  121. * @ORMColumn(name="society", type="string", length=30, nullable=false)
  122. */
  123. private $society;
  124.  
  125. /**
  126. * @var string
  127. *
  128. * @ORMColumn(name="t_card", type="string", length=30, nullable=false)
  129. */
  130. private $tCard;
  131.  
  132. /**
  133. * @var boolean
  134. *
  135. * @ORMColumn(name="t_card_propriety", type="boolean", nullable=true)
  136. */
  137. private $tCardPropriety;
  138.  
  139. /**
  140. * @var string
  141. *
  142. * @ORMColumn(name="siret", type="string", length=25, nullable=false)
  143. */
  144. private $siret;
  145.  
  146. /**
  147. * @var integer
  148. *
  149. * @ORMColumn(name="collaborators", type="integer", nullable=false)
  150. */
  151. private $collaborators;
  152.  
  153. /**
  154. * @var string
  155. *
  156. * @ORMColumn(name="address", type="string", length=25, nullable=false)
  157. */
  158. private $address;
  159.  
  160. /**
  161. * @var integer
  162. *
  163. * @ORMColumn(name="postal_code", type="integer", nullable=false)
  164. */
  165. private $postalCode;
  166.  
  167. /**
  168. * @var string
  169. *
  170. * @ORMColumn(name="city", type="string", length=20, nullable=false)
  171. */
  172. private $city;
  173.  
  174. /**
  175. * @var boolean
  176. *
  177. * @ORMColumn(name="software_solution", type="boolean", nullable=true)
  178. */
  179. private $softwareSolution;
  180.  
  181. /**
  182. * @var string
  183. *
  184. * @ORMColumn(name="software_solution_name", type="string", length=255, nullable=true)
  185. */
  186. private $softwareSolutionName;
  187.  
  188. /**
  189. * @var string
  190. *
  191. * @ORMColumn(name="avatar_path", type="string", length=255, nullable=false)
  192. */
  193. private $avatarPath;
  194.  
  195. /**
  196. * @var DateTime
  197. *
  198. * @ORMColumn(name="last_connexion", type="datetime", nullable=false)
  199. */
  200. private $lastConnexion;
  201.  
  202. /**
  203. * @var DateTime
  204. *
  205. * @ORMColumn(name="created_account", type="datetime", nullable=false)
  206. */
  207. private $createdAccount;
  208.  
  209. /**
  210. * @var string
  211. *
  212. * @ORMColumn(name="email", type="string", length=60, nullable=false, unique=true)
  213. */
  214. private $email;
  215.  
  216. /**
  217. * @var string
  218. *
  219. * @ORMColumn(name="password", type="text", nullable=false)
  220. * @AssertRegex(
  221. * pattern="/(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*])(?=.*[0-9]).{7,}/",
  222. * message="Le mot de passe doit être constitué de 8 caratères, une majuscule, une minuscule, un caractère special et un chiffre au minimum",
  223. * groups={"Default", "Patch"}
  224. * )
  225. */
  226. private $password;
  227.  
  228. /**
  229. * @var array
  230. *
  231. * @ORMColumn(name="roles", type="simple_array", length=255, nullable=false)
  232. */
  233. private $roles;
  234.  
  235. /**
  236. * @var integer
  237. *
  238. * @ORMColumn(name="mandates", type="integer", nullable=false)
  239. */
  240. private $mandates;
  241.  
  242. /**
  243. * @var DateTime
  244. *
  245. * @ORMColumn(name="last_mandate", type="datetime", nullable=true)
  246. */
  247. private $lastMandate;
  248.  
  249. /**
  250. * @var DateTime
  251. *
  252. * @ORMColumn(name="second_last_mandate", type="datetime", nullable=true)
  253. */
  254. private $secondLastMandate;
  255.  
  256. /**
  257. * @var AppBundleEntityProfileStatus
  258. *
  259. * @ORMManyToOne(targetEntity="ProfileStatus")
  260. * @ORMJoinColumns({
  261. * @ORMJoinColumn(name="status", referencedColumnName="id")
  262. * })
  263. */
  264. private $status;
  265.  
  266. /**
  267. * @var integer
  268. *
  269. * @ORMColumn(name="enabled", type="integer", nullable=false)
  270. */
  271. private $enabled;
  272.  
  273. /**
  274. * @var integer
  275. *
  276. * @ORMColumn(name="phone", type="integer", nullable=true)
  277. */
  278. private $phone;
  279.  
  280. /**
  281. * @return int
  282. */
  283. public function getId()
  284. {
  285. return $this->id;
  286. }
  287.  
  288. /**
  289. * @param int $id
  290. */
  291. public function setId($id)
  292. {
  293. $this->id = $id;
  294. }
  295.  
  296. /**
  297. * @return string
  298. */
  299. public function getFirstName()
  300. {
  301. return $this->firstName;
  302. }
  303.  
  304. /**
  305. * @param string $firstName
  306. */
  307. public function setFirstName($firstName)
  308. {
  309. $this->firstName = $firstName;
  310. }
  311.  
  312. /**
  313. * @return string
  314. */
  315. public function getSecondName()
  316. {
  317. return $this->secondName;
  318. }
  319.  
  320. /**
  321. * @param string $secondName
  322. */
  323. public function setSecondName($secondName)
  324. {
  325. $this->secondName = $secondName;
  326. }
  327.  
  328. /**
  329. * @return string
  330. */
  331. public function getSociety()
  332. {
  333. return $this->society;
  334. }
  335.  
  336. /**
  337. * @param string $society
  338. */
  339. public function setSociety($society)
  340. {
  341. $this->society = $society;
  342. }
  343.  
  344. /**
  345. * @return string
  346. */
  347. public function getTCard()
  348. {
  349. return $this->tCard;
  350. }
  351.  
  352. /**
  353. * @param string $tCard
  354. */
  355. public function setTCard($tCard)
  356. {
  357. $this->tCard = $tCard;
  358. }
  359.  
  360. /**
  361. * @return bool
  362. */
  363. public function isTCardPropriety()
  364. {
  365. return $this->tCardPropriety;
  366. }
  367.  
  368. /**
  369. * @param bool $tCardPropriety
  370. */
  371. public function setTCardPropriety($tCardPropriety)
  372. {
  373. $this->tCardPropriety = $tCardPropriety;
  374. }
  375.  
  376. /**
  377. * @return string
  378. */
  379. public function getSiret()
  380. {
  381. return $this->siret;
  382. }
  383.  
  384. /**
  385. * @param string $siret
  386. */
  387. public function setSiret($siret)
  388. {
  389. $this->siret = $siret;
  390. }
  391.  
  392. /**
  393. * @return int
  394. */
  395. public function getCollaborators()
  396. {
  397. return $this->collaborators;
  398. }
  399.  
  400. /**
  401. * @param int $collaborators
  402. */
  403. public function setCollaborators($collaborators)
  404. {
  405. $this->collaborators = $collaborators;
  406. }
  407.  
  408. /**
  409. * @return string
  410. */
  411. public function getAddress()
  412. {
  413. return $this->address;
  414. }
  415.  
  416. /**
  417. * @param string $address
  418. */
  419. public function setAddress($address)
  420. {
  421. $this->address = $address;
  422. }
  423.  
  424. /**
  425. * @return int
  426. */
  427. public function getPostalCode()
  428. {
  429. return $this->postalCode;
  430. }
  431.  
  432. /**
  433. * @param int $postalCode
  434. */
  435. public function setPostalCode($postalCode)
  436. {
  437. $this->postalCode = $postalCode;
  438. }
  439.  
  440. /**
  441. * @return string
  442. */
  443. public function getCity()
  444. {
  445. return $this->city;
  446. }
  447.  
  448. /**
  449. * @param string $city
  450. */
  451. public function setCity($city)
  452. {
  453. $this->city = $city;
  454. }
  455.  
  456. /**
  457. * @return bool
  458. */
  459. public function isSoftwareSolution()
  460. {
  461. return $this->softwareSolution;
  462. }
  463.  
  464. /**
  465. * @param bool $softwareSolution
  466. */
  467. public function setSoftwareSolution($softwareSolution)
  468. {
  469. $this->softwareSolution = $softwareSolution;
  470. }
  471.  
  472. /**
  473. * @return string
  474. */
  475. public function getSoftwareSolutionName()
  476. {
  477. return $this->softwareSolutionName;
  478. }
  479.  
  480. /**
  481. * @param string $softwareSolutionName
  482. */
  483. public function setSoftwareSolutionName($softwareSolutionName)
  484. {
  485. $this->softwareSolutionName = $softwareSolutionName;
  486. }
  487.  
  488. /**
  489. * @return string
  490. */
  491. public function getAvatarPath()
  492. {
  493. return $this->avatarPath;
  494. }
  495.  
  496. /**
  497. * @param string $avatarPath
  498. */
  499. public function setAvatarPath($avatarPath)
  500. {
  501. $this->avatarPath = $avatarPath;
  502. }
  503.  
  504. /**
  505. * @return DateTime
  506. */
  507. public function getLastConnexion()
  508. {
  509. return $this->lastConnexion;
  510. }
  511.  
  512. /**
  513. * @param DateTime $lastConnexion
  514. */
  515. public function setLastConnexion($lastConnexion)
  516. {
  517. $this->lastConnexion = $lastConnexion;
  518. }
  519.  
  520. /**
  521. * @return DateTime
  522. */
  523. public function getCreatedAccount()
  524. {
  525. return $this->createdAccount;
  526. }
  527.  
  528. /**
  529. * @param DateTime $createdAccount
  530. */
  531. public function setCreatedAccount($createdAccount)
  532. {
  533. $this->createdAccount = $createdAccount;
  534. }
  535.  
  536. /**
  537. * @return string
  538. */
  539. public function getEmail()
  540. {
  541. return $this->email;
  542. }
  543.  
  544. /**
  545. * @param string $email
  546. */
  547. public function setEmail($email)
  548. {
  549. $this->email = $email;
  550. }
  551.  
  552. /**
  553. * @return string
  554. */
  555. public function getPassword()
  556. {
  557. return $this->password;
  558. }
  559.  
  560. /**
  561. * @param string $password
  562. */
  563. public function setPassword($password)
  564. {
  565. $this->password = $password;
  566. }
  567.  
  568. /**
  569. * @return array
  570. */
  571. public function getRoles()
  572. {
  573. return $this->roles;
  574. }
  575.  
  576. /**
  577. * @param array $roles
  578. */
  579. public function setRoles($roles)
  580. {
  581. $this->roles = $roles;
  582. }
  583.  
  584. /**
  585. * @return int
  586. */
  587. public function getMandates()
  588. {
  589. return $this->mandates;
  590. }
  591.  
  592. /**
  593. * @param int $mandates
  594. */
  595. public function setMandates($mandates)
  596. {
  597. $this->mandates = $mandates;
  598. }
  599.  
  600. /**
  601. * @return DateTime
  602. */
  603. public function getLastMandate()
  604. {
  605. return $this->lastMandate;
  606. }
  607.  
  608. /**
  609. * @param DateTime $lastMandate
  610. */
  611. public function setLastMandate($lastMandate)
  612. {
  613. $this->lastMandate = $lastMandate;
  614. }
  615.  
  616. /**
  617. * @return DateTime
  618. */
  619. public function getSecondLastMandate()
  620. {
  621. return $this->secondLastMandate;
  622. }
  623.  
  624. /**
  625. * @param DateTime $secondLastMandate
  626. */
  627. public function setSecondLastMandate($secondLastMandate)
  628. {
  629. $this->secondLastMandate = $secondLastMandate;
  630. }
  631.  
  632. /**
  633. * @return string
  634. */
  635. public function getStatus()
  636. {
  637. return $this->status;
  638. }
  639.  
  640. /**
  641. * @param string $status
  642. */
  643. public function setStatus($status)
  644. {
  645. $this->status = $status;
  646. }
  647.  
  648. /**
  649. * @return int
  650. */
  651. public function getEnabled()
  652. {
  653. return $this->enabled;
  654. }
  655.  
  656. /**
  657. * @param int $enabled
  658. */
  659. public function setEnabled($enabled)
  660. {
  661. $this->enabled = $enabled;
  662. }
  663.  
  664. /**
  665. * @return int
  666. */
  667. public function getPhone()
  668. {
  669. return $this->phone;
  670. }
  671.  
  672. /**
  673. * @param int $phone
  674. */
  675. public function setPhone($phone)
  676. {
  677. $this->phone = $phone;
  678. }
  679.  
  680. /**
  681. * Removes sensitive data from the user.
  682. *
  683. * This is important if, at any given point, sensitive information like
  684. * the plain-text password is stored on this object.
  685. */
  686. public function eraseCredentials()
  687. {
  688. // TODO: Implement eraseCredentials() method.
  689. }
  690.  
  691. /**
  692. * Returns the username used to authenticate the user.
  693. *
  694. * @return string The username
  695. */
  696. public function getUsername()
  697. {
  698. return $this->getEmail();
  699. }
  700.  
  701. public static function loadValidatorMetadata(ClassMetadata $metadata)
  702. {
  703. $metadata->addPropertyConstraint('email', new AssertNotBlank(array(
  704. 'message' => 'Cette valeur ne doit pas être vide !',
  705. )));
  706. $metadata->addPropertyConstraint('password', new AssertNotBlank(array(
  707. 'message' => 'Cette valeur ne doit pas être vide !',
  708. )));
  709. $metadata->addPropertyConstraint('firstName', new AssertNotBlank(array(
  710. 'message' => 'Cette valeur ne doit pas être vide !',
  711. )));
  712. $metadata->addPropertyConstraint('secondName', new AssertNotBlank(array(
  713. 'message' => 'Cette valeur ne doit pas être vide !',
  714. )));
  715. $metadata->addPropertyConstraint('society', new AssertNotBlank(array(
  716. 'message' => 'Cette valeur ne doit pas être vide !',
  717. )));
  718. $metadata->addPropertyConstraint('avatarPath', new AssertImage(array(
  719. 'maxHeight' => 600,
  720. 'maxWidth' => 600,
  721. 'maxSize' => 1000000,
  722. 'maxHeightMessage' => 'Longeur maximale de 600Px',
  723. 'maxWidthMessage' => 'Largeur maximale de 600Px',
  724. 'maxSizeMessage' => 'Taille maximale de 1Mo',
  725. )));
  726. }
  727.  
  728. /**
  729. * @return string
  730. */
  731. public function getSalt()
  732. {
  733. return $this->salt;
  734. }
  735.  
  736. /**
  737. * @param string $salt
  738. */
  739. public function setSalt($salt)
  740. {
  741. $this->salt = $salt;
  742. }
  743.  
  744. /**
  745. * @return string
  746. */
  747. public function getStripeCustomerId()
  748. {
  749. return $this->stripeCustomerId;
  750. }
  751.  
  752. /**
  753. * @param string $stripeCustomerId
  754. */
  755. public function setStripeCustomerId($stripeCustomerId)
  756. {
  757. $this->stripeCustomerId = $stripeCustomerId;
  758. }
  759.  
  760. /**
  761. * String representation of object
  762. * @link http://php.net/manual/en/serializable.serialize.php
  763. * @return string the string representation of the object or null
  764. * @since 5.1.0
  765. */
  766. public function serialize()
  767. {
  768. return serialize(array(
  769. $this->id,
  770. $this->firstName,
  771. $this->secondName,
  772. $this->society,
  773. $this->tCard,
  774. $this->tCardPropriety,
  775. $this->siret,
  776. $this->collaborators,
  777. $this->address,
  778. $this->postalCode,
  779. $this->city,
  780. //$this->softwareSolution,
  781. //$this->softwareSolutionName,
  782. $this->avatarPath,
  783. //$this->lastConnexion,
  784. //$this->createdAccount,
  785. $this->email,
  786. $this->password,
  787. //$this->roles,
  788. //$this->mandates,
  789. //$this->lastMandate,
  790. //$this->secondLastMandate,
  791. //$this->enabled,
  792. //$this->phone,
  793. //$this->status,
  794. //$this->salt,
  795. //$this->stripeCustomerId,
  796. ));
  797. }
  798.  
  799. /**
  800. * Constructs the object
  801. * @link http://php.net/manual/en/serializable.unserialize.php
  802. * @param string $serialized <p>
  803. * The string representation of the object.
  804. * </p>
  805. * @return void
  806. * @since 5.1.0
  807. */
  808. public function unserialize($serialized)
  809. {
  810. list (
  811. $this->id,
  812. $this->firstName,
  813. $this->secondName,
  814. $this->society,
  815. $this->tCard,
  816. $this->siret,
  817. $this->tCardPropriety,
  818. $this->collaborators,
  819. $this->address,
  820. $this->postalCode,
  821. $this->city,
  822. //$this->softwareSolution,
  823. //$this->softwareSolutionName,
  824. $this->avatarPath,
  825. //$this->lastConnexion,
  826. //$this->createdAccount,
  827. $this->email,
  828. $this->password,
  829. //$this->roles,
  830. //$this->mandates,
  831. //$this->lastMandate,
  832. //$this->secondLastMandate,
  833. //$this->enabled,
  834. //$this->phone,
  835. //$this->status,
  836. //$this->salt,
  837. //$this->stripeCustomerId,
  838. ) = unserialize($serialized, array('allowed_classes' => false));
  839. }
  840. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement