...
 
Commits (3)
**__pycache__
.idea
settings.py
......@@ -10,6 +10,8 @@ from mongoengine.errors import NotUniqueError
from flask_babel import Babel
from flask_babel import gettext as _
from jinja2 import ext
from mail import send_mail
from model.recipe import Recipe, Ingredient, Instruction, Category
from model.user import User
......@@ -58,15 +60,22 @@ def register_page():
@app.route('/register', methods=['POST'])
def register():
data = json.loads(request.data)
if data["email"] is None or data["email"] == "" or data["password"] is None or data["password"] == ""\
or data["name"] is None or data["name"] == "":
return Response(json.dumps({"success": False, "message": _("Missing required fields")}), status=409)
role = "basic"
nb_user = User.objects().count()
if nb_user == 0:
role = "admin"
data = json.loads(request.data)
user = User(name=data["name"], email=data["email"],
password=hashlib.sha3_512(data["password"].encode()).hexdigest(), role=role, active=False)
try:
user.save()
token = "?token=" + hashlib.md5((data["name"] + data["email"]).encode()).hexdigest() + "&mail=" + data["email"]
send_mail(data["email"], f"{site_name} - " + _("please activate your account"),
_("Welcome %s,\n\nPlease click on this link to activate your account on %s:\n") %
(data["name"], site_name) + request.url_root + "activate" + token)
return jsonify(success=True,
message=_("User successfully created. Please check your mail to validate your account."))
except NotUniqueError:
......
# import necessary packages
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from settings import mail
import smtplib
def send_mail(to, subject, message):
# create message object instance
msg = MIMEMultipart()
# setup the parameters of the message
msg['From'] = mail["from"]
msg['To'] = to
msg['Subject'] = subject
# add in the message body
msg.attach(MIMEText(message, 'plain'))
# create server
server = smtplib.SMTP(f'{mail["server"]}: {mail["port"]}')
server.starttls()
# Login Credentials for sending the mail
server.login(mail["username"], mail["password"])
# send the message via the server.
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()
print("successfully sent email to: %s" % (msg['To']))
#!/bin/bash
set -e
pybabel extract -F translations/babel.cfg -o translations/messages.pot .
pybabel update -i translations/messages.pot -d translations
poedit translations/fr/LC_MESSAGES/messages.po
......
......@@ -4,3 +4,12 @@ categories = ["Entrée", "Plat principal", "Dessert", "Accompagnements", "Base",
site_name = "Recipen"
locale = "fr"
timezone = "Europe/Paris"
# PLEASE FILL MAIL SETTINGS TO MAKE REGISTER PAGE WORKING
mail = {
"server": "",
"username": "",
"from": "",
"password": "",
"port": 587
}
......@@ -27,4 +27,28 @@ html {
.main-content {
margin-left: 85px;
}
}
#loading {
margin-top: 10px;
position: fixed;
bottom: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 1000;
}
#loading .loader {
width: 240px;
height: 240px;
background-image: url(/static/img/loader.svg);
background-size: cover;
position: fixed;
bottom: 0;
right: 0;
}
header {
z-index: 1001 !important;
}
\ No newline at end of file
......@@ -35,7 +35,9 @@ init = function(locale, dark=true) {
delimiters: ['((', '))'],
el: '#app',
data: {
message: 'Hello Vue!',
show_alert: false,
message_alert: null,
type_alert: "error",
dark: true,
search: false,
searchText: "",
......@@ -56,20 +58,39 @@ init = function(locale, dark=true) {
loadings: 0,
},
methods: {
notifError(message) {
this.snackbar_color = "error";
alert(message, type_message) {
this.show_alert = true;
this.message_alert = message;
this.type_alert = type_message;
},
alertError(message) {
this.alert(message, "error");
},
alertWarn(message) {
this.alert(message, "warning");
},
alertInfo(message) {
this.alert(message, "info");
},
alertSuccess(message) {
this.alert(message, "success");
},
notif(message, type_message) {
this.snackbar_color = type_message;
this.snackbar_message = message;
this.snackbar = true;
},
notifError(message) {
this.notif(message, "error");
},
notifWarn(message) {
this.snackbar_color = "warning";
this.snackbar_message = message;
this.snackbar = true;
this.notif(message, "warning");
},
notifInfo(message) {
this.snackbar_color = "info";
this.snackbar_message = message;
this.snackbar = true;
this.notif(message, "info");
},
notifSuccess(message) {
this.notif(message, "success");
},
showHideSearch() {
this.searchText = "";
......@@ -109,16 +130,33 @@ init = function(locale, dark=true) {
},
created() {
let $this = this;
// Alert events:
eventBus.$on('alertInfo', function (message) {
this.alertInfo(message);
}.bind(this));
eventBus.$on('alertError', function (message) {
this.alertError(message);
}.bind(this));
eventBus.$on('alertWarn', function (message) {
this.alertWarn(message);
}.bind(this));
eventBus.$on('alertSuccess', function (message) {
this.alertSuccess(message);
}.bind(this));
// Notification events:
eventBus.$on('notifInfo', function (message) {
this.notifInfo(message);
}.bind(this));
eventBus.$on('notifError', function (message) {
console.log("NOTIF ERROR", message);
this.notifError(message);
}.bind(this));
eventBus.$on('notifWarn', function (message) {
this.notifWarn(message);
}.bind(this));
eventBus.$on('notifSuccess', function (message) {
this.notifSuccess(message);
}.bind(this));
eventBus.$on('startLoading', function () {
console.log("start");
$this.loadings += 1;
......
......@@ -12,7 +12,6 @@ Vue.component("main-register", {
<v-form
ref="form"
v-model="valid"
lazy-validation
>
<v-text-field
v-model="name"
......@@ -97,7 +96,7 @@ Vue.component("main-register", {
passwordLength: v => (v && v.length >= 12 || tr('Min 12 characters')),
passwordMatch: v => (v === this.password || tr("Passwords does not match"))
},
valid: true,
valid: false,
}},
methods: {
send() {
......@@ -108,7 +107,9 @@ Vue.component("main-register", {
email: this.email,
password: this.password
},
response => {console.log(response);});
response => {
eventBus.$emit("alertSuccess", response.data.message);
});
}
},
clear() {
......
......@@ -40,6 +40,7 @@
:multi-line="snackbar_multiline"
:top="true"
:color="snackbar_color"
style="z-index: 1002"
>
(( snackbar_message ))
<v-btn
......
......@@ -38,6 +38,12 @@
>
<v-container style="padding-top: 117px; display: table; padding-left: 0; padding-right: 0; margin-left: 0; margin-right: 0; max-width: none;" fill-height>
{# <div style="width: 260px; display: table-cell; vertical-align: top; height: 100%;">#}
<div id="loading" v-show="loadings > 0">
<div class="loader"></div>
</div>
<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>
{% 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 11:29+0200\n"
"PO-Revision-Date: 2019-09-01 11:29+0200\n"
"POT-Creation-Date: 2019-09-01 22:27+0200\n"
"PO-Revision-Date: 2019-09-01 22:28+0200\n"
"Last-Translator: \n"
"Language: fr\n"
"Language-Team: fr <LL@li.org>\n"
......@@ -19,15 +19,30 @@ msgstr ""
"Generated-By: Babel 2.7.0\n"
"X-Generator: Poedit 2.0.6\n"
#: app.py:47 app.py:51
#: app.py:49 app.py:53
msgid "Panel"
msgstr "Panel"
#: app.py:56
#: app.py:58
msgid "Register"
msgstr "Créer un compte"
#: app.py:71
#: app.py:73
msgid "please activate your account"
msgstr "veuillez activer votre compte"
#: app.py:74
#, python-format
msgid ""
"Welcome %s,\n"
"\n"
"Please click on this link to activate your account on %s:\n"
msgstr ""
"Bienvenue %s,\n"
"\n"
"Merci de cliquer sur ce lien afin d'activer cotre compte sur %s :\n"
#: app.py:77
msgid ""
"User successfully created. Please check your mail to validate your "
"account."
......@@ -35,11 +50,11 @@ msgstr ""
"Utilisateur créé avec succès. Veuillez vérifier vos mails afin de "
"valider votre compte."
#: app.py:74
#: app.py:80
msgid "There is already a user with this mail address"
msgstr "Un utilisateur existe déjà avec cette adresse e-mail"
#: app.py:86
#: app.py:92
msgid "Login"
msgstr "Connexion"
......
......@@ -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 11:29+0200\n"
"POT-Creation-Date: 2019-09-01 22:27+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,25 +17,37 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.7.0\n"
#: app.py:47 app.py:51
#: app.py:49 app.py:53
msgid "Panel"
msgstr ""
#: app.py:56
#: app.py:58
msgid "Register"
msgstr ""
#: app.py:71
#: app.py:73
msgid "please activate your account"
msgstr ""
#: app.py:74
#, python-format
msgid ""
"Welcome %s,\n"
"\n"
"Please click on this link to activate your account on %s:\n"
msgstr ""
#: app.py:77
msgid ""
"User successfully created. Please check your mail to validate your "
"account."
msgstr ""
#: app.py:74
#: app.py:80
msgid "There is already a user with this mail address"
msgstr ""
#: app.py:86
#: app.py:92
msgid "Login"
msgstr ""
......