mirror of
https://github.com/kevinveenbirkenbach/coding-challenge-online-shop.git
synced 2024-11-01 00:53:10 +01:00
Added addUser function to repository
This commit is contained in:
parent
2e1394f96a
commit
80be8e7361
@ -55,6 +55,15 @@ final class User implements UserInterface
|
|||||||
$this->passwordHash = $hash;
|
$this->passwordHash = $hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In a real application you should use a salt ;)
|
||||||
|
* @param string $password
|
||||||
|
*/
|
||||||
|
public function setPasswordHashByPassword(string $password): void
|
||||||
|
{
|
||||||
|
$this->passwordHash = password_hash($password, PASSWORD_BCRYPT);
|
||||||
|
}
|
||||||
|
|
||||||
public function getEmail(): string
|
public function getEmail(): string
|
||||||
{
|
{
|
||||||
return $this->email;
|
return $this->email;
|
||||||
|
@ -18,6 +18,8 @@ interface UserInterface extends UniqueInterface
|
|||||||
*/
|
*/
|
||||||
public function setPasswordHash(string $hash):void;
|
public function setPasswordHash(string $hash):void;
|
||||||
|
|
||||||
|
public function setPasswordHashByPassword(string $password): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
28
src/repository/user/User.php
Normal file
28
src/repository/user/User.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
namespace repository\user;
|
||||||
|
|
||||||
|
use repository\AbstractRepository;
|
||||||
|
use entity\user\UserInterface as UserEntityInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author kevinfrantz
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
final class User extends AbstractRepository implements UserInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
public function addUser(UserEntityInterface $user): void
|
||||||
|
{
|
||||||
|
$statement = $this->database->prepare('INSERT INTO `user` (`name`, `email`, `hash`) VALUES (?, ?, ?);');
|
||||||
|
$statement->execute([
|
||||||
|
$user->getName(),
|
||||||
|
$user->getEmail(),
|
||||||
|
$user->getPasswordHash()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserByMailAndHash(string $mail, string $hash): UserEntityInterface
|
||||||
|
{}
|
||||||
|
}
|
||||||
|
|
@ -12,11 +12,6 @@ interface UserInterface
|
|||||||
{
|
{
|
||||||
public function addUser(UserEntityInterface $user):void;
|
public function addUser(UserEntityInterface $user):void;
|
||||||
|
|
||||||
/**
|
|
||||||
* This function just exist for maintaining reasons
|
|
||||||
*/
|
|
||||||
public function deleteAllUsers():void;
|
|
||||||
|
|
||||||
public function getUserByMailAndHash(string $mail,string $hash):UserEntityInterface;
|
public function getUserByMailAndHash(string $mail,string $hash):UserEntityInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
CREATE TABLE `test_db`.`user` (
|
CREATE TABLE `test_db`.`user` (
|
||||||
`id` INT NOT NULL AUTO_INCREMENT,
|
`id` INT NOT NULL AUTO_INCREMENT,
|
||||||
`name` VARCHAR(45) NULL,
|
`name` VARCHAR(120) NULL,
|
||||||
`email` VARCHAR(45) NULL,
|
`email` VARCHAR(120) NULL,
|
||||||
`hash` VARCHAR(45) NULL,
|
`hash` VARCHAR(60) NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE INDEX `id_UNIQUE` (`id` ASC),
|
UNIQUE INDEX `id_UNIQUE` (`id` ASC),
|
||||||
UNIQUE INDEX `email_UNIQUE` (`email` ASC));
|
UNIQUE INDEX `email_UNIQUE` (`email` ASC));
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
use core\Core;
|
use core\Core;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use repository\product\Product as ProductRepository;
|
use repository\product\Product as ProductRepository;
|
||||||
|
use repository\user\User as UserRepository;
|
||||||
|
use entity\user\User;
|
||||||
|
|
||||||
require __DIR__ . '/../vendor/autoload.php';
|
require __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
@ -44,6 +46,14 @@ foreach ($lines as $number=>$line) {
|
|||||||
$products->add($product);
|
$products->add($product);
|
||||||
}
|
}
|
||||||
|
|
||||||
$productRepository = new ProductRepository((new Core())->getDatabase());
|
$productRepository = new ProductRepository(new Core());
|
||||||
$productRepository->addProducts($products);
|
$productRepository->addProducts($products);
|
||||||
|
|
||||||
|
echo "Insert dummy user...\n";
|
||||||
|
$user= new User();
|
||||||
|
$user->setName('Maxla Mustermensch');
|
||||||
|
$user->setPasswordHashByPassword('passwort:)');
|
||||||
|
$user->setEmail('test@mail.test');
|
||||||
|
$userRepository = new UserRepository(new Core());
|
||||||
|
$userRepository->addUser($user);
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue
Block a user