<commit_before>
## Simple management of users' permissions

Built on Nette Framework

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/e26c8a01b9674c198a68185187c469a7)](https://www.codacy.com/app/accgit/Acl?utm_source=github.com&utm_medium=referral&utm_content=accgit/Acl&utm_campaign=badger)

## Installation

**1) Put this code into the Presenter's Base.**

```php
/**
 * Check authorization
 * @return void
 */
public function checkRequirements($element)
{
	if ($element instanceof \ReflectionClass) {

		// Redirecting the user to the sign-in form if he wants to go to the administration.
		if (!$this->user->isLoggedIn() and $this->name == 'Dashboard') {
			$this->redirect('Sign:in', [
				'backlink' => $this->storeRequest()
			]);

		// Everything else will check where the user has access.
		} elseif (!$this->user->isAllowed($this->name, 'default')) {
			$this->messageWarning('You do not have permission.');
			$this->redirect('Homepage:');
		}

	// Check what the user can and can not do.
	} elseif ($element instanceof \ReflectionMethod) {
		if (!$this->user->isAllowed($this->name, $this->signal[1] ?: $this->action)) {
			$this->messageWarning('You do not have permission.');
			$this->redirect('Homepage:');
		}
	}
}
```

**2) Add a property annotation for the class.**

```php
/**
 * @property-read array $signal
 */
```

**3) We create a query for assigning roles to users.**

```php
/**
 * Returned record by id.
 * @param intd
 * @return array
 */
public function findRoles($userId)
{
	return $this->db
		->query('SELECT r.name AS role FROM acl AS a JOIN roles AS r USING (roleId) WHERE a.userId = ?', $userId);
}
```

**4) We go through the roles that are assigned to users and return them to the identity.**

```php
$roles = $this->repository->findRoles($row->userId);
foreach ($roles as $role) {
	$userRoles[] = $role['role'];
}

return new Security\Identity($row->userId, $userRoles, $row->toArray());
```<commit_msg>fix typo<commit_after>
## Simple management of users' permissions

Built on Nette Framework

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/e26c8a01b9674c198a68185187c469a7)](https://www.codacy.com/app/accgit/Acl?utm_source=github.com&utm_medium=referral&utm_content=accgit/Acl&utm_campaign=badger)

## Installation

**1) Put this code into the Presenter's Base.**

```php
/**
 * Check authorization
 * @return void
 */
public function checkRequirements($element)
{
	if ($element instanceof \ReflectionClass) {

		// Redirecting the user to the sign-in form if he wants to go to the administration.
		if (!$this->user->isLoggedIn() and $this->name == 'Dashboard') {
			$this->redirect('Sign:in', [
				'backlink' => $this->storeRequest()
			]);

		// Everything else will check where the user has access.
		} elseif (!$this->user->isAllowed($this->name, 'default')) {
			$this->messageWarning('You do not have permission.');
			$this->redirect('Homepage:');
		}

	// Check what the user can and can not do.
	} elseif ($element instanceof \ReflectionMethod) {
		if (!$this->user->isAllowed($this->name, $this->signal[1] ?: $this->action)) {
			$this->messageWarning('You do not have permission.');
			$this->redirect('Homepage:');
		}
	}
}
```

**2) Add a property annotation for the class.**

```php
/**
 * @property-read array $signal
 */
```

**3) We create a query for assigning roles to users.**

```php
/**
 * Returned record by id.
 * @param int
 * @return array
 */
public function findRoles($userId)
{
	return $this->db
		->query('SELECT r.name AS role FROM acl AS a JOIN roles AS r USING (roleId) WHERE a.userId = ?', $userId);
}
```

**4) We go through the roles that are assigned to users and return them to the identity.**

```php
$roles = $this->repository->findRoles($row->userId);
foreach ($roles as $role) {
	$userRoles[] = $role['role'];
}

return new Security\Identity($row->userId, $userRoles, $row->toArray());
```
{'fraction_non_alphanumeric': 0.1717948717948718, 'fraction_numerical': 0.014871794871794871, 'mean_word_length': 4.343835616438356, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 53, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '160584', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1297, 'n_words': 363}