Mojolicious-Plugin-Hakkefuin

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

- `callback` (`{lock => sub {}, unlock => sub {}}`): optional coderefs called after lock/unlock operations.

## Helper reference

- `<prefix>_signin($identify)`: create auth cookie + CSRF, store in DB with expiration derived from `c.time`.
- `<prefix>_signout($identify)`: clear session and cookies, remove DB entry.
- `<prefix>_has_auth`: check cookie + CSRF against the backend. Returns `{result => 1}` on success, `{result => 2}` when locked, `{result => 3}` when the CSRF token mismatches, or `{result => 0}` when missing/expired. Stashes backend id, identify, an...
- `<prefix>_auth_update($identify)`: rotate cookie and CSRF token for an active session.
- `<prefix>_lock` / `<prefix>_unlock`: issue or clear the lock cookie when `lock` is enabled.
- `<prefix>_csrf`: ensure a CSRF token exists in the session/response headers.
- `<prefix>_csrf_get`, `<prefix>_csrf_val`, `<prefix>_csrf_regen`: read, validate, or regenerate the CSRF token.
- `<prefix>_backend`: access the underlying backend object (e.g. for inspecting connection status).

### Lock/unlock flow

Call `<prefix>_lock` after `*_has_auth` passes to mark the session locked; a lock cookie is issued and the backend row is marked. Use `<prefix>_unlock` to clear the lock. When locked, `*_has_auth` returns `{result => 2, code => 423, lock_cookie => 0|...

## Backend notes

- SQLite stores data in `dir/mhf_sqlite.db`; a `dir/mhf_sqlite.sql` file is written only when `table_config` is provided. Indexes are created in the database at startup.
- MariaDB/MySQL and PostgreSQL create the tables (and indexes) directly in the database at startup; migration SQL is not dumped to `dir` unless you provide `table_config`.



( run in 0.706 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )