Authentication – podstawowe komendy

W szablonie:

<?php
  $user_id = $this->getRequest()->getAttribute('identity')->getIdentifier();
?>

W kontrolerze:

$user_id = $this->Authentication->getIdentity()->getIdentifier();

$role = $this->Authentication->getIdentity()->get('role');

$role == 'admin' || 'user'

Wyłączenie z dostępu po zalogowaniu

use Cake\Event\EventInterface;


public function beforeFilter(EventInterface $event): void
{
        parent::beforeFilter($event);

        if(!$this->is_admin) {
            $this->Flash->error(__('Nie ma takiej strony'));
            $event->setResult($this->redirect('/'));
            return;
        }

        $this->Authentication->addUnauthenticatedActions(['edit', 'changePassword' ]);
    }

Aktualizacja URL

let url = new URL(location.href);

$("#proj-tabs").find(".nav-link").on('click', function() {

    var tab_name = $(this).attr('data-bs-target').replace("#", "");

    url.searchParams.set("s_tab", tab_name);

    history.replaceState(null, null, url.href);

});

NipTrait

validateNip($nip)   - Sprawdza poprawność     - Invoice::validateNip('1234567890') → true 
normalizeNip($nip)  - Usuwa myślniki, spacje  - Invoice::normalizeNip('123-456-78-90') → '1234567890'
formatNip($nip)     - Formatuje XXX-XXX-XX-XX - Invoice::formatNip('1234567890') → '123-456-78-90'
generateRandomNip() - Generuje losowy - NIP   - Invoice::generateRandomNip() → '857-234-19-23'
getTestNip()        - Stały NIP testowy       - Invoice::getTestNip() → '123-456-78-16'
isForeignNip($nip)  - Czy NIP zagraniczny     - Invoice::isForeignNip('9912345678') → true 
getNipInfo($nip)    - Debug info Zwraca tablicę z detailami 

seller_nip_formatted - Virtual field - $invoice->seller_nip_formatted → '123-456-78-90' 
buyer_nip_formatted  - Virtual field - $invoice->buyer_nip_formatted → '123-456-78-90'

Czytaj dalej NipTrait

Nowy user

# adduser nowy_user

// User nowy_user dodany do grupy sudo - uprawnienia roota
# usermod -aG sudo nowy_user