nineskeletor/src/Entity/Registration.php

449 lines
8.9 KiB
PHP
Executable File

<?php
namespace App\Entity;
use App\Validator;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\LegacyPasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
* @ORM\Entity(repositoryClass="App\Repository\RegistrationRepository")
*
* @UniqueEntity(fields="username", message="Un utilisateur existe déjà avec ce login.")
* @UniqueEntity(fields="email", message="Un utilisateur existe déjà avec ce mail.")
*/
class Registration implements UserInterface, LegacyPasswordAuthenticatedUserInterface
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=128, unique=true)
* @Validator\Userusername()
*/
private $username;
/**
* @ORM\Column(type="string", length=250, nullable=true)
*/
private $firstname;
/**
* @ORM\Column(type="string", length=250, nullable=true)
*/
private $lastname;
/**
* @ORM\Column(type="string", length=250)
*/
private $password;
/**
* @Validator\Password()
*/
private $passwordplain;
/**
* @ORM\Column(type="string", length=250)
*/
private $salt;
/**
* @ORM\Column(type="string", length=128, unique=true)
*/
private $email;
/**
* @ORM\Column(type="boolean")
*/
protected $isvisible;
/**
* @ORM\Column(type="string", length=250, nullable=true)
*/
private $postaladress;
/**
* @ORM\Column(type="string", length=60, nullable=true)
*/
private $telephonenumber;
/**
* @ORM\Column(type="string", length=250, nullable=true)
*/
private $job;
/**
* @ORM\Column(type="string", length=250, nullable=true)
*/
private $position;
/**
* @ORM\Column(name="motivation", type="text", nullable=true)
*/
private $motivation;
/**
* @ORM\Column(name="note", type="text", nullable=true)
*/
private $note;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $keyexpire;
/**
* @ORM\Column(type="string", length=60, nullable=true)
*/
private $keyvalue;
/**
* @ORM\Column(type="integer", length=60, nullable=false)
*/
private $statut;
/**
* @ORM\ManyToOne(targetEntity="Niveau01", inversedBy="registrations")
* @ORM\JoinColumn(nullable=false)
*/
private $niveau01;
/**
* @ORM\ManyToOne(targetEntity="Niveau02", inversedBy="registrations")
*/
private $niveau02;
/**
* @ORM\ManyToOne(targetEntity="Niveau03", inversedBy="registrations")
*/
private $niveau03;
/**
* @ORM\ManyToOne(targetEntity="Niveau04", inversedBy="registrations")
*/
private $niveau04;
// == CODE A NE PAS REGENERER
private $roles;
public function getUserIdentifier(): string
{
return $this->username;
}
public function setPasswordDirect($password)
{
// Permet de setter le password généré lors de l'inscription
$this->password = $password;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword($password): self
{
if ($password != $this->password && '' != $password) {
// Placer le password non encodé dans une variable tempo sur laquel on va appliquer la contraite de form
$this->passwordplain = $password;
// Password encrypté format openldap
$this->salt = uniqid(mt_rand(), true);
$hash = '{SSHA}'.base64_encode(pack('H*', sha1($password.$this->salt)).$this->salt);
$this->password = $hash;
}
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return $this->salt;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
$this->passwordplain = null;
}
public function getRoles(): array
{
return $this->roles;
}
public function hasRole(string $role): ?bool
{
return in_array($role, $this->getRoles());
}
public function setRole(string $role): self
{
if (!$this->hasRole($role)) {
array_push($this->roles, $role);
}
return $this;
}
public function getDisplayname()
{
return $this->firstname.' '.$this->lastname;
}
// == FIN DU CODE A NE PAS REGENERER
public function getId(): ?int
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(?string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(?string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function setSalt(string $salt): self
{
$this->salt = $salt;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function isIsvisible(): ?bool
{
return $this->isvisible;
}
public function setIsvisible(bool $isvisible): self
{
$this->isvisible = $isvisible;
return $this;
}
public function getPostaladress(): ?string
{
return $this->postaladress;
}
public function setPostaladress(?string $postaladress): self
{
$this->postaladress = $postaladress;
return $this;
}
public function getTelephonenumber(): ?string
{
return $this->telephonenumber;
}
public function setTelephonenumber(?string $telephonenumber): self
{
$this->telephonenumber = $telephonenumber;
return $this;
}
public function getJob(): ?string
{
return $this->job;
}
public function setJob(?string $job): self
{
$this->job = $job;
return $this;
}
public function getPosition(): ?string
{
return $this->position;
}
public function setPosition(?string $position): self
{
$this->position = $position;
return $this;
}
public function getMotivation(): ?string
{
return $this->motivation;
}
public function setMotivation(?string $motivation): self
{
$this->motivation = $motivation;
return $this;
}
public function getNote(): ?string
{
return $this->note;
}
public function setNote(?string $note): self
{
$this->note = $note;
return $this;
}
public function getKeyexpire(): ?\DateTimeInterface
{
return $this->keyexpire;
}
public function setKeyexpire(?\DateTimeInterface $keyexpire): self
{
$this->keyexpire = $keyexpire;
return $this;
}
public function getKeyvalue(): ?string
{
return $this->keyvalue;
}
public function setKeyvalue(?string $keyvalue): self
{
$this->keyvalue = $keyvalue;
return $this;
}
public function getStatut(): ?int
{
return $this->statut;
}
public function setStatut(int $statut): self
{
$this->statut = $statut;
return $this;
}
public function getNiveau01(): ?Niveau01
{
return $this->niveau01;
}
public function setNiveau01(?Niveau01 $niveau01): self
{
$this->niveau01 = $niveau01;
return $this;
}
public function getNiveau02(): ?Niveau02
{
return $this->niveau02;
}
public function setNiveau02(?Niveau02 $niveau02): self
{
$this->niveau02 = $niveau02;
return $this;
}
public function getNiveau03(): ?Niveau03
{
return $this->niveau03;
}
public function setNiveau03(?Niveau03 $niveau03): self
{
$this->niveau03 = $niveau03;
return $this;
}
public function getNiveau04(): ?Niveau04
{
return $this->niveau04;
}
public function setNiveau04(?Niveau04 $niveau04): self
{
$this->niveau04 = $niveau04;
return $this;
}
}