Try and connect to the database.
This commit is contained in:
parent
9eb433a8ed
commit
8424a8c6ee
@ -39,6 +39,7 @@ use Slovocast\Domain\Repository\User\UserRepository;
|
||||
use Slovocast\Domain\Repository\User\UserRepositoryInterface;
|
||||
|
||||
use Slovocast\Infrastructure\Api\Database\DatabaseConnectionInterface;
|
||||
use Slovocast\Infrastructure\Database\DatabaseConnection;
|
||||
use Slovocast\Infrastructure\Api\User\UserAuthorizationInterface;
|
||||
use Slovocast\Infrastructure\User\BasicUserAuthorization;
|
||||
|
||||
@ -71,7 +72,6 @@ class Bootstrap
|
||||
$config->addSchema('database', DatabaseConnectionSchema::getSchema());
|
||||
$config->addSchema('session', SessionSchema::getSchema());
|
||||
|
||||
|
||||
$config->merge([
|
||||
'site' => [
|
||||
'name' => "Slovocast",
|
||||
@ -143,7 +143,14 @@ class Bootstrap
|
||||
* Database Connections
|
||||
*/
|
||||
DatabaseConnectionInterface::class => function (ContainerInterface $container) {
|
||||
$config = $container->get('config')->get('database');
|
||||
$config = $container->get('config');
|
||||
return new DatabaseConnection(
|
||||
$config->get('database.host'),
|
||||
$config->get('database.username'),
|
||||
$config->get('database.password'),
|
||||
$config->get('database.database'),
|
||||
$config->get('database.port'),
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -15,7 +15,7 @@ class DatabaseConnectionSchema
|
||||
'port' => Expect::int()->min(1)->max(65535)->default(3306),
|
||||
'database' => Expect::string()->required(),
|
||||
'username' => Expect::string()->required(),
|
||||
'password' => Expect::string()->nullable()
|
||||
'password' => Expect::string()->required()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -34,10 +34,7 @@ class LoginUserAction extends Controller
|
||||
}
|
||||
|
||||
// start the session
|
||||
$this->session->set('user', [
|
||||
'id' => $user->getId(),
|
||||
'authenticated' => true
|
||||
]);
|
||||
return $this->response;
|
||||
$this->session->set('user', [ 'id' => $user->getId(), 'authenticated' => true ]);
|
||||
return $this->render('dashboard.twig');
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,18 @@ use PDO;
|
||||
|
||||
class DatabaseConnection implements DatabaseConnectionInterface
|
||||
{
|
||||
public function __construct(private PDO $pdo) {}
|
||||
private PDO $pdo;
|
||||
|
||||
public function __construct(
|
||||
string $host,
|
||||
string $username,
|
||||
string $password,
|
||||
string $database,
|
||||
int $port = 3306
|
||||
) {
|
||||
$dsn = "mysql:dbname={$database};host={$host};port={$port}";
|
||||
$this->pdo = new PDO($dsn. $username, $password);
|
||||
}
|
||||
|
||||
public function getConnection(): PDO
|
||||
{
|
||||
|
@ -42,7 +42,6 @@ class Routes
|
||||
$app->get('/login', LoginUserPage::class)
|
||||
->setName('user-login-page');
|
||||
$app->post('/login', LoginUserAction::class)
|
||||
->add(AuthenticatedMiddleware::class)
|
||||
->setName('user-login-action');
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user