Guest User

Untitled

a guest
Dec 19th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.36 KB | None | 0 0
  1. public function api()
  2. {
  3. return new Response(sprintf('Logged in as %s', $this->getUser()->getUsername()));
  4. }
  5.  
  6. security:
  7. encoders:
  8. AppEntityUser:
  9. algorithm: bcrypt
  10. # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
  11. providers:
  12. entity_provider:
  13. entity:
  14. class: AppEntityUser
  15. property: username
  16. firewalls:
  17. dev:
  18. pattern: ^/(_(profiler|wdt)|css|images|js)/
  19. security: false
  20. # main:
  21. # anonymous: true
  22. login:
  23. pattern: ^/login
  24. stateless: true
  25. anonymous: true
  26. json_login:
  27. check_path: /login_check
  28. success_handler: lexik_jwt_authentication.handler.authentication_success
  29. failure_handler: lexik_jwt_authentication.handler.authentication_failure
  30.  
  31. register:
  32. pattern: ^/register
  33. stateless: true
  34. anonymous: true
  35.  
  36. api:
  37. pattern: ^/api
  38. stateless: true
  39. anonymous: false
  40. provider: entity_provider
  41. guard:
  42. authenticators:
  43. - lexik_jwt_authentication.jwt_token_authenticator
  44.  
  45. # activate different ways to authenticate
  46.  
  47. # http_basic: true
  48. # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
  49.  
  50. # form_login: true
  51. # https://symfony.com/doc/current/security/form_login_setup.html
  52.  
  53. # Easy way to control access for large sections of your site
  54. # Note: Only the *first* access control that matches will be used
  55. access_control:
  56. - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  57. - { path: ^/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  58. - { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
  59.  
  60. register:
  61. path: /register
  62. controller: AppControllerAuthController::register
  63. methods: POST
  64.  
  65. api:
  66. path: /api
  67. controller: AppControllerAuthController::api
  68.  
  69. login_check:
  70. path: /login_check
  71. methods: [POST]
  72.  
  73. <?php
  74.  
  75. namespace AppEntity;
  76.  
  77. use ApiPlatformCoreAnnotationApiFilter;
  78. use ApiPlatformCoreAnnotationApiProperty;
  79. use ApiPlatformCoreAnnotationApiSubresource;
  80. use DoctrineCommonCollectionsArrayCollection;
  81. use DoctrineCommonCollectionsCollection;
  82. use DoctrineORMMapping as ORM;
  83. use SymfonyComponentSecurityCoreUserUserInterface;
  84. use ApiPlatformCoreAnnotationApiResource;
  85. use SymfonyComponentSerializerAnnotationGroups;
  86. use ApiPlatformCoreBridgeDoctrineOrmFilterSearchFilter;
  87.  
  88. /**
  89. * @ORMEntity(repositoryClass="AppRepositoryUserRepository")
  90. * @ApiResource(normalizationContext={"groups"={"user"}})
  91. * @ApiFilter(SearchFilter::class, properties={"centres.id": "exact"})
  92. */
  93. class User implements UserInterface
  94. {
  95. /**
  96. * @ORMId()
  97. * @ORMGeneratedValue()
  98. * @ORMColumn(type="integer")
  99. * @Groups({"user"})
  100. */
  101. private $id;
  102.  
  103. /**
  104. * @ORMColumn(type="string", length=50, unique=true)
  105. * @Groups({"user"})
  106. */
  107. private $username;
  108.  
  109. /**
  110. * @ORMColumn(type="string", length=64)
  111. * @Groups({"user"})
  112. */
  113. private $password;
  114.  
  115. /**
  116. * @ORMColumn(type="string", length=50, nullable=true)
  117. * @Groups({"user"})
  118. */
  119. private $prenom;
  120.  
  121. /**
  122. * @ORMColumn(type="string", length=50, nullable=true)
  123. * @Groups({"user"})
  124. */
  125. private $nom;
  126.  
  127. /**
  128. * @ORMColumn(type="string", length=80, unique=true)
  129. * @Groups({"user"})
  130. */
  131. private $email;
  132.  
  133. /**
  134. * @ORMColumn(type="array")
  135. * @Groups({"user"})
  136. */
  137. private $roles = [];
  138.  
  139. /**
  140. * @ORMColumn(type="datetime", nullable=true)
  141. * @Groups({"user"})
  142. */
  143. private $dateNaissance;
  144.  
  145. /**
  146. * @ORMColumn(type="datetime")
  147. * @Groups({"user"})
  148. */
  149. private $dateEnregistrement;
  150.  
  151. /**
  152. * @ORMColumn(type="datetime", nullable=true)
  153. * @Groups({"user"})
  154. */
  155. private $dateDernierePartie;
  156.  
  157. /**
  158. * @ORMColumn(type="boolean")
  159. * @Groups({"user"})
  160. */
  161. private $actif;
  162.  
  163. /**
  164. * @ORMColumn(type="integer")
  165. * @Groups({"user"})
  166. */
  167. private $niveau;
  168.  
  169. /**
  170. * @ORMColumn(type="integer")
  171. * @Groups({"user"})
  172. */
  173. private $experience;
  174.  
  175. /**
  176. * @ORMColumn(type="integer")
  177. * @Groups({"user"})
  178. */
  179. private $nbVictimes;
  180.  
  181. /**
  182. * @ORMColumn(type="integer")
  183. * @Groups({"user"})
  184. */
  185. private $nbMorts;
  186.  
  187. /**
  188. * @ORMColumn(type="integer", nullable=true)
  189. * @Groups({"user"})
  190. */
  191. private $justesse;
  192.  
  193. /**
  194. * @ORMColumn(type="integer", nullable=true)
  195. * @Groups({"user"})
  196. */
  197. private $nbParties;
  198.  
  199. /**
  200. * @ORMOneToMany(targetEntity="AppEntityCarte", mappedBy="client")
  201. * @Groups({"user"})
  202. * @var Collection
  203. */
  204. private $cartes;
  205.  
  206. /**
  207. * @ORMManyToOne(targetEntity="AppEntityEquipe", inversedBy="joueurs")
  208. * @ORMJoinColumn(nullable=true)
  209. * @Groups({"user"})
  210. */
  211. private $equipe;
  212.  
  213. /**
  214. * @ORMManyToMany(targetEntity="AppEntityCentre", inversedBy="clients")
  215. * @ORMJoinTable(name="users_centres")
  216. * @var Collection
  217. * @Groups({"user"})
  218. */
  219. private $centres;
  220.  
  221. public function __construct()
  222. {
  223. $this->cartes = new ArrayCollection();
  224. $this->centres = new ArrayCollection();
  225. $this->actif = true;
  226. $this->niveau = 1;
  227. $this->experience = 0;
  228. $this->nbVictimes = 0;
  229. $this->nbMorts = 0;
  230. $this->justesse = 0;
  231. $this->nbParties = 0;
  232. $this->dateEnregistrement = new DateTime();
  233. }
  234.  
  235. /**
  236. * @param int|null $id
  237. * @param string $username
  238. * @param string $email
  239. * @param string $password
  240. * @param array $roles
  241. * @param DateTime|null $dateEnregistrement
  242. * @return User
  243. */
  244. static public function creer(
  245. ?int $id = null,
  246. string $username,
  247. string $email,
  248. string $password,
  249. array $roles,
  250. ?DateTime $dateEnregistrement = null
  251. )
  252. {
  253. $user = new self();
  254.  
  255. $user->id = $id;
  256. $user->username = $username;
  257. $user->email = $email;
  258. $user->password = $password;
  259. $user->roles = $roles;
  260. $user->dateEnregistrement = $dateEnregistrement;
  261.  
  262. return $user;
  263. }
  264.  
  265. public function addCarte(Carte $carte)
  266. {
  267. if ($this->cartes->contains($carte)) {
  268. return;
  269. }
  270. $this->cartes->add($carte);
  271. $carte->setClient($this);
  272. }
  273.  
  274. public function addCentre(Centre $centre)
  275. {
  276. if ($this->centres->contains($centre)) {
  277. return;
  278. }
  279.  
  280. $this->centres->add($centre);
  281. //$centre->inscrireJoueur($this);
  282. }
  283.  
  284. public function ajouterNbVictimes(int $nbVictimes)
  285. {
  286. $this->nbVictimes += $nbVictimes;
  287. }
  288.  
  289. public function ajouterJustesse(int $justesse)
  290. {
  291. $this->justesse += $justesse;
  292. }
  293.  
  294. public function diminuerJustesse(int $justesse)
  295. {
  296. $this->justesse -= $justesse;
  297. }
  298.  
  299. public function ajouterNbMorts(int $nbMorts)
  300. {
  301. $this->nbMorts += $nbMorts;
  302. }
  303.  
  304. public function getId(): ?int
  305. {
  306. return $this->id;
  307. }
  308.  
  309. public function setUsername(string $username): self
  310. {
  311. $this->username = $username;
  312.  
  313. return $this;
  314. }
  315.  
  316. public function getPassword(): ?string
  317. {
  318. return $this->password;
  319. }
  320.  
  321. public function setPassword(string $password): self
  322. {
  323. $this->password = $password;
  324.  
  325. return $this;
  326. }
  327.  
  328. public function getPrenom(): ?string
  329. {
  330. return $this->prenom;
  331. }
  332.  
  333. public function setPrenom(string $prenom): self
  334. {
  335. $this->prenom = $prenom;
  336.  
  337. return $this;
  338. }
  339.  
  340. public function getNom(): ?string
  341. {
  342. return $this->nom;
  343. }
  344.  
  345. public function setNom(string $nom): self
  346. {
  347. $this->nom = $nom;
  348.  
  349. return $this;
  350. }
  351.  
  352. public function getEmail(): ?string
  353. {
  354. return $this->email;
  355. }
  356.  
  357. public function setEmail(string $email): self
  358. {
  359. $this->email = $email;
  360.  
  361. return $this;
  362. }
  363.  
  364. public function getRoles(): ?array
  365. {
  366. return $this->roles;
  367. }
  368.  
  369. public function setRoles(array $roles): self
  370. {
  371. $this->roles = $roles;
  372.  
  373. return $this;
  374. }
  375.  
  376. public function getDateNaissance(): ?DateTimeInterface
  377. {
  378. return $this->dateNaissance;
  379. }
  380.  
  381. public function setDateNaissance(DateTimeInterface $dateNaissance): self
  382. {
  383. $this->dateNaissance = $dateNaissance;
  384.  
  385. return $this;
  386. }
  387.  
  388. public function getDateEnregistrement(): ?DateTimeInterface
  389. {
  390. return $this->dateEnregistrement;
  391. }
  392.  
  393. public function setDateEnregistrement(DateTimeInterface $dateEnregistrement): self
  394. {
  395. $this->dateEnregistrement = $dateEnregistrement;
  396.  
  397. return $this;
  398. }
  399.  
  400. public function getDateDernierePartie(): ?DateTimeInterface
  401. {
  402. return $this->dateDernierePartie;
  403. }
  404.  
  405. public function setDateDernierePartie(?DateTimeInterface $dateDernierePartie): self
  406. {
  407. $this->dateDernierePartie = $dateDernierePartie;
  408.  
  409. return $this;
  410. }
  411.  
  412. public function getActif(): ?bool
  413. {
  414. return $this->actif;
  415. }
  416.  
  417. public function setActif(bool $actif): self
  418. {
  419. $this->actif = $actif;
  420.  
  421. return $this;
  422. }
  423.  
  424. public function getNiveau(): ?int
  425. {
  426. return $this->niveau;
  427. }
  428.  
  429. public function setNiveau(int $niveau): self
  430. {
  431. $this->niveau = $niveau;
  432.  
  433. return $this;
  434. }
  435.  
  436. public function getExperience(): ?int
  437. {
  438. return $this->experience;
  439. }
  440.  
  441. public function setExperience(int $experience): self
  442. {
  443. $this->experience = $experience;
  444.  
  445. return $this;
  446. }
  447.  
  448. public function getNbVictimes(): ?int
  449. {
  450. return $this->nbVictimes;
  451. }
  452.  
  453. public function setNbVictimes(int $nbVictimes): self
  454. {
  455. $this->nbVictimes = $nbVictimes;
  456.  
  457. return $this;
  458. }
  459.  
  460. public function getNbMorts(): ?int
  461. {
  462. return $this->nbMorts;
  463. }
  464.  
  465. public function setNbMorts(int $nbMorts): self
  466. {
  467. $this->nbMorts = $nbMorts;
  468.  
  469. return $this;
  470. }
  471.  
  472. public function getJustesse(): ?int
  473. {
  474. return $this->justesse;
  475. }
  476.  
  477. public function setJustesse(int $justesse): self
  478. {
  479. $this->justesse = $justesse;
  480.  
  481. return $this;
  482. }
  483.  
  484. /**
  485. * @return mixed
  486. */
  487. public function getNbParties()
  488. {
  489. return $this->nbParties;
  490. }
  491.  
  492. /**
  493. * @param mixed $nbParties
  494. */
  495. public function setNbParties($nbParties): void
  496. {
  497. $this->nbParties = $nbParties;
  498. }
  499.  
  500. /**
  501. * @return mixed
  502. */
  503. public function getCartes()
  504. {
  505. return $this->cartes;
  506. }
  507.  
  508. /**
  509. * @param mixed $cartes
  510. */
  511. public function setCartes($cartes): void
  512. {
  513. $this->cartes = $cartes;
  514. }
  515.  
  516. /**
  517. * @return mixed
  518. */
  519. public function getEquipe()
  520. {
  521. return $this->equipe;
  522. }
  523.  
  524. /**
  525. * @param mixed $equipe
  526. */
  527. public function setEquipe($equipe): void
  528. {
  529. $this->equipe = $equipe;
  530. }
  531.  
  532. /**
  533. * @return mixed
  534. */
  535. public function getCentres()
  536. {
  537. return $this->centres;
  538. }
  539.  
  540. /**
  541. * @param mixed $centre
  542. */
  543. public function setCentres($centres): void
  544. {
  545. $this->centres = $centres;
  546. }
  547.  
  548. /**
  549. * Returns the salt that was originally used to encode the password.
  550. *
  551. * This can return null if the password was not encoded using a salt.
  552. *
  553. * @return string|null The salt
  554. */
  555. public function getSalt()
  556. {
  557. return null;
  558. }
  559.  
  560. /**
  561. * Returns the username used to authenticate the user.
  562. *
  563. * @return string The username
  564. */
  565. public function getUsername()
  566. {
  567. return $this->username;
  568. }
  569.  
  570. /**
  571. * Removes sensitive data from the user.
  572. *
  573. * This is important if, at any given point, sensitive information like
  574. * the plain-text password is stored on this object.
  575. */
  576. public function eraseCredentials()
  577. {
  578. }
  579. }
  580.  
  581. {
  582. "@context": "/api/contexts/Entrypoint",
  583. "@id": "/api",
  584. "@type": "Entrypoint",
  585. "user": "/api/users",
  586. "carte": "/api/cartes",
  587. "equipe": "/api/equipes",
  588. "centre": "/api/centres",
  589. "partie": "/api/parties"
  590. }
Add Comment
Please, Sign In to add comment