Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| OlzStravaRedirectParams | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | n/a |
0 / 0 |
|||
| OlzStravaRedirect | |
0.00% |
0 / 22 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 1 |
| hasAccess | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| searchSqlWhenHasAccess | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPageTitle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPageDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getHtmlWhenHasAccess | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Components\Auth\OlzStravaRedirect; |
| 4 | |
| 5 | use Olz\Components\Common\OlzRootComponent; |
| 6 | use Olz\Components\Page\OlzFooter\OlzFooter; |
| 7 | use Olz\Components\Page\OlzHeader\OlzHeader; |
| 8 | use Olz\Utils\HttpParams; |
| 9 | |
| 10 | /** @extends HttpParams<array{ |
| 11 | * redirect_url?: ?string, |
| 12 | * state?: ?string, |
| 13 | * code?: ?string, |
| 14 | * scope?: ?string, |
| 15 | * }> */ |
| 16 | class OlzStravaRedirectParams extends HttpParams { |
| 17 | } |
| 18 | |
| 19 | /** @extends OlzRootComponent<array<string, mixed>> */ |
| 20 | class OlzStravaRedirect extends OlzRootComponent { |
| 21 | public function hasAccess(): bool { |
| 22 | return true; |
| 23 | } |
| 24 | |
| 25 | public function searchSqlWhenHasAccess(array $terms): string|array|null { |
| 26 | return null; |
| 27 | } |
| 28 | |
| 29 | public function getPageTitle(): string { |
| 30 | return "Mit Strava verbinden"; |
| 31 | } |
| 32 | |
| 33 | public function getPageDescription(): string { |
| 34 | return "Mit Strava verbinden"; |
| 35 | } |
| 36 | |
| 37 | public function getHtmlWhenHasAccess(mixed $args): string { |
| 38 | $params = $this->httpUtils()->validateGetParams(OlzStravaRedirectParams::class); |
| 39 | $code = $params['code'] ?? ''; |
| 40 | $js_code = json_encode($code) ?: '""'; |
| 41 | $js_redirect_url = json_encode($params['redirect_url'] ?? null) ?: 'null'; |
| 42 | |
| 43 | $out = OlzHeader::render([ |
| 44 | 'title' => $this->getPageTitle(), |
| 45 | 'description' => $this->getPageDescription(), |
| 46 | 'norobots' => true, |
| 47 | ]); |
| 48 | |
| 49 | $out .= "<div class='content-full'>"; |
| 50 | $out .= <<<ZZZZZZZZZZ |
| 51 | <script> |
| 52 | const code = {$js_code}; |
| 53 | const redirectUrl = {$js_redirect_url}; |
| 54 | window.addEventListener('load', function () { |
| 55 | olz.olzLinkStravaWithCode(code).then(function () { |
| 56 | window.location.href = redirectUrl; |
| 57 | }).catch(function () { |
| 58 | window.location.href = redirectUrl; |
| 59 | }); |
| 60 | }); |
| 61 | </script> |
| 62 | ZZZZZZZZZZ; |
| 63 | $out .= "</div>"; |
| 64 | |
| 65 | $out .= OlzFooter::render(); |
| 66 | return $out; |
| 67 | } |
| 68 | } |