Skip to content

Commit

Permalink
Rename Passwords => Password
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jul 19, 2023
1 parent d04ca04 commit 6d5469a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
22 changes: 11 additions & 11 deletions application/src/Controller/BackOfficeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Entity\Externalids;
use App\Entity\Medias;
use App\Entity\Passwords;
use App\Entity\Password;
use App\Entity\RoomMember;
use App\Entity\Rooms;
use App\Entity\Threepids;
Expand Down Expand Up @@ -62,22 +62,22 @@ public function backOfficeCreateAdmin(string $serverID, Request $request) : Json
}

// Process password.
$passwords = $entityManager->getRepository(Passwords::class)
$password = $entityManager->getRepository(Password::class)
->findOneBy(['userid' => $user->getId()]);
if (!$passwords) {
if (!$password) {
// 1. Generates and returns token as password.
// 2. Generates and returns token pattern.
$password = $this->hashPassword('password', null, true);
$newpassword = $this->hashPassword('password', null, true);

// New user, or existing user without any associated Tokens.
$passwords = new Passwords();
$passwords->setPassword($password['token']);
$passwords->setServerid($serverID);
$password = new Password();
$password->setPassword($newpassword['token']);
$password->setServerid($serverID);

$user->addPasswords($passwords);
$user->setPasswordpattern($password['pattern']);
$passwords->setUserid($user);
$entityManager->persist($passwords);
$user->addPassword($password);
$user->setPasswordpattern($newpassword['pattern']);
$password->setUserid($user);
$entityManager->persist($password);
}
$entityManager->persist($user);
$entityManager->flush();
Expand Down
4 changes: 2 additions & 2 deletions application/src/Controller/MatrixController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Controller;

use App\Entity\Passwords;
use App\Entity\Password;
use App\Entity\Rooms;
use App\Entity\RoomMember;
use App\Entity\Tokens;
Expand Down Expand Up @@ -130,7 +130,7 @@ public function login(string $serverID, Request $request): JsonResponse {

$passwordpatter = $user ? $user->getPasswordpattern() : null;
$userid = $user ? $user->getId() : null;
$password = $entityManager->getRepository(Passwords::class)->findOneBy([
$password = $entityManager->getRepository(Password::class)->findOneBy([
'password' => $this->hashPassword($payload->password, $passwordpatter)['token'],
'userid' => $userid
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace App\Entity;

use App\Repository\PasswordsRepository;
use App\Repository\PasswordRepository;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity(repositoryClass=PasswordsRepository::class)
* @ORM\Entity(repositoryClass=PasswordRepository::class)
*/
class Passwords
class Password
{
/**
* @ORM\Id
Expand Down
6 changes: 3 additions & 3 deletions application/src/Entity/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Users
private $tokens;

/**
* @ORM\OneToMany(targetEntity=Passwords::class, mappedBy="userid", cascade={"persist", "remove"})
* @ORM\OneToMany(targetEntity=Password::class, mappedBy="userid", cascade={"persist", "remove"})
*/
private $passwords;

Expand Down Expand Up @@ -252,14 +252,14 @@ public function addToken(Tokens $token): self
}

/**
* @return Collection<Passwords>
* @return Collection<Password>
*/
public function getPasswords(): Collection
{
return $this->passwords;
}

public function addPasswords(Passwords $password): self
public function addPassword(Password $password): self
{
$password->setUserid($this);
$this->passwords->add($password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@

namespace App\Repository;

use App\Entity\Passwords;
use App\Entity\Password;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Doctrine\Persistence\ManagerRegistry;

/**
* @extends ServiceEntityRepository<Passwords>
* @extends ServiceEntityRepository<Password>
*
* @method Passwords|null find($id, $lockMode = null, $lockVersion = null)
* @method Passwords|null findOneBy(array $criteria, array $orderBy = null)
* @method Passwords[] findAll()
* @method Passwords[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
* @method Password|null find($id, $lockMode = null, $lockVersion = null)
* @method Password|null findOneBy(array $criteria, array $orderBy = null)
* @method Password[] findAll()
* @method Password[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class PasswordsRepository extends ServiceEntityRepository
class PasswordRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Passwords::class);
parent::__construct($registry, Password::class);
}

/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function add(Passwords $entity, bool $flush = true): void
public function add(Password $entity, bool $flush = true): void
{
$this->_em->persist($entity);
if ($flush) {
Expand All @@ -39,7 +39,7 @@ public function add(Passwords $entity, bool $flush = true): void
* @throws ORMException
* @throws OptimisticLockException
*/
public function remove(Passwords $entity, bool $flush = true): void
public function remove(Password $entity, bool $flush = true): void
{
$this->_em->remove($entity);
if ($flush) {
Expand Down

0 comments on commit 6d5469a

Please sign in to comment.