Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $loggedAs = $this->getUser();
- $avatar_profile = $loggedAs->getAvatarPath();
- $em = $this->getDoctrine()->getManager();
- $form = $this->createForm(ProfileModificationType::class, $loggedAs);
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
- /**
- * @var UploadedFile $file
- */
- $file = $form->get('avatarPath')->getData();
- if ($file != NULL) {
- $fileName = md5(uniqid()) . '.' . $file->guessExtension();
- $file->move(
- $this->getParameter('image_directory'), $fileName
- );
- $loggedAs->setAvatarPath($fileName);
- } else {
- $loggedAs->setAvatarPath($avatar_profile);
- }
- $loggedAs->setSalt(md5(uniqid()));
- $loggedAs->setPassword($encoder->encodePassword($loggedAs, $loggedAs->getPassword()));
- $em->flush();
- $this->get('session')->getFlashBag()->add('success', "Votre compte a été modifié");
- ->add('avatarPath', FileType::class, array(
- 'data_class' => null,
- 'required' => false,
- 'label' => 'Avatar',
- 'constraints' => array(
- new AssertImage(array(
- 'maxHeight' => 600,
- 'maxWidth' => 600,
- 'maxSize' => 1000000,
- 'maxHeightMessage' => 'Longeur maximale de 600Px',
- 'maxWidthMessage' => 'Largeur maximale de 600Px',
- 'maxSizeMessage' => 'Taille maximale de 1Mo',
- ))),
- 'invalid_message' => 'Cette valeur est invalide',
- ));
- public static function loadValidatorMetadata(ClassMetadata $metadata)
- {
- $metadata->addPropertyConstraint('avatarPath', new AssertImage(array(
- 'maxHeight' => 600,
- 'maxWidth' => 600,
- 'maxSize' => 1000000,
- 'maxHeightMessage' => 'Longeur maximale de 600Px',
- 'maxWidthMessage' => 'Largeur maximale de 600Px',
- 'maxSizeMessage' => 'Taille maximale de 1Mo',
- )));
- }
- /**
- * @var string
- *
- * @ORMColumn(name="avatar_path", type="string", length=255, nullable=false)
- */
- private $avatarPath;
- /**
- * Profile
- *
- * @UniqueEntity(fields="email", message="Cette adresse mail est déjà
- utilisée")
- * @ORMTable(name="profile", uniqueConstraints=
- {@ORMUniqueConstraint(name="UNIQ_8157AA0FE7927C74", columns=
- {"email"})})
- *
- @ORMEntity(repositoryClass="AppBundleRepositoryProfileRepository")
- */
- class Profile implements UserInterface, Serializable
- {
- const ROLE_USER = 'ROLE_USER';
- const ROLE_ADMIN = 'ROLE_ADMIN';
- /**
- * @var integer
- *
- * @ORMColumn(name="id", type="integer", nullable=false)
- * @ORMId
- * @ORMGeneratedValue(strategy="IDENTITY")
- */
- private $id;
- /**
- * @var string
- *
- * @ORMColumn(name="salt", type="string", length=40)
- */
- private $salt;
- /**
- * @var string
- *
- * @ORMColumn(name="stripe_customer_id", type="string", length=100, nullable=true)
- */
- private $stripeCustomerId;
- /**
- * @var string
- *
- * @ORMColumn(name="first_name", type="string", length=25, nullable=false)
- */
- private $firstName;
- /**
- * @var string
- *
- * @ORMColumn(name="second_name", type="string", length=25, nullable=false)
- */
- private $secondName;
- /**
- * @var string
- *
- * @ORMColumn(name="society", type="string", length=30, nullable=false)
- */
- private $society;
- /**
- * @var string
- *
- * @ORMColumn(name="t_card", type="string", length=30, nullable=false)
- */
- private $tCard;
- /**
- * @var boolean
- *
- * @ORMColumn(name="t_card_propriety", type="boolean", nullable=true)
- */
- private $tCardPropriety;
- /**
- * @var string
- *
- * @ORMColumn(name="siret", type="string", length=25, nullable=false)
- */
- private $siret;
- /**
- * @var integer
- *
- * @ORMColumn(name="collaborators", type="integer", nullable=false)
- */
- private $collaborators;
- /**
- * @var string
- *
- * @ORMColumn(name="address", type="string", length=25, nullable=false)
- */
- private $address;
- /**
- * @var integer
- *
- * @ORMColumn(name="postal_code", type="integer", nullable=false)
- */
- private $postalCode;
- /**
- * @var string
- *
- * @ORMColumn(name="city", type="string", length=20, nullable=false)
- */
- private $city;
- /**
- * @var boolean
- *
- * @ORMColumn(name="software_solution", type="boolean", nullable=true)
- */
- private $softwareSolution;
- /**
- * @var string
- *
- * @ORMColumn(name="software_solution_name", type="string", length=255, nullable=true)
- */
- private $softwareSolutionName;
- /**
- * @var string
- *
- * @ORMColumn(name="avatar_path", type="string", length=255, nullable=false)
- */
- private $avatarPath;
- /**
- * @var DateTime
- *
- * @ORMColumn(name="last_connexion", type="datetime", nullable=false)
- */
- private $lastConnexion;
- /**
- * @var DateTime
- *
- * @ORMColumn(name="created_account", type="datetime", nullable=false)
- */
- private $createdAccount;
- /**
- * @var string
- *
- * @ORMColumn(name="email", type="string", length=60, nullable=false, unique=true)
- */
- private $email;
- /**
- * @var string
- *
- * @ORMColumn(name="password", type="text", nullable=false)
- * @AssertRegex(
- * pattern="/(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*])(?=.*[0-9]).{7,}/",
- * 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",
- * groups={"Default", "Patch"}
- * )
- */
- private $password;
- /**
- * @var array
- *
- * @ORMColumn(name="roles", type="simple_array", length=255, nullable=false)
- */
- private $roles;
- /**
- * @var integer
- *
- * @ORMColumn(name="mandates", type="integer", nullable=false)
- */
- private $mandates;
- /**
- * @var DateTime
- *
- * @ORMColumn(name="last_mandate", type="datetime", nullable=true)
- */
- private $lastMandate;
- /**
- * @var DateTime
- *
- * @ORMColumn(name="second_last_mandate", type="datetime", nullable=true)
- */
- private $secondLastMandate;
- /**
- * @var AppBundleEntityProfileStatus
- *
- * @ORMManyToOne(targetEntity="ProfileStatus")
- * @ORMJoinColumns({
- * @ORMJoinColumn(name="status", referencedColumnName="id")
- * })
- */
- private $status;
- /**
- * @var integer
- *
- * @ORMColumn(name="enabled", type="integer", nullable=false)
- */
- private $enabled;
- /**
- * @var integer
- *
- * @ORMColumn(name="phone", type="integer", nullable=true)
- */
- private $phone;
- /**
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * @param int $id
- */
- public function setId($id)
- {
- $this->id = $id;
- }
- /**
- * @return string
- */
- public function getFirstName()
- {
- return $this->firstName;
- }
- /**
- * @param string $firstName
- */
- public function setFirstName($firstName)
- {
- $this->firstName = $firstName;
- }
- /**
- * @return string
- */
- public function getSecondName()
- {
- return $this->secondName;
- }
- /**
- * @param string $secondName
- */
- public function setSecondName($secondName)
- {
- $this->secondName = $secondName;
- }
- /**
- * @return string
- */
- public function getSociety()
- {
- return $this->society;
- }
- /**
- * @param string $society
- */
- public function setSociety($society)
- {
- $this->society = $society;
- }
- /**
- * @return string
- */
- public function getTCard()
- {
- return $this->tCard;
- }
- /**
- * @param string $tCard
- */
- public function setTCard($tCard)
- {
- $this->tCard = $tCard;
- }
- /**
- * @return bool
- */
- public function isTCardPropriety()
- {
- return $this->tCardPropriety;
- }
- /**
- * @param bool $tCardPropriety
- */
- public function setTCardPropriety($tCardPropriety)
- {
- $this->tCardPropriety = $tCardPropriety;
- }
- /**
- * @return string
- */
- public function getSiret()
- {
- return $this->siret;
- }
- /**
- * @param string $siret
- */
- public function setSiret($siret)
- {
- $this->siret = $siret;
- }
- /**
- * @return int
- */
- public function getCollaborators()
- {
- return $this->collaborators;
- }
- /**
- * @param int $collaborators
- */
- public function setCollaborators($collaborators)
- {
- $this->collaborators = $collaborators;
- }
- /**
- * @return string
- */
- public function getAddress()
- {
- return $this->address;
- }
- /**
- * @param string $address
- */
- public function setAddress($address)
- {
- $this->address = $address;
- }
- /**
- * @return int
- */
- public function getPostalCode()
- {
- return $this->postalCode;
- }
- /**
- * @param int $postalCode
- */
- public function setPostalCode($postalCode)
- {
- $this->postalCode = $postalCode;
- }
- /**
- * @return string
- */
- public function getCity()
- {
- return $this->city;
- }
- /**
- * @param string $city
- */
- public function setCity($city)
- {
- $this->city = $city;
- }
- /**
- * @return bool
- */
- public function isSoftwareSolution()
- {
- return $this->softwareSolution;
- }
- /**
- * @param bool $softwareSolution
- */
- public function setSoftwareSolution($softwareSolution)
- {
- $this->softwareSolution = $softwareSolution;
- }
- /**
- * @return string
- */
- public function getSoftwareSolutionName()
- {
- return $this->softwareSolutionName;
- }
- /**
- * @param string $softwareSolutionName
- */
- public function setSoftwareSolutionName($softwareSolutionName)
- {
- $this->softwareSolutionName = $softwareSolutionName;
- }
- /**
- * @return string
- */
- public function getAvatarPath()
- {
- return $this->avatarPath;
- }
- /**
- * @param string $avatarPath
- */
- public function setAvatarPath($avatarPath)
- {
- $this->avatarPath = $avatarPath;
- }
- /**
- * @return DateTime
- */
- public function getLastConnexion()
- {
- return $this->lastConnexion;
- }
- /**
- * @param DateTime $lastConnexion
- */
- public function setLastConnexion($lastConnexion)
- {
- $this->lastConnexion = $lastConnexion;
- }
- /**
- * @return DateTime
- */
- public function getCreatedAccount()
- {
- return $this->createdAccount;
- }
- /**
- * @param DateTime $createdAccount
- */
- public function setCreatedAccount($createdAccount)
- {
- $this->createdAccount = $createdAccount;
- }
- /**
- * @return string
- */
- public function getEmail()
- {
- return $this->email;
- }
- /**
- * @param string $email
- */
- public function setEmail($email)
- {
- $this->email = $email;
- }
- /**
- * @return string
- */
- public function getPassword()
- {
- return $this->password;
- }
- /**
- * @param string $password
- */
- public function setPassword($password)
- {
- $this->password = $password;
- }
- /**
- * @return array
- */
- public function getRoles()
- {
- return $this->roles;
- }
- /**
- * @param array $roles
- */
- public function setRoles($roles)
- {
- $this->roles = $roles;
- }
- /**
- * @return int
- */
- public function getMandates()
- {
- return $this->mandates;
- }
- /**
- * @param int $mandates
- */
- public function setMandates($mandates)
- {
- $this->mandates = $mandates;
- }
- /**
- * @return DateTime
- */
- public function getLastMandate()
- {
- return $this->lastMandate;
- }
- /**
- * @param DateTime $lastMandate
- */
- public function setLastMandate($lastMandate)
- {
- $this->lastMandate = $lastMandate;
- }
- /**
- * @return DateTime
- */
- public function getSecondLastMandate()
- {
- return $this->secondLastMandate;
- }
- /**
- * @param DateTime $secondLastMandate
- */
- public function setSecondLastMandate($secondLastMandate)
- {
- $this->secondLastMandate = $secondLastMandate;
- }
- /**
- * @return string
- */
- public function getStatus()
- {
- return $this->status;
- }
- /**
- * @param string $status
- */
- public function setStatus($status)
- {
- $this->status = $status;
- }
- /**
- * @return int
- */
- public function getEnabled()
- {
- return $this->enabled;
- }
- /**
- * @param int $enabled
- */
- public function setEnabled($enabled)
- {
- $this->enabled = $enabled;
- }
- /**
- * @return int
- */
- public function getPhone()
- {
- return $this->phone;
- }
- /**
- * @param int $phone
- */
- public function setPhone($phone)
- {
- $this->phone = $phone;
- }
- /**
- * Removes sensitive data from the user.
- *
- * This is important if, at any given point, sensitive information like
- * the plain-text password is stored on this object.
- */
- public function eraseCredentials()
- {
- // TODO: Implement eraseCredentials() method.
- }
- /**
- * Returns the username used to authenticate the user.
- *
- * @return string The username
- */
- public function getUsername()
- {
- return $this->getEmail();
- }
- public static function loadValidatorMetadata(ClassMetadata $metadata)
- {
- $metadata->addPropertyConstraint('email', new AssertNotBlank(array(
- 'message' => 'Cette valeur ne doit pas être vide !',
- )));
- $metadata->addPropertyConstraint('password', new AssertNotBlank(array(
- 'message' => 'Cette valeur ne doit pas être vide !',
- )));
- $metadata->addPropertyConstraint('firstName', new AssertNotBlank(array(
- 'message' => 'Cette valeur ne doit pas être vide !',
- )));
- $metadata->addPropertyConstraint('secondName', new AssertNotBlank(array(
- 'message' => 'Cette valeur ne doit pas être vide !',
- )));
- $metadata->addPropertyConstraint('society', new AssertNotBlank(array(
- 'message' => 'Cette valeur ne doit pas être vide !',
- )));
- $metadata->addPropertyConstraint('avatarPath', new AssertImage(array(
- 'maxHeight' => 600,
- 'maxWidth' => 600,
- 'maxSize' => 1000000,
- 'maxHeightMessage' => 'Longeur maximale de 600Px',
- 'maxWidthMessage' => 'Largeur maximale de 600Px',
- 'maxSizeMessage' => 'Taille maximale de 1Mo',
- )));
- }
- /**
- * @return string
- */
- public function getSalt()
- {
- return $this->salt;
- }
- /**
- * @param string $salt
- */
- public function setSalt($salt)
- {
- $this->salt = $salt;
- }
- /**
- * @return string
- */
- public function getStripeCustomerId()
- {
- return $this->stripeCustomerId;
- }
- /**
- * @param string $stripeCustomerId
- */
- public function setStripeCustomerId($stripeCustomerId)
- {
- $this->stripeCustomerId = $stripeCustomerId;
- }
- /**
- * String representation of object
- * @link http://php.net/manual/en/serializable.serialize.php
- * @return string the string representation of the object or null
- * @since 5.1.0
- */
- public function serialize()
- {
- return serialize(array(
- $this->id,
- $this->firstName,
- $this->secondName,
- $this->society,
- $this->tCard,
- $this->tCardPropriety,
- $this->siret,
- $this->collaborators,
- $this->address,
- $this->postalCode,
- $this->city,
- //$this->softwareSolution,
- //$this->softwareSolutionName,
- $this->avatarPath,
- //$this->lastConnexion,
- //$this->createdAccount,
- $this->email,
- $this->password,
- //$this->roles,
- //$this->mandates,
- //$this->lastMandate,
- //$this->secondLastMandate,
- //$this->enabled,
- //$this->phone,
- //$this->status,
- //$this->salt,
- //$this->stripeCustomerId,
- ));
- }
- /**
- * Constructs the object
- * @link http://php.net/manual/en/serializable.unserialize.php
- * @param string $serialized <p>
- * The string representation of the object.
- * </p>
- * @return void
- * @since 5.1.0
- */
- public function unserialize($serialized)
- {
- list (
- $this->id,
- $this->firstName,
- $this->secondName,
- $this->society,
- $this->tCard,
- $this->siret,
- $this->tCardPropriety,
- $this->collaborators,
- $this->address,
- $this->postalCode,
- $this->city,
- //$this->softwareSolution,
- //$this->softwareSolutionName,
- $this->avatarPath,
- //$this->lastConnexion,
- //$this->createdAccount,
- $this->email,
- $this->password,
- //$this->roles,
- //$this->mandates,
- //$this->lastMandate,
- //$this->secondLastMandate,
- //$this->enabled,
- //$this->phone,
- //$this->status,
- //$this->salt,
- //$this->stripeCustomerId,
- ) = unserialize($serialized, array('allowed_classes' => false));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement