epaper.guru
EN

Home / Developers / Login and paywall

Login and paywall

The subscription management of epaper.guru comes with ready-made components for login, registration, account and subscription shop. Once logged in, your subscribers read protected articles on your website and the e-paper without a second login.

Embedding the components

<script src="https://abo-admin.epaper.guru/components/abo-components.js" defer></script>
<abo-login tenant="SHOP-SCHLÜSSEL" redirect="/konto"></abo-login>

You find the shop key and the ready-made code in the subscription management under Online → Integration. The components only work on the websites you enter there. Colours, logo and texts are set under Login & registration.

ElementWhat it does
<abo-login>log in with email and password
<abo-register>set up online access, for print subscribers with subscription number and postcode
<abo-password-forgot>, <abo-password-reset>forgotten password and setting a new one
<abo-account>account: details, password, subscriptions, log out
<abo-shop>order subscriptions, by invoice or card and TWINT
<abo-print>print subscription: change of address, pause, redirection

All elements know tenant (required) and lang (de or fr). With login-url, register-url, account-url and shop-url you connect them to the pages of your website. They report abo-login, abo-logout, abo-registered and abo-order as events.

Without pages of your own: ready-made pages are available at https://abo-admin.epaper.guru/p/SHOP-SCHLÜSSEL/anmelden (likewise registrieren, konto, shop).

One login for website and e-paper

The components remember the login in the browser. The e-paper reader on the same website finds it and opens protected issues without another form. When readers log out on the website, the reader logs out too. There is nothing to program; the title only has to be protected with the subscription management in epaper.guru.

If your website does the login itself on the server (via the Subscription API), hand the session to the reader:

<madlab-epaper collection="TITEL-GUID" session="st_…"></madlab-epaper>

Paywall

In the browser

For simple cases, check in the browser whether the logged-in reader has a product (or product group):

const abo = window.AboGuru.client('SHOP-SCHLÜSSEL')
if (abo.token) {
  const { granted } = await abo.access('PRODUKT-GUID')
  if (granted) document.querySelector('.artikel').classList.add('frei')
}

This is convenient but not secure: anyone reading the source sees the protected text as well. For real paywalls, check on the server.

On the server

The server doesn't see the components' login directly. Pass it the session when logging in, for example as a cookie:

document.addEventListener('abo-login', (e) => {
  document.cookie = `abo_session=${e.detail.token}; path=/; secure; samesite=lax; max-age=2592000`
})
document.addEventListener('abo-logout', () => {
  document.cookie = 'abo_session=; path=/; max-age=0'
})

Your server then asks, with its secret API key (ak_…), whom the session belongs to and whether the subscription covers the article:

<?php
function abo(string $method, string $path, array $data = []): ?array {
    $ch = curl_init('https://api.epaper.guru/v1/server/' . $path
        . ($method === 'GET' && $data ? '?' . http_build_query($data) : ''));
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 5,
        CURLOPT_CUSTOMREQUEST => $method,
        CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('ABO_API_KEY'), 'Content-Type: application/json'],
        CURLOPT_POSTFIELDS => $method === 'POST' ? json_encode($data) : null,
    ]);
    $body = curl_exec($ch);
    $ok = curl_getinfo($ch, CURLINFO_RESPONSE_CODE) === 200;
    curl_close($ch);
    return $ok ? json_decode($body, true) : null;
}

$frei = false;
if ($token = $_COOKIE['abo_session'] ?? null) {
    $session = abo('POST', 'session', ['token' => $token]);          // wem gehört die Sitzung?
    if ($session) {
        $access = abo('GET', 'access', ['user' => $session['user']['guid'], 'product' => 'PRODUKT-GUID']);
        $frei = $access['granted'] ?? false;
    }
}

Keep the result in your website's session for a few minutes instead of asking on every page view. More methods under Subscription API.