1. Go to this page and download the library: Download petrsladek/skautis library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
petrsladek / skautis example snippets
class LoginPresenter extends BasePresenter
{
/**
* @var \PetrSladek\SkautIS\SkautIS @inject
*/
public $skautis;
/** @var UsersModel @inject*/
public $usersModel;
/**
* Vytvoří komponentu pro otevření login dialogu SkautISu
* @return \PetrSladek\SkautIS\Dialog\LoginDialog
*/
protected function createComponentSkautisLoginDialog()
{
$dialog = new \PetrSladek\SkautIS\Dialog\LoginDialog($this->skautis);
// nebo $dialog = $this->skautis->createLoginDialog();
$dialog->onResponse[] = function(\PetrSladek\SkautIS\Dialog\LoginDialog $dialog) {
$skautis = $dialog->getSkautIS();
/** @var $api \SkautIS\SkautIS */
$api = $dialog->getSkautIS()->getClient();
if (!$skautis->isLoggedIn()) {
$this->flashMessage("Přihlášení se nezdařilo.");
return;
}
/**
* Pokud jsme se tady, bude fungovat normálně přístupné SkautIS API
*/
try {
// $skautisUserId = $skautis->getUserId(); // vrati ID skautis uctu kterym jste se prihlasil
$skautisPersonId = $skautis->getPersonId(); // vrati ID sparovan osoby se skautis uctem kterym jste se prihlasil
// $me = $skautis->getUserData(); // vrati data o prihlasenem skautis uzivateli
$me = $skautis->getPersonData(); // vrati data o osobe ktera je sparovana s prihlasenym skautis uzivatelem
if (!$existing = $this->usersModel->findBySkautisPersonId($skautisPersonId)) {
/**
* Pokud uzivatel neni u nas v DB, tak ho zaregistrujeme
*/
$existing = $this->usersModel->registerFromSkautis($me);
}
/**
* Prihlasime uzivatele pomoci objektu Identity
*/
$this->user->login(new \Nette\Security\Identity($existing->id, $existing->roles, $existing));
/**
* Nyni jste prihlaseni pres skautis
*/
} catch (\Exception $e) {
\Tracy\Debugger::log($e, 'skautis');
$this->flashMessage("Prihlaseni se nazdarilo.");
}
$this->redirect('this'); // jsme v obsluze handleru, takze presmerujeme na sebe abychom nemeli v adrese ?do=xxx
};
return $dialog;
}
}
if(!$this->user->isLoggedIn()) { // nebo if(!$skautis->isLoggedIn()) pro skautis uzivatele
$this['skautisLoginDialog']->open(); // presmeruje na skautis prihlaseni a po navraceni standartne provede onResponse event.
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.