-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserService.php
More file actions
42 lines (34 loc) · 1.17 KB
/
UserService.php
File metadata and controls
42 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
class UserService
{
private ?UserRepository $repository = null;
private ?Router $router = null;
public function __construct(UserRepository $repository, Router $router)
{
$this->repository = $repository;
$this->router = $router;
}
public function loginWithUserAndPasswordAndRedirect(string $user, string $password): void
{
if ($this->repository->isLoginValid($user, $password)) {
$user = $this->repository->get($user);
$this->generateVectorForUser($user);
$this->router->redirect('home');
} else {
$this->router->addFlashError('Invalid User/Password');
$this->router->redirect('login');
}
}
public function generateVectorForUser(User $user): void
{
$vector = [];
for ($i = 0; $i < 10; $i++) {
$vector[$i] = isset($vector[$i]) ? $vector[$i] : [];
for ($j = 0; $j < 10; $j++) {
$vector[$i][$j] = isset($vector[$i][$j]) ? $vector[$i][$j] : [];
$vector[$i][$j] = $user->getVectorInfo($i, $j) + 1;
}
}
$user->setVectorInfo($vector);
}
}