Commit 348e0c79 authored by Floréal Cabanettes's avatar Floréal Cabanettes

Add activation of account + add flash messages, definitively Implements #3

parent a7da8071
......@@ -14,6 +14,8 @@ from jinja2 import ext
from view.register import page as register
from view.panel import page as panel
from settings import SECRET_KEY
from mail import send_mail
from model.recipe import Recipe, Ingredient, Instruction, Category
from model.user import User
......@@ -25,6 +27,7 @@ app.config['BABEL_DEFAULT_LOCALE'] = LOCALE
app.config['BABEL_DEFAULT_TIMEZONE'] = TIMEZONE
app.register_blueprint(register)
app.register_blueprint(panel)
app.secret_key = SECRET_KEY
babel = Babel(app)
db = MongoEngine(app)
crypt = Bcrypt(app)
......
......@@ -14,3 +14,5 @@ MAIL = {
}
PASSWORD_HASH_ROUNDS = 12
SECRET_KEY = "mz(YvhXW:zyVNjLrY[bVSGZC98LH}7SZ[h*A:4{tjB*L?zX*WK" # Change it to be unique for you
\ No newline at end of file
......@@ -44,6 +44,16 @@
<v-alert v-model="show_alert" :type="type_alert" style="margin-top: 15px; position: fixed; width: 100%; z-index: 10;" dismissible>
(( message_alert ))
</v-alert>
{% with messages = get_flashed_messages() %}
{% if messages %}
{% for message in messages %}
{% set message = message.split("|") %}
<v-alert type="{{ message[0] }}" style="margin-top: 15px; position: fixed; width: 100%; z-index: 10;" dismissible>
{{ message[1] }}
</v-alert>
{% endfor %}
{% endif %}
{% endwith %}
{% block bodycontent %}
{% endblock %}
</v-container>
......
......@@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2019-09-01 22:27+0200\n"
"PO-Revision-Date: 2019-09-01 22:28+0200\n"
"POT-Creation-Date: 2019-09-08 17:41+0200\n"
"PO-Revision-Date: 2019-09-08 17:42+0200\n"
"Last-Translator: \n"
"Language: fr\n"
"Language-Team: fr <LL@li.org>\n"
......@@ -19,19 +19,35 @@ msgstr ""
"Generated-By: Babel 2.7.0\n"
"X-Generator: Poedit 2.0.6\n"
#: app.py:49 app.py:53
#: app.py:55 view/panel.py:11
msgid "Panel"
msgstr "Panel"
#: app.py:58
#: app.py:67
msgid "Login"
msgstr "Connexion"
#: templates/404.html:321
msgid "GO BACK HOME"
msgstr "RETOURNER À LA MAISON"
#: templates/basis.html:51
msgid "Close"
msgstr "Fermer"
#: view/register.py:19
msgid "Register"
msgstr "Créer un compte"
#: app.py:73
#: view/register.py:27
msgid "Missing required fields"
msgstr "Des champs requis sont manquants"
#: view/register.py:38
msgid "please activate your account"
msgstr "veuillez activer votre compte"
#: app.py:74
#: view/register.py:39
#, python-format
msgid ""
"Welcome %s,\n"
......@@ -42,7 +58,7 @@ msgstr ""
"\n"
"Merci de cliquer sur ce lien afin d'activer cotre compte sur %s :\n"
#: app.py:77
#: view/register.py:42
msgid ""
"User successfully created. Please check your mail to validate your "
"account."
......@@ -50,18 +66,10 @@ msgstr ""
"Utilisateur créé avec succès. Veuillez vérifier vos mails afin de "
"valider votre compte."
#: app.py:80
#: view/register.py:45
msgid "There is already a user with this mail address"
msgstr "Un utilisateur existe déjà avec cette adresse e-mail"
#: app.py:92
msgid "Login"
msgstr "Connexion"
#: templates/404.html:321
msgid "GO BACK HOME"
msgstr "RETOURNER À LA MAISON"
#: templates/basis.html:50
msgid "Close"
msgstr "Fermer"
#: view/register.py:53
msgid "Invalid request"
msgstr "Requête invalide"
......@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2019-09-01 22:27+0200\n"
"POT-Creation-Date: 2019-09-08 17:41+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......@@ -17,19 +17,35 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.7.0\n"
#: app.py:49 app.py:53
#: app.py:55 view/panel.py:11
msgid "Panel"
msgstr ""
#: app.py:58
#: app.py:67
msgid "Login"
msgstr ""
#: templates/404.html:321
msgid "GO BACK HOME"
msgstr ""
#: templates/basis.html:51
msgid "Close"
msgstr ""
#: view/register.py:19
msgid "Register"
msgstr ""
#: app.py:73
#: view/register.py:27
msgid "Missing required fields"
msgstr ""
#: view/register.py:38
msgid "please activate your account"
msgstr ""
#: app.py:74
#: view/register.py:39
#, python-format
msgid ""
"Welcome %s,\n"
......@@ -37,25 +53,17 @@ msgid ""
"Please click on this link to activate your account on %s:\n"
msgstr ""
#: app.py:77
#: view/register.py:42
msgid ""
"User successfully created. Please check your mail to validate your "
"account."
msgstr ""
#: app.py:80
#: view/register.py:45
msgid "There is already a user with this mail address"
msgstr ""
#: app.py:92
msgid "Login"
msgstr ""
#: templates/404.html:321
msgid "GO BACK HOME"
msgstr ""
#: templates/basis.html:50
msgid "Close"
#: view/register.py:53
msgid "Invalid request"
msgstr ""
import json
import hashlib
from flask import Blueprint, render_template, request, Response, jsonify
from flask import Blueprint, render_template, request, Response, jsonify, flash ,redirect, url_for
from flask_babel import gettext as _
from flask_bcrypt import generate_password_hash
from mongoengine.errors import NotUniqueError
from mongoengine.errors import NotUniqueError, DoesNotExist
from werkzeug.exceptions import BadRequest
from settings import SITE_NAME, PASSWORD_HASH_ROUNDS
......@@ -41,4 +42,23 @@ def register():
message=_("User successfully created. Please check your mail to validate your account."))
except NotUniqueError:
return Response(json.dumps({"success": False,
"message": _("There is already a user with this mail address")}), status=409)
\ No newline at end of file
"message": _("There is already a user with this mail address")}), status=409)
@page.route('/activate')
def activate_account():
token = request.args.get("token")
mail = request.args.get("mail")
if token is None or mail is None:
raise BadRequest(_("Invalid request"))
try:
user = User.objects.get(email=mail)
except DoesNotExist:
pass
else:
user_token = hashlib.md5((user.name + user.email).encode()).hexdigest()
if user_token == token:
user.active = True
user.save()
flash("success|" + _("Your account is now active. You can login in"))
return redirect(url_for("login"))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment