Commit 7a175310 authored by reminec's avatar reminec
Browse files

Login by username or email. Username not mandatory. Private integer id to...

Login by username or email. Username not mandatory. Private integer id to DBMS. Public uuid to resource identifier with Ramsey\Uuid
parent 7ea034d0
Pipeline #343038 failed with stage
in 2 minutes and 11 seconds
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "8806c3d2fa5420c7c7a63be8664dfaef",
"content-hash": "7ba34acd06a76b8be1ff1abec931ce76",
"packages": [
{
"name": "api-platform/api-pack",
......@@ -2124,44 +2124,46 @@
},
{
"name": "ramsey/uuid",
"version": "3.8.0",
"version": "3.9.3",
"source": {
"type": "git",
"url": "https://github.com/ramsey/uuid.git",
"reference": "d09ea80159c1929d75b3f9c60504d613aeb4a1e3"
"reference": "7e1633a6964b48589b142d60542f9ed31bd37a92"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ramsey/uuid/zipball/d09ea80159c1929d75b3f9c60504d613aeb4a1e3",
"reference": "d09ea80159c1929d75b3f9c60504d613aeb4a1e3",
"url": "https://api.github.com/repos/ramsey/uuid/zipball/7e1633a6964b48589b142d60542f9ed31bd37a92",
"reference": "7e1633a6964b48589b142d60542f9ed31bd37a92",
"shasum": ""
},
"require": {
"paragonie/random_compat": "^1.0|^2.0|9.99.99",
"php": "^5.4 || ^7.0",
"ext-json": "*",
"paragonie/random_compat": "^1 | ^2 | 9.99.99",
"php": "^5.4 | ^7 | ^8",
"symfony/polyfill-ctype": "^1.8"
},
"replace": {
"rhumsaa/uuid": "self.version"
},
"require-dev": {
"codeception/aspect-mock": "^1.0 | ~2.0.0",
"doctrine/annotations": "~1.2.0",
"goaop/framework": "1.0.0-alpha.2 | ^1.0 | ~2.1.0",
"ircmaxell/random-lib": "^1.1",
"jakub-onderka/php-parallel-lint": "^0.9.0",
"mockery/mockery": "^0.9.9",
"codeception/aspect-mock": "^1 | ^2",
"doctrine/annotations": "^1.2",
"goaop/framework": "1.0.0-alpha.2 | ^1 | ^2.1",
"jakub-onderka/php-parallel-lint": "^1",
"mockery/mockery": "^0.9.11 | ^1",
"moontoast/math": "^1.1",
"php-mock/php-mock-phpunit": "^0.3|^1.1",
"phpunit/phpunit": "^4.7|^5.0|^6.5",
"squizlabs/php_codesniffer": "^2.3"
"paragonie/random-lib": "^2",
"php-mock/php-mock-phpunit": "^0.3 | ^1.1",
"phpunit/phpunit": "^4.8 | ^5.4 | ^6.5",
"squizlabs/php_codesniffer": "^3.5"
},
"suggest": {
"ext-ctype": "Provides support for PHP Ctype functions",
"ext-libsodium": "Provides the PECL libsodium extension for use with the SodiumRandomGenerator",
"ext-openssl": "Provides the OpenSSL extension for use with the OpenSslGenerator",
"ext-uuid": "Provides the PECL UUID extension for use with the PeclUuidTimeGenerator and PeclUuidRandomGenerator",
"ircmaxell/random-lib": "Provides RandomLib for use with the RandomLibAdapter",
"moontoast/math": "Provides support for converting UUID to 128-bit integer (in string form).",
"paragonie/random-lib": "Provides RandomLib for use with the RandomLibAdapter",
"ramsey/uuid-console": "A console application for generating UUIDs with ramsey/uuid",
"ramsey/uuid-doctrine": "Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type."
},
......@@ -2174,13 +2176,21 @@
"autoload": {
"psr-4": {
"Ramsey\\Uuid\\": "src/"
}
},
"files": [
"src/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Ben Ramsey",
"email": "ben@benramsey.com",
"homepage": "https://benramsey.com"
},
{
"name": "Marijn Huizendveld",
"email": "marijn.huizendveld@gmail.com"
......@@ -2188,11 +2198,6 @@
{
"name": "Thibaud Fabre",
"email": "thibaud@aztech.io"
},
{
"name": "Ben Ramsey",
"email": "ben@benramsey.com",
"homepage": "https://benramsey.com"
}
],
"description": "Formerly rhumsaa/uuid. A PHP 5.4+ library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID).",
......@@ -2202,7 +2207,7 @@
"identifier",
"uuid"
],
"time": "2018-07-19T23:38:55+00:00"
"time": "2020-02-21T04:36:14+00:00"
},
{
"name": "ramsey/uuid-doctrine",
......
......@@ -5,7 +5,6 @@ security:
app_user_provider:
entity:
class: App\Entity\User
property: email
encoders:
App\Entity\User:
......
......@@ -3,12 +3,13 @@
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Serializer\Annotation\Groups;
......@@ -49,18 +50,23 @@ class Poll
/**
* @var UuidInterface
* @var int|null
* @ApiProperty(identifier=false)
*
* @Groups({"Poll:read"})
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var UuidInterface|null
* @ApiProperty(identifier=true)
* @ORM\Column(type="uuid", unique=true)
* @Groups({"Poll:read"})
*/
public $uuid;
/**
* @Groups({"Poll:create", "Poll:read", "Poll:update"})
* @ORM\Column(type="string", length=142)
......@@ -87,13 +93,19 @@ class Poll
public function __construct()
{
$this->proposals = new ArrayCollection();
$this->uuid = Uuid::uuid4();
}
public function getId(): ?UuidInterface
public function getId(): ?int
{
return $this->id;
}
public function getUuid(): ?UuidInterface
{
return $this->uuid;
}
public function getTitle(): ?string
{
return $this->title;
......
......@@ -3,11 +3,12 @@
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Serializer\Annotation\Groups;
......@@ -35,16 +36,23 @@ use Symfony\Component\Serializer\Annotation\Groups;
class PollProposal
{
/**
* @var UuidInterface
* @var int|null
* @ApiProperty(identifier=false)
*
* @Groups({"PollProposal:read"})
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var UuidInterface|null
* @ApiProperty(identifier=true)
* @ORM\Column(type="uuid", unique=true)
* @Groups({"PollProposal:read"})
*/
public $uuid;
/**
* @Groups({"PollProposal:create", "PollProposal:read"})
* @ORM\Column(type="string", length=142)
......@@ -68,13 +76,19 @@ class PollProposal
public function __construct()
{
$this->votes = new ArrayCollection();
$this->uuid = Uuid::uuid4();
}
public function getId()
public function getId(): ?int
{
return $this->id;
}
public function getUuid(): ?UuidInterface
{
return $this->uuid;
}
public function getTitle(): ?string
{
return $this->title;
......
......@@ -3,9 +3,10 @@
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Serializer\Annotation\Groups;
......@@ -36,20 +37,27 @@ use Symfony\Component\Serializer\Annotation\Groups;
class PollProposalVote
{
/**
* @var UuidInterface
* @var int|null
* @ApiProperty(identifier=false)
*
* @Groups({"ProllProposalVote:read", "ProllProposalVote:read"})
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var UuidInterface|null
* @ApiProperty(identifier=true)
* @ORM\Column(type="uuid", unique=true)
* @Groups({"ProllProposalVote:read"})
*/
public $uuid;
/**
* The Majority Judgment Poll Proposal the author is giving a mention to.
*
* @Groups({"ProllProposalVote:create", "voProllProposalVotete:read"})
* @Groups({"ProllProposalVote:create", "ProllProposalVote:read"})
* @ORM\ManyToOne(targetEntity="PollProposal", inversedBy="votes")
* @ORM\JoinColumn(nullable=false)
*/
......@@ -77,14 +85,21 @@ class PollProposalVote
*/
private $elector;
public function __construct()
{
$this->uuid = Uuid::uuid4();
}
public function getId(): ?UuidInterface
public function getId(): ?int
{
return $this->id;
}
public function getUuid(): ?UuidInterface
{
return $this->uuid;
}
public function getProposal(): ?PollProposal
{
return $this->proposal;
......
......@@ -2,13 +2,16 @@
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\SerializedName;
......@@ -53,13 +56,23 @@ use Symfony\Component\Serializer\Annotation\SerializedName;
* )
*/
class User implements UserInterface
{
{
/**
* @var int|null
* @ApiProperty(identifier=false)
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
private $id;
/**
* @var UuidInterface|null
* @ApiProperty(identifier=true)
* @ORM\Column(type="uuid", unique=true)
* @Groups({"User:read"})
*/
public $uuid;
/**
* @ORM\Column(type="string", length=180, unique=true)
......@@ -69,6 +82,12 @@ class User implements UserInterface
*/
private $email;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"User:create", "User:read", "User:edit"})
*/
private $username;
/**
* @ORM\Column(type="json")
*/
......@@ -101,16 +120,11 @@ class User implements UserInterface
*/
private $votes;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"User:create", "User:read", "User:edit"})
*/
private $username;
public function __construct()
{
$this->polls = new ArrayCollection();
$this->votes = new ArrayCollection();
$this->uuid = Uuid::uuid4();
}
......@@ -119,6 +133,11 @@ class User implements UserInterface
return $this->id;
}
public function getUuid(): ?UuidInterface
{
return $this->uuid;
}
public function getEmail(): ?string
{
return $this->email;
......@@ -132,13 +151,19 @@ class User implements UserInterface
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string) $this->email;
return (string)$this->username;
}
public function setUsername(?string $username): self
{
$this->username = $username;
return $this;
}
/**
......@@ -197,8 +222,7 @@ class User implements UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
$this->plainPassword = null;
}
/**
......@@ -262,11 +286,4 @@ class User implements UserInterface
return $this;
}
public function setUsername(?string $username): self
{
$this->username = $username;
return $this;
}
}
......@@ -5,6 +5,7 @@ namespace App\Repository;
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
/**
* @method User|null find($id, $lockMode = null, $lockVersion = null)
......@@ -12,13 +13,29 @@ use Doctrine\Common\Persistence\ManagerRegistry;
* @method User[] findAll()
* @method User[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class UserRepository extends ServiceEntityRepository
class UserRepository extends ServiceEntityRepository implements UserLoaderInterface
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, User::class);
}
/**
* {@inheritdoc }
*/
public function loadUserByUsername($usernameOrEmail)
{
return $this->createQuery(
'SELECT u
FROM App\Entity\User u
WHERE u.username = :query
OR u.email = :query'
)
->setParameter('query', $usernameOrEmail)
->getQuery()
->getOneOrNullResult();
}
// /**
// * @return User[] Returns an array of User objects
// */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment