Skip to content

Commit

Permalink
added visual + routing for skautis login
Browse files Browse the repository at this point in the history
  • Loading branch information
Lung committed Nov 25, 2023
1 parent 25cf76d commit fb05681
Show file tree
Hide file tree
Showing 18 changed files with 238 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ POSTGRES_DB="kissj"

SENTRY_DSN=""
SENTRY_PROFILING_RATE="0.5" # from 0 to 1

SKAUTIS_APP_ID="kissj"
SKAUTIS_USE_TEST="true"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ Backlog is in project GitHub issues

#### User cannot log in - after click it stays on "insert mail" page

- try what function `session_start()` returs
- try what function `session_start()` returns
- if false, it probably cannot write session into filesystem
- make path from `session_save_path()` writable
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"ext-fileinfo": "*",
"ext-gd": "*",
"ext-mbstring": "*",
"ext-sqlite3": "*",
"ext-soap": "*",
"composer": "^2",
"aws/aws-sdk-php": "^3.158",
"dflydev/fig-cookies": "^3.0",
Expand All @@ -44,6 +44,7 @@
"robmorgan/phinx": "^0.12.5",
"selective/basepath": "^2.1",
"sentry/sdk": "^3.1",
"skautis/skautis": "2.1.*",
"slim/psr7": "^1.1",
"slim/slim": "^4",
"slim/twig-view": "^3.1",
Expand Down
67 changes: 65 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ protected function getParameterFromBody(Request $request, string $parameterName,
return $parameter;
}

protected function getParameterFromQuery(Request $request, string $parameterName): string
{
$queryParams = $request->getQueryParams();
if (!is_array($queryParams)) {
throw new \RuntimeException('getQueryParams() did not returned array');
}

if (!array_key_exists($parameterName, $queryParams)) {
throw new \RuntimeException('query parameter does not contain key ' . $parameterName);
}

return $queryParams[$parameterName];
}

/**
* @return array<mixed>
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Application/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use kissj\Participant\ParticipantController;
use kissj\Participant\Patrol\PatrolController;
use kissj\Participant\Troop\TroopController;
use kissj\Skautis\SkautisController;
use kissj\User\UserController;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
Expand All @@ -31,7 +32,8 @@ class Route
{
public function addRoutesInto(App $app): App
{
$app->redirect($app->getBasePath() ?: '/', $app->getBasePath() . '/v2/kissj/events', 301);
$app->get($app->getBasePath() . '/', SkautisController::class . '::redirectFromSkautis')
->setName('index');

$app->group($app->getBasePath() . '/v2', function (RouteCollectorProxy $app) {
$app->redirect('', $app->getBasePath() . '/v2/kissj', 301);
Expand Down
10 changes: 10 additions & 0 deletions src/Event/EventType/EventType.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,14 @@ public function isMultiplePaymentsAllowed(): bool
{
return false;
}

public function isLoginEmailAllowed(): bool
{
return true;
}

public function isLoginSkautisAllowed(): bool
{
return false;
}
}
10 changes: 10 additions & 0 deletions src/Event/EventType/Obrok/EventTypeObrok.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ public function isUnlockExpiredButtonAllowed(): bool
{
return true;
}

public function isLoginEmailAllowed(): bool
{
return true; // TODO change to false in production
}

public function isLoginSkautisAllowed(): bool
{
return true;
}
}
2 changes: 1 addition & 1 deletion src/Participant/ParticipantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function changeDetails(Request $request, Response $response, User $user):
$this->participantRepository->persist($participant);
$this->flashMessages->success($this->translator->trans('flash.success.detailsSaved'));

return $this->redirect($request, $response, 'getDashboard'); // TODO change to common dashboard when possible
return $this->redirect($request, $response, 'getDashboard');
}

public function showCloseRegistration(Request $request, Response $response, User $user): Response
Expand Down
9 changes: 9 additions & 0 deletions src/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use kissj\Middleware\SentryHttpContextMiddleware;
use kissj\Middleware\UserAuthenticationMiddleware;
use kissj\Orm\Mapper;
use kissj\Skautis\SkautisFactory;
use kissj\User\UserRegeneration;
use LeanMapper\Connection;
use LeanMapper\DefaultEntityFactory;
Expand Down Expand Up @@ -148,6 +149,12 @@ public function getContainerDefinition(string $envPath, string $envFilename): ar
'secret' => $_ENV['S3_SECRET'],
],
]);
$container[SkautisFactory::class] = function (): SkautisFactory {
return new SkautisFactory(
$_ENV['SKAUTIS_APP_ID'],
(bool)$_ENV['SKAUTIS_USE_TEST'],
);
};
$container[Translator::class] = function () {
// https://symfony.com/doc/current/components/translation.html
$translator = new Translator($_ENV['DEFAULT_LOCALE']);
Expand Down Expand Up @@ -230,5 +237,7 @@ private function validateAllSettings(Dotenv $dotenv): void
$dotenv->required('POSTGRES_DB');
$dotenv->required('SENTRY_DSN');
$dotenv->required('SENTRY_PROFILING_RATE')->notEmpty();
$dotenv->required('SKAUTIS_APP_ID')->notEmpty();
$dotenv->required('SKAUTIS_USE_TEST')->isBoolean();
}
}
28 changes: 28 additions & 0 deletions src/Skautis/SkautisController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace kissj\Skautis;

use kissj\AbstractController;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

class SkautisController extends AbstractController
{
public function __construct(
) {
}

public function redirectFromSkautis(Request $request, Response $response): Response
{
$this->flashMessages->info($this->translator->trans('flash.info.redirectedFromSkautis'));

$returnLink = $this->getParameterFromQuery($request, 'ReturnUrl');
// TODO load user into session

return $response
->withHeader('Location', $returnLink)
->withStatus(302);
}
}
30 changes: 30 additions & 0 deletions src/Skautis/SkautisFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace kissj\Skautis;

use Skautis\Config;
use Skautis\SessionAdapter\SessionAdapter;
use Skautis\Skautis;
use Skautis\User;
use Skautis\Wsdl\WebServiceFactory;
use Skautis\Wsdl\WsdlManager;

class SkautisFactory
{
public function __construct(
private readonly string $appId,
private readonly bool $isTestMode,
) {
}

public function getSkautis(): Skautis
{
$config = new Config($this->appId, $this->isTestMode, true, true);
$wsdlManager = new WsdlManager(new WebServiceFactory(), $config);
$user = new User($wsdlManager, new SessionAdapter());

return new Skautis($wsdlManager, $user);
}
}
18 changes: 18 additions & 0 deletions src/Skautis/SkautisService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace kissj\Skautis;

class SkautisService
{
public function __construct(
private readonly SkautisFactory $skautisFactory,
) {
}

public function getLoginUri(string $backlink): string
{
return $this->skautisFactory->getSkautis()->getLoginUrl($backlink);
}
}
3 changes: 3 additions & 0 deletions src/Templates/cs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ login:
waitForApproval: "Počkej na schválení a informace k platbě"
pay: "Zaplať a jeď!"
more: "Více informací o registraci"
skautis: "Přihlásit se přes Skautis"
email:
layout:
welcome: "Ahoj!"
Expand Down Expand Up @@ -398,6 +399,7 @@ troopManagement-admin:
openTroopLeaders: "odemčené skupiny"
noTroopParticipants: "žádní účastníci bez skupiny nejsou k dispozici"
troopParticipantsWithoutLeader: "účastníci bez skupiny"
tieTogether: "Připojit účastníka do skupiny"
flash:
info:
participantDeleted: "Účastník byl smazán"
Expand All @@ -414,6 +416,7 @@ flash:
differentScarfs: "Účastníci mají různě nastavené šátky - šátek bude změněn u kupujícího, aby odpovídal platbě"
duePaymentDenied: "Kvůli nezaplacení emaily odemknuto účastníků"
generatedPayments: "Vygenerováno plateb a rozposláno emailů"
redirectedFromSkautis: "Přesměrováno ze Skautisu"
success:
linkSent: "E-mail poslán! Přihlaš se pomocí odkazu v něm"
confirmPayment: "Platba účastníka byla potvrzena, e-mail o potvrzení byl odeslán"
Expand Down
3 changes: 3 additions & 0 deletions src/Templates/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ login:
waitForApproval: "Wait for approval and payment info"
pay: "Pay and you are good to go!"
more: "More information about registration system"
skautis: "Skautis login"
email:
layout:
welcome: "Hello!"
Expand Down Expand Up @@ -398,6 +399,7 @@ troopManagement-admin:
openTroopLeaders: "unlocked troops"
noTroopParticipants: "there are no participants without troop"
troopParticipantsWithoutLeader: "participants without troop"
tieTogether: "Tie participant into troop"
flash:
info:
participantDeleted: "Participant was deleted"
Expand All @@ -414,6 +416,7 @@ flash:
differentScarfs: "Participants have differently selected scarf option - it will be changed at the buyer's registration form to correspond the payment."
duePaymentDenied: "Participants denied which missed due payment deadline by mail"
generatedPayments: "Generated payments and emails sent"
redirectedFromSkautis: "Redirected from Skautis"
success:
linkSent: "Email sent! Follow the link in it to log in."
confirmPayment: "Participant payment is confirmed, email about confirmation is sent"
Expand Down
3 changes: 3 additions & 0 deletions src/Templates/sk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ login:
waitForApproval: "Počkaj na schválenie a platobné údaje"
pay: "Zaplať a prídi na akciu!"
more: "Viac informácií o registračnom systéme"
skautis: "Přihlásit se přes Skautis"
email:
layout:
welcome: "Ahoy!"
Expand Down Expand Up @@ -368,6 +369,7 @@ transferPayment-admin:
participantNotFound: "Účastník nebyl nalezen :( Mail:"
transfer: "Přesuň platbu"
notPossible: "Přesun nelze uskutečnit"
tieTogether: "Připojit účastníka do skupiny"
flash:
info:
participantDeleted: "Účastník bol vymazaný"
Expand All @@ -383,6 +385,7 @@ flash:
differentScarfs: "Účastníci mají různě nastavené šátky - šátek bude změněn u kupujícího, aby odpovídal platbě"
duePaymentDenied: "Participants denied which missed due payment deadline by mail"
generatedPayments: "Vygenerováno plateb a rozposláno emailů"
redirectedFromSkautis: "Přesměrováno ze Skautisu"
success:
linkSent: "E-mail odoslaný! Klikni na link v ňom pre prihlásenie."
confirmPayment: "Platba účastníka byla potvrzena, e-mail o potvrzení byl odeslán"
Expand Down
Loading

0 comments on commit fb05681

Please sign in to comment.