The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

MKDoc::Auth::TempUser - Simple temp user class for MKDoc::Auth

OVERVIEW

MKDoc::Auth provides a simple and efficient user account signup facility. It works as follows:

A user goes to a signup page, typically /.signup.html.
A user enter his email address and name and sumbits the form.
An email is sent to the user with his login, password, and a confirmation link.
The user clicks on the confirmation link.
The user is now confirmed and is able to login.

This process ensures that the users email addresses are all valid. Additionally, it guarantees that the user has not been maliciously subscribed by someone else.

Before the user has completed confirmation step, it would be unwise to store that user directly in the database since it could be full of bogus users who never actually clicked on the confirmation link.

So instead, MKDoc::Auth::TempUser objects are created. They are stored on disk for a limited amount of time using Cache::FileCache via the MKDoc::Core::FileCache wrapper.

The users are stored along with a confirmation number which has to be supplied in order to activate the user account. If the confirmation number is correct, the temporary user can be 'upgraded' to a normal user since their email address has been confirmed.

This module is used by MKDoc::Auth::Plugin::Signup and MKDoc::Auth::Plugin::Confirm.

INHERITANCE

MKDoc::Auth::User

API

$self->id();

Returns the object identifier.

In the special case of MKDoc::Auth::TempUser objects, id() is an alias for login().

$self->load ($login);

Loads an MKDoc::Auth object with login $login.

$self->new();

Same as MKDoc::Auth::User::new(), except that it adds a randomly generated 'confirm_nb' attribute.

This attribute is used as a confirmation ticket when a user confirms / activates his accounts.

$self->confirm ($confirmation_nb);

Checks that $confirmation_nb matches the confirmation number of the object.

If it does, removes $self from the cache and turns it into a permanent MKDoc::Auth object, and saves it.

$self->confirm_nb();

Returns this object's confirmation number.

$self->set_confirm_nb ($confirmation_nb);

Sets this object's confirmation number to $confirmation_nb.

$class->list();

Lists all objects from the cache _ONLY_, i.e. returns only MKDoc::Auth::TempUser objects.

$class->load_from_login ($login);

Returns any object which matches $login, in this order:

First attempts to load a MKDoc::Auth::User object matching $login, even if this object is marked as deleted.

Attempts to load a MKDoc::Auth::TempUser object from the cache.

Returns undef

$self->delete();

Removes this temporary object from the cache.

$class->_expiration_time();

Defines how long the temporary object will live in the cache for.

By default, returns '1 month', i.e. if a user does not confirm his account within one month then he'll have to sign-up again.

This value can be overriden with the environment variable MKD__AUTH_TEMPUSER_EXPIRES.

The value can be anything that Cache::Cache will understand.