Revize 3aa5f2d2
Přidáno uživatelem Filip Jani před asi 6 roky(ů)
app/enum/EUserRole.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
|
|
4 |
namespace App\Enum; |
|
5 |
|
|
6 |
|
|
7 |
class EUserRole |
|
8 |
{ |
|
9 |
const ADMIN = 'admin'; |
|
10 |
const USER = 'user'; |
|
11 |
const BASIC_USER = 'basic user'; |
|
12 |
} |
app/model/Authenticator.php | ||
---|---|---|
2 | 2 |
|
3 | 3 |
namespace App\Model; |
4 | 4 |
|
5 |
use App\Model\Repository\RoleRepository; |
|
5 | 6 |
use App\Model\Repository\UserRepository; |
6 | 7 |
use App\Model\Repository\UserRoleRepository; |
7 | 8 |
use Nette\Security\AuthenticationException; |
... | ... | |
46 | 47 |
throw new AuthenticationException('Nesprávné heslo.'); |
47 | 48 |
} |
48 | 49 |
|
49 |
$roles = $row->related(UserRoleRepository::TABLE_NAME, UserRoleRepository::COLUMN_USER_ID) |
|
50 |
->fetchField(UserRoleRepository::COLUMN_ROLE_ID); |
|
50 |
$userRoles = $row->related(UserRoleRepository::TABLE_NAME, UserRoleRepository::COLUMN_USER_ID)->fetchAll(); |
|
51 |
foreach ($userRoles as $userRole) |
|
52 |
{ |
|
53 |
$roles[] = $userRole->ref(RoleRepository::TABLE_NAME, UserRoleRepository::COLUMN_ROLE_ID)->{RoleRepository::COLUMN_NAME}; |
|
54 |
} |
|
51 | 55 |
|
52 |
return new UserIdentity($row->{UserRepository::COLUMN_ID}, $row->{UserRepository::COLUMN_USERNAME}, $roles);
|
|
56 |
return new Identity($row->{UserRepository::COLUMN_ID}, $roles, $row);
|
|
53 | 57 |
} |
54 | 58 |
} |
app/model/UserIdentity.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
namespace App\Model; |
|
4 |
|
|
5 |
use Nette\Security\Identity; |
|
6 |
|
|
7 |
/** |
|
8 |
* Rozšíření identity o jméno uživatele |
|
9 |
* |
|
10 |
* @package App\Model |
|
11 |
*/ |
|
12 |
class UserIdentity extends Identity |
|
13 |
{ |
|
14 |
/** @property */ |
|
15 |
public $username; |
|
16 |
|
|
17 |
public function __construct($id, $username, $roles = null, $data = null) |
|
18 |
{ |
|
19 |
parent::__construct($id, $roles, $data); |
|
20 |
|
|
21 |
$this->username = $username; |
|
22 |
} |
|
23 |
|
|
24 |
/** |
|
25 |
* Vrací uživatelské jméno |
|
26 |
* |
|
27 |
* @return string |
|
28 |
*/ |
|
29 |
public function getUsername() |
|
30 |
{ |
|
31 |
return $this->username; |
|
32 |
} |
|
33 |
} |
Také k dispozici: Unified diff
Re #7329 upravení identity a přidání enumu s rolemi