NAME

Slovo::Task::SendOnboardingEmail - Send an email with link for first time login

SYNOPSIS

  # common configuration for similar Tasks in slovo.conf
  my $mail_cfg = {
    token_valid_for => 24 * 3600,
    'Net::SMTP'     => {
      new => {
        Host => 'mail.example.org',

        #Debug          => 1,
        SSL             => 1,
        SSL_version     => 'TLSv1',
        SSL_verify_mode => 0,
        Timeout         => 60,
             },
      auth => ['slovo@example.org', 'Pa55w03D'],
      mail => 'slovo@example.org',
    },
  };

  #load the plugin via slovo.conf
  plugins => [
    #...
    #Tasks
    {'Task::SendOnboardingEmail' => $mail_cfg},
    {'Task::SendPasswEmail'      => $mail_cfg},
  ],

DESCRIPTION

This is the first Minion task implemented in Slovo.

Slovo is not integrated with any social network. A plugin for such integration can be relatively easily written and there are maybe already some Mojolicious::Plugin written. Ado had such functionality by leveraging Mojolicious::Plugin::OAuth2.

Slovo takes another approach. Its users can invite each other to join the set of sites that one Slovo instance manages. Slovo is the social network it self. We may use Mojolicious::Plugin::OAuth2::Server at some point.

A user in Slovo can create others users' accounts. Upon creation of the new user account an email is sent to the new user. In the email there is a link for the first time login fo the new user. The new user follows the link and is signed in after confirming the names of the user who created his account. After that the user has to change his password to be able to sign in next time.

Slovo::Task::SendOnboardingEmail inherits Mojolicious::Plugin and implements the following functionality.

METHODS

The following methods are implemented.

register

Reads the configuration and adds the implemented tasks to Minion.

validate_conf

Validates provided in slovo.conf configuration and throws a Mojo::Exception in case some values are invalid.

FUNCTIONS

The following functions are implemented.

send_mail_by_net_smtp

Arguments: $message, $to_user, $app

$message must be already fully prepared and looks something like:

    my $message = <<"MAIL";
  To: $to_user->{email}
  From: $CONF->{'Net::SMTP'}{mail}
  Subject: =?UTF-8?B?${\ b64_encode(encode('UTF-8', $subject), '') }?=
  Content-Type: text/plain; charset="utf-8"
  Content-Transfer-Encoding: 8bit
  Message-Id: <acc-msg-to-$to_user->{login_name}${\ time}\@$domain>
  Date: ${\ Mojo::Date->new->to_datetime }
  MIME-Version: 1.0
  
  ${\ encode('UTF-8', $body)}
  
  MAIL

$to_user is a hash reference containing at least $to_user->{email} and $to_user->{id}.

$app is the current Slovo instance.

This function sends the prepared message using Net::SMTP.

  $app->debug('Message to be send:' . $/ . $message);
  send_mail_by_net_smtp($message, $to_user, $app);

TASKS

The following tasks are implemented.

mail_first_login

Prepares and sends email using Net::SMTP to the newly created user. The email contains a link for the first sign in. The task is enqued upon creation of the new account. The first time sign in is implemented in "first_login_form" in Slovo::Controller::Auth and "first_login" in Slovo::Controller::Auth.

delete_first_login

Deletes the record with the login token for the new user. The task is enqued by "mail_first_login" with delay token_valid_for as configured. Defaults to 24 hours after creation of the account.

SEE ALSO

Slovo::Controller::Auth, Slovo::Task::SendPasswEmail.