various updates

This commit is contained in:
Andy Miller
2015-07-21 22:02:13 -06:00
parent 23dde43f3e
commit 3f6b0c0fa5
10 changed files with 287 additions and 90 deletions

View File

@@ -176,8 +176,6 @@ class AdminPlugin extends Plugin
$page = new Page;
$page->init(new \SplFileInfo(__DIR__ . "/pages/admin/{$self->template}.md"));
$page->slug(basename($self->template));
$page->extension('.md');
return $page;
};
}

View File

@@ -120,10 +120,12 @@ class AdminController
*/
protected function taskLogin()
{
$l = $this->grav['language'];
if ($this->admin->authenticate($this->post)) {
$this->admin->setMessage('You have been logged in.');
$this->admin->setMessage($l->translate('LOGIN_LOGGED_IN'));
} else {
$this->admin->setMessage('Login failed.');
$this->admin->setMessage($l->translate('LOGIN_FAILED'));
}
return true;
@@ -136,8 +138,10 @@ class AdminController
*/
protected function taskLogout()
{
$l = $this->grav['language'];
$this->admin->session()->invalidate()->start();
$this->admin->setMessage('You have been logged out.');
$this->admin->setMessage($l->translate('LOGGED_OUT'));
$this->setRedirect('/');
return true;
@@ -145,25 +149,27 @@ class AdminController
protected function taskForgot()
{
$l = $this->grav['language'];
$data = $this->post;
$username = isset($data['username']) ? $data['username'] : '';
$user = !empty($username) ? User::load($username) : null;
if (!isset($this->grav['Email'])) {
$this->admin->setMessage('Cannot reset password. This site is not configured to send emails.');
$this->admin->setMessage($l->translate('FORGOT_EMAIL_NOT_CONFIGURED'));
$this->setRedirect('/');
return true;
}
if (!$user || !$user->exists()) {
$this->admin->setMessage('User with username \'' . $username . '\' does not exist.');
$this->admin->setMessage($l->translate(['FORGOT_USERNAME_DOES_NOT_EXIST', $username]));
$this->setRedirect('/forgot');
return true;
}
if (empty($user->email)) {
$this->admin->setMessage('Cannot reset password for \'' . $username . '\', no email address is set.');
$this->admin->setMessage($l->translate(['FORGOT_CANNOT_RESET_EMAIL_NO_EMAIL', $username]));
$this->setRedirect('/forgot');
return true;
}
@@ -178,14 +184,14 @@ class AdminController
$fullname = $user->fullname ?: $username;
$reset_link = rtrim($this->grav['uri']->rootUrl(true), '/') . '/' . trim($this->admin->base, '/') . '/reset/task:reset/user:' . $username . '/token:' . $token;
$from = $this->grav['config']->get('site.author.email', 'noreply@getgrav.org');
$sitename = $this->grav['config']->get('site.title', 'Website');
$from = $this->grav['config']->get('plugins.email.from', 'noreply@getgrav.org');
$to = $user->email;
$subject = $this->grav['config']->get('site.title', 'Website') . ' password reset';
$body = $this->grav['twig']->processString('{% include "email/reset.html.twig" %}', [
'name' => $fullname,
'author' => $author,
'reset_link' =>$reset_link
]);
$subject = $l->translate(['FORGOT_EMAIL_SUBJECT', $sitename]);
$content = $l->translate(['FORGOT_EMAIL_BODY', $fullname, $reset_link, $author, $sitename]);
$body = $this->grav['twig']->processTemplate('email/base.html.twig', ['content' => $content]);
$message = $this->grav['Email']->message($subject, $body, 'text/html')
->setFrom($from)
@@ -194,9 +200,9 @@ class AdminController
$sent = $this->grav['Email']->send($message);
if ($sent < 1) {
$this->admin->setMessage('Failed to email instructions, please try again later.');
$this->admin->setMessage($l->translate('FORGOT_FAILED_TO_EMAIL'));
} else {
$this->admin->setMessage('Instructions to reset your password have been sent by email.');
$this->admin->setMessage($l->translate(['FORGOT_INSTRUCTIONS_SENT_VIA_EMAIL', $to]));
}
$this->setRedirect('/');
@@ -205,10 +211,11 @@ class AdminController
public function taskReset()
{
$l = $this->grav['language'];
$data = $this->post;
if (isset($data['password'])) {
$username = isset($data['username']) ? $data['username'] : null;
$user = !empty($username) ? User::load($username) : null;
$password = isset($data['password']) ? $data['password'] : null;
@@ -218,9 +225,8 @@ class AdminController
list($good_token, $expire) = explode('::', $user->reset);
if ($good_token === $token) {
if (time() > $expire) {
$this->admin->setMessage('Reset link has expired, please try again.');
$this->admin->setMessage($l->translate('RESET_LINK_EXPIRED'));
$this->setRedirect('/forgot');
return true;
}
@@ -231,13 +237,13 @@ class AdminController
$user->password = $password;
$user->save();
$this->admin->setMessage('Password has been reset.');
$this->admin->setMessage($l->translate('RESET_PASSWORD_RESET'));
$this->setRedirect('/');
return true;
}
}
$this->admin->setMessage('Invalid reset link used, please try again.');
$this->admin->setMessage($l->translate('RESET_INVALID_LINK'));
$this->setRedirect('/forgot');
return true;
@@ -246,7 +252,7 @@ class AdminController
$token = $this->grav['uri']->param('token');
if (empty($user) || empty($token)) {
$this->admin->setMessage('Invalid reset link used, please try again.');
$this->admin->setMessage($l->translate('RESET_INVALID_LINK'));
$this->setRedirect('/forgot');
return true;
}

19
languages.yaml Normal file
View File

@@ -0,0 +1,19 @@
en:
EMAIL_FOOTER: <a href="http://getgrav.org">Powered by Grav</a> - The Modern Flat File CMS
LOGIN_BTN: Login
LOGIN_BTN_FORGOT: Forgot
LOGIN_BTN_RESET: Reset Password
LOGIN_BTN_SEND_INSTRUCTIONS: Send Reset Instructions
LOGIN_LOGGED_IN: You have been logged in
LOGIN_FAILED: Login failed
LOGGED_OUT: You have been logged out
RESET_LINK_EXPIRED: Reset link has expired, please try again
RESET_PASSWORD_RESET: Password has been reset
RESET_INVALID_LINK: Invalid reset link used, please try again
FORGOT_INSTRUCTIONS_SENT_VIA_EMAIL: Instructions to reset your password have been sent via email to %s
FORGOT_FAILED_TO_EMAIL: Failed to email instructions, please try again later
FORGOT_CANNOT_RESET_EMAIL_NO_EMAIL: Cannot reset password for %s, no email address is set
FORGOT_USERNAME_DOES_NOT_EXIST: User with username <b>%s</b> does not exist
FORGOT_EMAIL_NOT_CONFIGURED: Cannot reset password. This site is not configured to send emails
FORGOT_EMAIL_SUBJECT: %s Password Reset Request
FORGOT_EMAIL_BODY: <h1>Password Reset</h1><p>Dear %1$s,</p><p>A request was made on <b>%4$s</b> to reset your password.</p><p><br /><a href="%2$s" class="btn-primary">Click this to reset your password</a><br /><br /></p><p>Alternatively, copy the following URL into your browser's address bar:</p> <p>%2$s</p><p><br />Kind regards,<br /><br />%3$s</p>

View File

@@ -1,11 +1,194 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
{% block head %}
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
{% endblock %}
<title>Really Simple HTML Email Template</title>
<style>
/* -------------------------------------
GLOBAL
------------------------------------- */
* {
margin: 0;
padding: 0;
font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;
font-size: 100%;
line-height: 1.6;
}
img {
max-width: 100%;
}
body {
-webkit-font-smoothing: antialiased;
-webkit-text-size-adjust: none;
width: 100%!important;
height: 100%;
}
/* -------------------------------------
ELEMENTS
------------------------------------- */
a {
color: #348eda;
}
.btn-primary {
text-decoration: none;
color: #FFF;
background-color: #348eda;
border: solid #348eda;
border-width: 10px 20px;
line-height: 2;
font-weight: bold;
margin-right: 10px;
text-align: center;
cursor: pointer;
display: inline-block;
border-radius: 25px;
}
.btn-secondary {
text-decoration: none;
color: #FFF;
background-color: #aaa;
border: solid #aaa;
border-width: 10px 20px;
line-height: 2;
font-weight: bold;
margin-right: 10px;
text-align: center;
cursor: pointer;
display: inline-block;
border-radius: 25px;
}
.last {
margin-bottom: 0;
}
.first {
margin-top: 0;
}
.padding {
padding: 10px 0;
}
/* -------------------------------------
BODY
------------------------------------- */
table.body-wrap {
width: 100%;
padding: 20px;
}
table.body-wrap .container {
border: 1px solid #f0f0f0;
}
/* -------------------------------------
FOOTER
------------------------------------- */
table.footer-wrap {
width: 100%;
clear: both!important;
}
.footer-wrap .container p {
font-size: 12px;
color: #666;
}
table.footer-wrap a {
color: #999;
}
/* -------------------------------------
TYPOGRAPHY
------------------------------------- */
h1, h2, h3 {
font-family: "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
color: #000;
margin: 40px 0 10px;
line-height: 1.2;
font-weight: 200;
}
h1 {
font-size: 36px;
}
h2 {
font-size: 28px;
}
h3 {
font-size: 22px;
}
p, ul, ol {
margin-bottom: 10px;
font-weight: normal;
font-size: 14px;
}
ul li, ol li {
margin-left: 5px;
list-style-position: inside;
}
/* ---------------------------------------------------
RESPONSIVENESS
Nuke it from orbit. It's the only way to be sure.
------------------------------------------------------ */
/* Set a max-width, and make it display as block so it will automatically stretch to that width, but will also shrink down on a phone or something */
.container {
display: block!important;
max-width: 600px!important;
margin: 0 auto!important; /* makes it centered */
clear: both!important;
}
/* Set the padding on the td rather than the div for Outlook compatibility */
.body-wrap .container {
padding: 20px;
}
/* This should also be a block element, so that it will fill 100% of the .container */
.content {
max-width: 600px;
margin: 0 auto;
display: block;
}
/* Let's make sure tables in the content area are 100% wide */
.content table {
width: 100%;
}
</style>
</head>
<body>
{% block content %}{% endblock %}
<body bgcolor="#f6f6f6">
<!-- body -->
<table class="body-wrap" bgcolor="#f6f6f6">
<tr>
<td></td>
<td class="container" bgcolor="#FFFFFF">
<div class="content">
<table>
<tr>
<td>
{{ content }}
</td>
</tr>
</table>
</div>
</td>
<td></td>
</tr>
</table>
<!-- /body -->
<!-- footer -->
<table class="footer-wrap">
<tr>
<td></td>
<td class="container">
<div class="content">
<table>
<tr>
<td align="center">
{{ 'EMAIL_FOOTER'|t }}
</td>
</tr>
</table>
</div>
</td>
<td></td>
</tr>
</table>
<!-- /footer -->
</body>
</html>

View File

@@ -1,25 +1,17 @@
{% extends 'partials/base.html.twig' %}
{% embed 'partials/login.html.twig' with {title:'Grav Forgot Password'} %}
{% block page %}
<section id="admin-login" class="default-glow-shadow">
<h1>
Grav forgot password
</h1>
{% block form %}
{% for field in page.header.form.fields %}
{% if field.type %}
<div>
{% include ["forms/fields/#{field.type}/#{field.type}.html.twig", 'forms/fields/text/text.html.twig'] %}
</div>
{% endif %}
{% endfor %}
<div class="form-actions secondary-accent">
<button type="submit" class="button primary" name="task" value="forgot"><i class="fa fa-paper-plane"></i> {{ "LOGIN_BTN_SEND_INSTRUCTIONS"|t }}</button>
</div>
{% endblock %}
{% include 'partials/messages.html.twig' %}
<form method="post" action="{{ base_url_relative }}">
{% for field in page.header.form.fields %}
{% if field.type %}
<div>
{% include ["forms/fields/#{field.type}/#{field.type}.html.twig", 'forms/fields/text/text.html.twig'] %}
</div>
{% endif %}
{% endfor %}
<div class="form-actions secondary-accent">
<button type="submit" class="button primary" name="task" value="forgot"><i class="fa fa-paper-plane"></i> Send reset instructions</button>
</div>
</form>
</section>
{% endblock %}
{% endembed %}

View File

@@ -18,6 +18,7 @@
name="{{ (scope ~ field.name)|fieldName }}"
value="{{ value|join(', ') }}"
{% if field.placeholder %}placeholder="{{ field.placeholder }}"{% endif %}
{% if field.title %}title="{{ field.title }}"{% endif %}
{% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %}
{% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
{% if field.autocomplete in ['on', 'off'] %}autocomplete="{{ field.autocomplete }}"{% endif %}

View File

@@ -18,6 +18,7 @@
name="{{ (scope ~ field.name)|fieldName }}"
value="{{ value|join(', ') }}"
{% if field.placeholder %}placeholder="{{ field.placeholder }}"{% endif %}
{% if field.title %}title="{{ field.title }}"{% endif %}
{% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %}
{% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
{% if field.readonly in ['on', 'true', 1] %}readonly="readonly"{% endif %}

View File

@@ -1,15 +1,7 @@
{% extends 'partials/base.html.twig' %}
{% embed 'partials/login.html.twig' with {title:'Grav Login'} %}
{% block page %}
<section id="admin-login" class="default-glow-shadow">
<h1>
Grav Login
</h1>
{% include 'partials/messages.html.twig' %}
<form method="post" action="{{ base_url_relative }}">
{% for field in page.header.form.fields %}
{% block form %}
{% for field in page.header.form.fields %}
{% if field.type %}
<div>
{% include ["forms/fields/#{field.type}/#{field.type}.html.twig", 'forms/fields/text/text.html.twig'] %}
@@ -17,10 +9,10 @@
{% endif %}
{% endfor %}
<div class="form-actions secondary-accent">
<a class="button secondary" href="{{ base_url_relative }}/forgot"><i class="fa fa-exclamation-circle"></i> Forgot</a>
<button type="submit" class="button primary" name="task" value="login"><i class="fa fa-sign-in"></i> Login</button>
<a class="button secondary" href="{{ base_url_relative }}/forgot"><i class="fa fa-exclamation-circle"></i> {{ 'LOGIN_BTN_FORGOT'|t }}</a>
<button type="submit" class="button primary" name="task" value="login"><i class="fa fa-sign-in"></i> {{ 'LOGIN_BTN'|t }}</button>
</div>
</form>
</section>
{% endblock %}
{% endblock %}
{% endembed %}

View File

@@ -0,0 +1,15 @@
{% extends 'partials/base.html.twig' %}
{% block page %}
<section id="admin-login" class="default-glow-shadow">
<h1>
{{ title }}
</h1>
{% include 'partials/messages.html.twig' %}
<form method="post" action="{{ base_url_relative }}">
{% block form %}{% endblock %}
</form>
</section>
{% endblock %}

View File

@@ -1,29 +1,19 @@
{% extends 'partials/base.html.twig' %}
{% embed 'partials/login.html.twig' with {title:'Grav Reset Password'} %}
{% block page %}
<section id="admin-login" class="default-glow-shadow">
<h1>
Reset Grav password
</h1>
{% block form %}
{% for field in page.header.form.fields %}
{% set value = attribute(admin.forgot, field.name) is defined ? attribute(admin.forgot, field.name) : null %}
{% include 'partials/messages.html.twig' %}
{% if field.type %}
<div>
{% include ["forms/fields/#{field.type}/#{field.type}.html.twig", 'forms/fields/text/text.html.twig'] %}
</div>
{% endif %}
{% endfor %}
<div class="form-actions secondary-accent">
<button type="submit" class="button primary" name="task" value="reset"><i class="fa fa-key"></i> {{ 'LOGIN_BTN_RESET'|t }}</button>
</div>
{% endblock %}
<form method="post" action="{{ base_url_relative }}">
{% for field in page.header.form.fields %}
{% set value = attribute(admin.forgot, field.name) is defined ? attribute(admin.forgot, field.name) : null %}
{% if field.type %}
<div>
{% include ["forms/fields/#{field.type}/#{field.type}.html.twig", 'forms/fields/text/text.html.twig'] %}
</div>
{% endif %}
{% endfor %}
<div class="form-actions secondary-accent">
<button type="submit" class="button primary" name="task" value="reset"><i class="fa fa-key"></i> Reset password</button>
</div>
</form>
</section>
{% endblock %}
{% endembed %}