Wraith.Accounts (Wraith v0.1.0)

View Source

Who writes here. The first user is the owner (created at /setup); owners add authors. Passwords are bcrypt; a login mints a random session token whose SHA-256 is the key of a session item (60 days).

A user is a plain map: id, email, name, slug, role ("owner" | "author"), bio, password_hash.

Summary

Functions

Change the password: the current one must match, the new one must be long enough.

Mint a session token for the user; store its hash. Returns the raw token.

Create a user. The email is unique (a transaction with the email item).

Remove a staff member (never the owner). Their posts stay, attributed to them.

A user without the password hash (for templates and the agent).

Mail a reset link if the address belongs to an author. Always :ok (no enumeration).

What a reset token is bound to: changes whenever the password does.

Set a new password from a reset link (Wraith.Tokens :password_reset).

Change a user's role (the caller's right to do so is the caller's business — Wraith.Policy).

Create the owner and mark setup done. Refused once any user exists — and two setups submitted at once can't both win: the owner claim item is put with :not_exists in the same transaction as the user.

Name, bio, avatar URL, website and social handles.

The user behind a session token, or nil.

Functions

any_users?()

authenticate(email, password)

change_password(user, current, new)

Change the password: the current one must match, the new one must be long enough.

create_session(map)

Mint a session token for the user; store its hash. Returns the raw token.

create_user(attrs)

@spec create_user(map()) :: {:ok, map()} | {:error, map()}

Create a user. The email is unique (a transaction with the email item).

delete_session(token)

delete_user(u)

Remove a staff member (never the owner). Their posts stay, attributed to them.

get_user(id)

get_user_by_email(email)

get_user_by_slug(slug)

list_users()

public(user)

A user without the password hash (for templates and the agent).

request_password_reset(email)

Mail a reset link if the address belongs to an author. Always :ok (no enumeration).

reset_binding(arg1)

What a reset token is bound to: changes whenever the password does.

reset_password(token, new)

Set a new password from a reset link (Wraith.Tokens :password_reset).

set_role(arg1, role)

Change a user's role (the caller's right to do so is the caller's business — Wraith.Policy).

setup_owner(attrs)

Create the owner and mark setup done. Refused once any user exists — and two setups submitted at once can't both win: the owner claim item is put with :not_exists in the same transaction as the user.

social_fields()

update_profile(map, attrs)

Name, bio, avatar URL, website and social handles.

user_by_session(token)

The user behind a session token, or nil.