Added email support.

master
Manager Bot 3 years ago
parent ae82906362
commit 8bc7f27015
  1. 6
      Web/cpanfile
  2. 5
      Web/lib/MJB/Web.pm
  3. 8
      Web/lib/MJB/Web/Controller/Auth.pm
  4. 6
      Web/lib/MJB/Web/Plugin/Email.pm
  5. 74
      Web/mkits/forgot_password.mkit/body.html
  6. 9
      Web/mkits/forgot_password.mkit/body.txt
  7. 18
      Web/mkits/forgot_password.mkit/manifest.json

@ -6,7 +6,11 @@ requires 'DateTime';
requires 'DateTime::Format::Pg';
requires 'Try::Tiny';
# Remove when moving mail to its own package.
# For MJB::Web::Plugin::Email
requires 'Email::Sender::Simple';
requires 'Email::Sender::Transport::SMTP';
requires 'Email::MIME::Kit';
requires 'Email::MIME::Kit::Renderer::TT';
requires 'MIME::Base64';
requires 'Authen::SASL';

@ -25,8 +25,11 @@ sub startup ($self) {
# Add MJB::Web::Plugin to plugin search path.
push @{$self->plugins->namespaces}, 'MJB::Web::Plugin';
# Load the MJB::Web::Plugin::Nginx plugin.
# Load the MJB::Web::Plugin::Nginx plugin for $c->domain_config
$self->plugin('Nginx');
# Load the MJB::Web::Plugin::Email plugin for $c->send_email
$self->plugin('Email');
$self->helper( db => sub {
return state $db = MJB::DB->connect($config->{database}->{mjb});

@ -213,10 +213,10 @@ sub do_forgot ( $c ) {
# Make a token & send the email TODO
my $token = $person->create_auth_token( 'forgot' );
#$c->send_email( 'forgot_password', {
# send_to => $email,
# link => 'https://' . $c->config->{domain} . "/reset/$token"
#});
$c->send_email( 'forgot_password', {
send_to => $email,
link => 'https://' . $c->config->{domain_for_links} . "/reset/$token"
});
# Let the user know the next steps.
$c->flash( confirmation => 'Please check your email for a password reset link.' );

@ -8,12 +8,14 @@ sub register ( $self, $app, $config ) {
$app->helper( send_email => sub ($c, $template, $options ) {
my $transport = Email::Sender::Transport::SMTP->new(%{$c->config->{smtp}});
my $mkit_path = $c->home->child('mkits')->to_string;
my $mkit_path = $app->home->child('mkits')->to_string;
my $kit = Email::MIME::Kit->new({ source => sprintf( "%s/%s.mkit", $mkit_path, $template ) } );
my $message = $kid->assemble( $options );
my $message = $kit->assemble( $options );
sendmail( $message, { transport => $transport } );
});
}
1;

@ -0,0 +1,74 @@
<!DOCTYPE html>
<html style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; margin: 0; padding: 0;">
<head>
<meta name="viewport" content="width=device-width">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TodayChecklist Password Reset</title>
</head>
<body bgcolor="#f8f8f8" style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; -webkit-font-smoothing: antialiased; height: 100%; -webkit-text-size-adjust: none; width: 100% !important; margin: 0; padding: 0;">
<!-- body -->
<table class="body-wrap" bgcolor="#eeeeee" style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; width: 100%; margin: 0; padding: 20px;">
<tr style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; margin: 0; padding: 0;">
<td style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; margin: 0; padding: 0;"></td>
<td class="container" bgcolor="#F8F8F8" style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; clear: both !important; display: block !important; max-width: 600px !important; margin: 0 auto; padding: 20px; border: 1px solid #f0f0f0;">
<!-- content -->
<div class="content" style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; display: block; max-width: 600px; margin: 0 auto; padding: 0;">
<table style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; width: 100%; margin: 0; padding: 0;">
<tr style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; margin: 0; padding: 0;">
<td style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; margin: 0; padding: 0;">
<h1 align="center" style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 36px; line-height: 1.2em; color: #111111; font-weight: 200; margin: 40px 0 10px; padding: 0;">
You requested a password reset.
</h1>
<p style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.6em; font-weight: normal; margin: 0 0 10px; padding: 0;">
Please use the following [% link %] to reset your password.
</p>
<p style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.6em; font-weight: normal; margin: 0 0 10px; padding: 0;">
Thanks!
</p>
</td>
</tr>
</table>
</div>
<!-- /content -->
</td>
<td style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; margin: 0; padding: 0;"></td>
</tr>
</table>
<!-- /body -->
<!-- footer -->
<table class="footer-wrap" style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; clear: both !important; width: 100%; margin: 0; padding: 0;">
<tr style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; margin: 0; padding: 0;">
<td style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; margin: 0; padding: 0;"></td>
<td class="container" style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; clear: both !important; display: block !important; max-width: 600px !important; margin: 0 auto; padding: 0;">
<!-- content -->
<div class="content" style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; display: block; max-width: 600px; margin: 0 auto; padding: 0;">
<table style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; width: 100%; margin: 0; padding: 0;">
<tr style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; margin: 0; padding: 0;">
<td align="center" style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; margin: 0; padding: 0;">
<p style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 12px; line-height: 1.6em; color: #666666; font-weight: normal; margin: 0 0 10px; padding: 0;">Sent from the MyJekyllBlog Email Robot</p>
<p style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 12px; line-height: 1.6em; color: #666666; font-weight: normal; margin: 0 0 10px; padding: 0;">
</p>
</td>
</tr>
</table>
</div>
<!-- /content -->
</td>
<td style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; font-size: 100%; line-height: 1.6em; margin: 0; padding: 0;"></td>
</tr>
</table>
<!-- /footer -->
</body>
</html>

@ -0,0 +1,9 @@
Hello!
You requested a password reset link.
Here it is: [% link %]
Thank you!
- The MyJekyllBlog Robot

@ -0,0 +1,18 @@
{
"renderer": "TT",
"header": [
{ "To" : "[% send_to %]" },
{ "From" : "MyJekyllBlog Robot <mailbot@myjekyllblog.com>" },
{ "Subject" : "Password reset link for your MyJekyllBlog account" }
],
"alternatives": [
{
"type": "text/plain",
"path": "body.txt"
},
{
"type": "text/html",
"path": "body.html"
}
]
}
Loading…
Cancel
Save