Merge pull request #1021 from wallabag/register

working on registration support
This commit is contained in:
Thomas Citharel 2015-02-14 13:46:05 +01:00
commit 7780b8cb37
12 changed files with 113 additions and 13 deletions

View file

@ -76,6 +76,7 @@ class Poche
*/ */
public function createNewUser($username, $password, $email = "", $internalRegistration = false) public function createNewUser($username, $password, $email = "", $internalRegistration = false)
{ {
Tools::logm('Trying to create a new user...');
if (!empty($username) && !empty($password)){ if (!empty($username) && !empty($password)){
$newUsername = filter_var($username, FILTER_SANITIZE_STRING); $newUsername = filter_var($username, FILTER_SANITIZE_STRING);
$email = filter_var($email, FILTER_SANITIZE_STRING); $email = filter_var($email, FILTER_SANITIZE_STRING);
@ -84,7 +85,7 @@ class Poche
if ($email != "") { // if email is filled if ($email != "") { // if email is filled
if (SEND_CONFIRMATION_EMAIL && function_exists('mail')) { if (SEND_CONFIRMATION_EMAIL && function_exists('mail')) {
// if internal registration // if internal registration from config screen
$body_internal = _('Hi,') . "\r\n\r\n" . sprintf(_('Someone just created a wallabag account for you on %1$s.'), Tools::getPocheUrl()) . $body_internal = _('Hi,') . "\r\n\r\n" . sprintf(_('Someone just created a wallabag account for you on %1$s.'), Tools::getPocheUrl()) .
"\r\n\r\n" . sprintf(_('Your login is %1$s.'), $newUsername) ."\r\n\r\n" . "\r\n\r\n" . sprintf(_('Your login is %1$s.'), $newUsername) ."\r\n\r\n" .
_('Note : The password has been chosen by the person who created your account. Get in touch with that person to know your password and change it as soon as possible') . "\r\n\r\n" . _('Note : The password has been chosen by the person who created your account. Get in touch with that person to know your password and change it as soon as possible') . "\r\n\r\n" .
@ -92,7 +93,10 @@ class Poche
_('This is an automatically generated message, no one will answer if you respond to it.'); _('This is an automatically generated message, no one will answer if you respond to it.');
// if external (public) registration // if external (public) registration
$body = "Hi, " . $newUsername . "\r\n\r\nYou've just created a wallabag account on " . Tools::getPocheUrl() . ".\r\nHave fun with it !"; $body = sprintf(_('Hi, %1$s'), $newUsername) . "\r\n\r\n" .
sprintf(_('You\'ve just created a wallabag account on %1$s.'), Tools::getPocheUrl()) .
"\r\n\r\n" . _("Have fun with it !");
$body = $internalRegistration ? $body_internal : $body; $body = $internalRegistration ? $body_internal : $body;
$body = wordwrap($body, 70, "\r\n"); // cut lines with more than 70 caracters (MIME standard) $body = wordwrap($body, 70, "\r\n"); // cut lines with more than 70 caracters (MIME standard)
@ -102,6 +106,7 @@ class Poche
"From: " . $newUsername . "@" . gethostname() . "\r\n")) { "From: " . $newUsername . "@" . gethostname() . "\r\n")) {
Tools::logm('The user ' . $newUsername . ' has been emailed'); Tools::logm('The user ' . $newUsername . ' has been emailed');
$this->messages->add('i', sprintf(_('The new user %1$s has been sent an email at %2$s. You may have to check spam folder.'), $newUsername, $email)); $this->messages->add('i', sprintf(_('The new user %1$s has been sent an email at %2$s. You may have to check spam folder.'), $newUsername, $email));
Tools::redirect('?');
} else { } else {
Tools::logm('A problem has been encountered while sending an email'); Tools::logm('A problem has been encountered while sending an email');
@ -109,14 +114,16 @@ class Poche
} }
} else { } else {
Tools::logm('The user has been created, but the server did not authorize sending emails'); Tools::logm('The user has been created, but the server did not authorize sending emails');
$this->messages->add('i', _('The server did not authorize sending a confirmation email')); $this->messages->add('i', _('The server did not authorize sending a confirmation email, but the user was created.'));
} }
} else { } else {
Tools::logm('The user has been created, but no email was saved, so no confimation email was sent'); Tools::logm('The user has been created, but no email was saved, so no confimation email was sent');
$this->messages->add('i', _('The user was created, but no email was sent because email was not filled in')); $this->messages->add('i', _('The user was created, but no email was sent because email was not filled in'));
} }
Tools::logm('The new user ' . $newUsername . ' has been installed'); Tools::logm('The new user ' . $newUsername . ' has been installed');
$this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to <a href="?logout">logout ?</a>'), $newUsername)); if (\Session::isLogged()) {
$this->messages->add('s', sprintf(_('The new user %s has been installed. Do you want to <a href="?logout">logout ?</a>'), $newUsername));
}
Tools::redirect(); Tools::redirect();
} }
else { else {
@ -130,6 +137,9 @@ class Poche
Tools::redirect(); Tools::redirect();
} }
} }
else {
Tools::logm('Password or username were empty');
}
} }
/** /**

View file

@ -68,6 +68,12 @@ class Routing
$this->wallabag->action($this->action, $this->url, $this->id, FALSE, $this->autoclose); $this->wallabag->action($this->action, $this->url, $this->id, FALSE, $this->autoclose);
$tplFile = Tools::getTplFile($this->view); $tplFile = Tools::getTplFile($this->view);
$tplVars = array_merge($this->vars, $this->wallabag->displayView($this->view, $this->id)); $tplVars = array_merge($this->vars, $this->wallabag->displayView($this->view, $this->id));
} elseif(ALLOW_REGISTER && isset($_GET['registerform'])) {
Tools::logm('register');
$tplFile = Tools::getTplFile('register');
} elseif (ALLOW_REGISTER && isset($_GET['register'])){
$this->wallabag->createNewUser($_POST['newusername'], $_POST['password4newuser'], $_POST['newuseremail']);
Tools::redirect();
} elseif(isset($_SERVER['PHP_AUTH_USER'])) { } elseif(isset($_SERVER['PHP_AUTH_USER'])) {
if($this->wallabag->store->userExists($_SERVER['PHP_AUTH_USER'])) { if($this->wallabag->store->userExists($_SERVER['PHP_AUTH_USER'])) {
$this->wallabag->login($this->referer); $this->wallabag->login($this->referer);
@ -105,7 +111,9 @@ class Routing
$tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0); $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0);
$limit = (isset($_GET['limit']) ? intval($_GET['limit']) : 0); $limit = (isset($_GET['limit']) ? intval($_GET['limit']) : 0);
$this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type'], $limit); $this->wallabag->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type'], $limit);
} } //elseif (ALLOW_REGISTER && isset($_GET['register'])) {
//$this->wallabag->register
//}
//allowed ONLY to logged in user //allowed ONLY to logged in user
if (\Session::isLogged() === true) if (\Session::isLogged() === true)

View file

@ -117,7 +117,7 @@ final class Tools
{ {
$views = array( $views = array(
'install', 'import', 'export', 'config', 'tags', 'install', 'import', 'export', 'config', 'tags',
'edit-tags', 'view', 'login', 'error', 'about' 'edit-tags', 'view', 'login', 'error', 'about', 'register'
); );
return (in_array($view, $views) ? $view . '.twig' : 'home.twig'); return (in_array($view, $views) ? $view . '.twig' : 'home.twig');

View file

@ -60,7 +60,8 @@
@define ('PDF', FALSE); @define ('PDF', FALSE);
// registration // registration
@define ('SEND_CONFIRMATION_EMAIL', TRUE); @define ('SEND_CONFIRMATION_EMAIL', FALSE);
@define ('ALLOW_REGISTER', TRUE);
// display or not print link in article view // display or not print link in article view
@define ('SHOW_PRINTLINK', '1'); @define ('SHOW_PRINTLINK', '1');

View file

@ -369,8 +369,8 @@ msgstr "Mark all the entries as read"
msgid "Return home" msgid "Return home"
msgstr "Return home" msgstr "Return home"
msgid "Back to top" msgid "back"
msgstr "Back to top" msgstr "back"
msgid "Mark as read" msgid "Mark as read"
msgstr "Mark as read" msgstr "Mark as read"
@ -435,6 +435,9 @@ msgstr "Save a Link"
msgid "back to home" msgid "back to home"
msgstr "Back to Home" msgstr "Back to Home"
msgid "back to login"
msgstr "back to login"
msgid "toggle mark as read" msgid "toggle mark as read"
msgstr "Toggle mark as read" msgstr "Toggle mark as read"
@ -673,6 +676,9 @@ msgstr "Hi, %1$s"
msgid "Someone just created a wallabag account for you on %1$s." msgid "Someone just created a wallabag account for you on %1$s."
msgstr "Someone just created a wallabag account for you on %1$s." msgstr "Someone just created a wallabag account for you on %1$s."
msgid "You've just created a wallabag account on %1$s"
msgstr "You've just created a wallabag account on %1$s"
msgid "Your login is %1$s." msgid "Your login is %1$s."
msgstr "Your login is %1$s." msgstr "Your login is %1$s."
@ -702,8 +708,12 @@ msgstr ""
"The new user %1$s has been sent an email at %2$s. You may have to check spam " "The new user %1$s has been sent an email at %2$s. You may have to check spam "
"folder." "folder."
msgid "A problem has been encountered while sending the confirmation email" msgid ""
msgstr "A problem has been encountered while sending an confirmation email" "A problem has been encountered while sending the confirmation email, but the "
"user was created."
msgstr ""
"A problem has been encountered while sending an confirmation email, but the "
"user was created."
msgid "The server did not authorize sending a confirmation email" msgid "The server did not authorize sending a confirmation email"
msgstr "The server did not authorize sending a confirmation email" msgstr "The server did not authorize sending a confirmation email"

View file

@ -67,6 +67,9 @@ msgstr "Se connecter"
msgid "back to home" msgid "back to home"
msgstr "retour à l'accueil" msgstr "retour à l'accueil"
msgid "back"
msgstr "retour"
msgid "favorites" msgid "favorites"
msgstr "favoris" msgstr "favoris"
@ -357,6 +360,9 @@ msgstr "Tweet"
msgid "Email" msgid "Email"
msgstr "E-mail" msgstr "E-mail"
msgid "Email (not required)"
msgstr "E-mail (non requis)"
msgid "shaarli" msgid "shaarli"
msgstr "Shaarli" msgstr "Shaarli"
@ -800,6 +806,9 @@ msgid "Someone just created a wallabag account for you on %1$s."
msgstr "" msgstr ""
"Quelqu'un vient juste de créer un compte wallabag pour vous à l'adresse %1$s." "Quelqu'un vient juste de créer un compte wallabag pour vous à l'adresse %1$s."
msgid "You've just created a wallabag account on %1$s"
msgstr "Vous venez juste de vous créer un compte wallabag sur %1$s"
msgid "Your login is %1$s." msgid "Your login is %1$s."
msgstr "Votre identifiant is %1$s." msgstr "Votre identifiant is %1$s."
@ -832,8 +841,12 @@ msgstr ""
msgid "A problem has been encountered while sending the confirmation email" msgid "A problem has been encountered while sending the confirmation email"
msgstr "Un problème a été rencontré lors de l'envoi de l'email de confirmation" msgstr "Un problème a été rencontré lors de l'envoi de l'email de confirmation"
msgid "The server did not authorize sending a confirmation email" msgid ""
msgstr "Le serveur n'autorise pas l'envoi d'un email de confirmation" "The server did not authorize sending a confirmation email, but the user was "
"created."
msgstr ""
"Le serveur n'autorise pas l'envoi d'un email de confirmation, mais "
"l'utilisateur a été créé."
msgid "" msgid ""
"The user was created, but no email was sent because email was not filled in" "The user was created, but no email was sent because email was not filled in"

View file

@ -26,6 +26,11 @@
<div class="row mts txtcenter"> <div class="row mts txtcenter">
<button class="bouton" type="submit" tabindex="4">{% trans "Sign in" %}</button> <button class="bouton" type="submit" tabindex="4">{% trans "Sign in" %}</button>
</div> </div>
{% if constant('ALLOW_REGISTER') == 1 %}
<div class="register">
<a href="?registerform">{% trans "Register" %}</a>
</div>
{% endif %}
</fieldset> </fieldset>
<input type="hidden" name="returnurl" value="{{ referer }}"> <input type="hidden" name="returnurl" value="{{ referer }}">
<input type="hidden" name="token" value="{{ token }}"> <input type="hidden" name="token" value="{{ token }}">

View file

@ -0,0 +1,28 @@
{% extends "layout-login.twig" %}
{% block content %}
<form method="post" action="?register">
<h2>{% trans 'Add user' %}</h2>
<fieldset class="w500p">
<div class="row">
<label class="col w150p" for="newusername">{% trans 'Login' %}</label>
<input class="col" type="text" id="newusername" name="newusername" placeholder="{% trans 'Login' %}" required>
</div>
<div class="row">
<label class="col w150p" for="password4newuser">{% trans "Password" %}</label>
<input class="col" type="password" id="password4newuser" name="password4newuser" placeholder="{% trans 'Password' %}" required>
</div>
<div class="row">
<label class="col w150p" for="newuseremail">{% trans 'Email (not required)' %}</label>
<input class="col" type="email" id="newuseremail" name="newuseremail" placeholder="{% trans 'Email' %}">
</div>
<div class="row mts txtcenter">
<button type="submit">{% trans "Register" %}</button>
</div>
<div class="register">
<a href="?">{% trans "Back" %}</a>
</div>
</fieldset>
</form>
{% endblock %}

View file

@ -31,4 +31,9 @@
<input type="hidden" name="token" value="{{ token }}"> <input type="hidden" name="token" value="{{ token }}">
</form> </form>
{% endif %} {% endif %}
{% if constant('ALLOW_REGISTER') == 1 %}
<div class="registerform">
<a href="?register">{% trans "Register" %}</a>
</div>
{% endif %}
{% endblock %} {% endblock %}

View file

@ -0,0 +1,20 @@
<h2>{% trans 'Add user' %}</h2>
<form method="post" action="?newuser">
<fieldset class="w500p">
<div class="row">
<label class="col w150p" for="newusername">{% trans 'Login' %}</label>
<input class="col" type="text" id="newusername" name="newusername" placeholder="{% trans 'Login' %}" required>
</div>
<div class="row">
<label class="col w150p" for="password4newuser">{% trans "Password" %}</label>
<input class="col" type="password" id="password4newuser" name="password4newuser" placeholder="{% trans 'Password' %}" required>
</div>
<div class="row">
<label class="col w150p" for="newuseremail">{% trans 'Email' %}</label>
<input class="col" type="email" id="newuseremail" name="newuseremail" placeholder="{% trans 'Email' %}">
</div>
<div class="row mts txtcenter">
<button type="submit">{% trans "Register" %}</button>
</div>
</fieldset>
</form>