Accounts Module

The Accounts module provides server-rendered account pages on top of Atom's Identity API. Atom handles the forms and session authentication. Your application supplies the user objects and the code that reads or changes them.

Registration

Add the module in the application's existing modules() hook. The second argument is the URL prefix for all the module's routes.

app/Application.php (excerpt)
use Atom\Module\ModuleRegistry;
use Atom\Modules\Accounts\Accounts;

protected function modules(ModuleRegistry $modules): void
{
    $modules->add(Accounts::module(), "/account");
}

Account pages

With the /account prefix, the module registers these routes:

Path Methods What it does
/account/login GET, POST Show the sign-in form and authenticate the submitted credentials.
/account/register GET, POST Show registration and delegate account creation to the application.
/account/forgot-password GET, POST Show the recovery form and ask the application to send reset instructions.
/account/reset-password GET, POST Show the new-password form and delegate password replacement.
/account/logout POST Sign out the current user.

The module also serves its stylesheet under /account/resources/. POST routes use CSRF protection. Sign-in, registration, and password recovery have their own rate limits.

Requirements

Interface What the application supplies
Atom\Identity\IdentityInterface A user model or adapter with a stable identifier().
Atom\Identity\IdentityProviderInterface An adapter that finds users by identifier or login and validates credentials. Bind it to enable sign-in and current-user lookup.
Atom\Modules\Accounts\AccountManagerInterface An implementation of register(), requestPasswordReset(), and resetPassword(). Bind it to enable registration and password recovery.

In your application's service provider, bind the two services to your own implementations. Add their imports to the provider.

Service provider (excerpt)
use Atom\Identity\IdentityProviderInterface;
use Atom\Modules\Accounts\AccountManagerInterface;

// Inside register(Bindings $bindings).
$bindings->bind(IdentityProviderInterface::class)
    ->to(UserIdentityProvider::class);
$bindings->bind(AccountManagerInterface::class)
    ->to(ApplicationAccountManager::class);

Link the provider from the application's services() hook. When you only need sign-in, the identity provider is enough. The module's fallback account manager leaves registration and recovery unconfigured. If you want application-owned starting implementations, the optional php atom accounts:publish command generates them for you to adapt.

Configuration

Pass AccountsOptions when the module needs its own title, destinations, or stylesheet.

app/Application.php (excerpt)
use Atom\Modules\Accounts\AccountsOptions;

// Inside modules().
$modules->add(Accounts::module(new AccountsOptions(
    title: "Sign in",
    afterLogin: "/dashboard",
    afterLogout: "/",
    themeStylesheet: "/style.css",
)), "/account");

Logout Form

Render the provided form in your template when a user can sign out. It submits a POST to the mounted logout route and includes the required CSRF token.

<Accounts.LogoutForm label="Sign out" />