diff --git a/backend/OLA_DATA.mysql b/backend/OLA_DATA.mysql
index 53b4cc0..65e56a8 100644
--- a/backend/OLA_DATA.mysql
+++ b/backend/OLA_DATA.mysql
@@ -1,5 +1,5 @@
USE OLA;
-INSERT INTO SETTINGS VALUES ('URL_BASE_DIRECTORY', '/OLA_RESSOURCES/', 'Répertoire base pour le dépot des fichiers');
+INSERT INTO SETTINGS VALUES ('BASE_DIRECTORY', '/OLA_RESSOURCES/', 'Répertoire base pour le dépot des fichiers');
INSERT INTO SETTINGS VALUES ('OLA_URL', 'ola.univ-tlse2.fr/', 'URL de l application');
INSERT INTO `USER` VALUES (1, '1', 'sec@univ-tlse2.fr', 'Secrétaire', DEFAULT, 'aZeRtYuIoP', '01.23.45.67.89');
diff --git a/backend/app/OLA_DATA.mysql b/backend/app/OLA_DATA.mysql
new file mode 100644
index 0000000..31fd9a8
--- /dev/null
+++ b/backend/app/OLA_DATA.mysql
@@ -0,0 +1,18 @@
+USE OLA;
+INSERT INTO SETTINGS VALUES ('URL_BASE_DIRECTORY', '/OLA_RESSOURCES/', 'Répertoire base pour le dépot des fichiers');
+INSERT INTO SETTINGS VALUES ('OLA_URL', 'ola.univ-tlse2.fr/', 'URL de l application');
+
+INSERT INTO `USER` VALUES (1, 'sec', '1', 'sec@univ-tlse2.fr', '01.23.45.67.89');
+INSERT INTO `USER` VALUES (2, 'etu1', '4', 'etu1@univ-tlse2.fr', '01.23.45.67.89');
+INSERT INTO `USER` VALUES (3, 'etu2', '4', 'etu2@univ-tlse2.fr', '01.23.45.67.89');
+INSERT INTO `USER` VALUES (4, 'etu3', '4', 'etu3@univ-tlse2.fr', '01.23.45.67.89');
+INSERT INTO `USER` VALUES (5, 'resp', '2-3', 'resp@univ-tlse2.fr', '01.23.45.67.89');
+INSERT INTO `USER` VALUES (6, 'tut', '3', 'tut@univ-tlse2.fr', '01.23.45.67.89');
+
+INSERT INTO `GROUP` VALUES (1, 'M2_ICE_2016-2017_TEST', '2017', 'Master2 ICE', 'Master 2 Informatique Collaborative en Entreprise', 'Sciences du chômage proffessionnel', 5, 1, '/home/dan/PycharmProjects/OLA/backend/app/OLA_RESSOURCES/M2_ICE_2016-2017_TEST');
+INSERT INTO `GROUP` VALUES (2, 'M1_ICE_2016-2017_TEST', '2017', 'Master1 ICE', 'Master 1 Informatique Collaborative en Entreprise', 'Sciences du chômage proffessionnel', 5, 1, '/home/dan/PycharmProjects/OLA/backend/app/OLA_RESSOURCES/M1_ICE_2016-2017_TEST');
+
+INSERT INTO TUTORSHIP VALUES (DEFAULT, 1, 5, 2);
+INSERT INTO TUTORSHIP VALUES (DEFAULT, 2, 5, 4);
+INSERT INTO TUTORSHIP VALUES (DEFAULT, 1, 6, 3);
+
diff --git a/backend/app/api/GroupAPI.py b/backend/app/api/GroupAPI.py
index 6242511..a8b13c3 100644
--- a/backend/app/api/GroupAPI.py
+++ b/backend/app/api/GroupAPI.py
@@ -24,7 +24,7 @@ class GroupAPI(Resource):
department = args['department']
resp_id = args['resp_id']
sec_id = args['sec_id']
- res_dir = getParam('URL_BASE_DIRECTORY') + name + "/"
+ res_dir = getParam('BASE_DIRECTORY') + name + "/"
mails = []
group = getGroup(name=name)
@@ -97,7 +97,7 @@ class GroupAPI(Resource):
department = args['department']
resp_id = args['resp_id']
sec_id = args['sec_id']
- res_dir = getParam('URL_BASE_DIRECTORY') + name + "/"
+ res_dir = getParam('BASE_DIRECTORY') + name + "/"
mails = []
group = getGroup(gid=gid)
diff --git a/backend/app/api/LoginAPI.py b/backend/app/api/LoginAPI.py
index 13a4b15..4990769 100644
--- a/backend/app/api/LoginAPI.py
+++ b/backend/app/api/LoginAPI.py
@@ -1,8 +1,11 @@
+from hashlib import sha256
+
from flask import session
from flask_restful import Resource
from flask_restful.reqparse import RequestParser
-from app.model import getUser
+from app.core import app
+from app.model import USER
class LoginAPI(Resource):
@@ -15,18 +18,31 @@ class LoginAPI(Resource):
parser.add_argument('email', required=True, help="Email cannot be blank!")
parser.add_argument('password', required=True, help="Password cannot be blank!")
args = parser.parse_args()
+ email = args['email']
+ psw = args['password']
+ password = sha256(psw.encode('utf-8')).hexdigest()
if "user" in session and session["user"] is not None:
return {'AUTH_RESULT': 'ALREADY_LOGGED'}, 201
- user = getUser(email=args['email'])
+ query = USER.select(USER.c.email == email)
+ rows = query.execute()
+ user = rows.first()
- if user is not None and args['password'] == args['email']:
- session['user'] = user
- return {'AUTH_RESULT': 'OK'}, 200
+ if app.config['TESTING']:
+ if user is not None and psw == email:
+ session['user'] = user
+ return {'AUTH_RESULT': 'OK'}, 200
+ else:
+ session['user'] = None
+ return {'AUTH_RESULT': 'AUTHENTICATION_FAILED'}, 401
else:
- session['user'] = None
- return {'AUTH_RESULT': 'AUTHENTICATION_FAILED'}, 401
+ if user is not None and password == user.psw:
+ session['user'] = user
+ return {'AUTH_RESULT': 'OK'}, 200
+ else:
+ session['user'] = None
+ return {'AUTH_RESULT': 'AUTHENTICATION_FAILED'}, 401
def delete(self):
session['user'] = None
diff --git a/backend/app/api/UserAPI.py b/backend/app/api/UserAPI.py
index 6583c39..fd4b9be 100644
--- a/backend/app/api/UserAPI.py
+++ b/backend/app/api/UserAPI.py
@@ -59,8 +59,10 @@ class UserAPI(Resource):
query.execute()
return {"UID": uid}, 200
- def get(self, uid=0, email=""):
+ def get(self, uid=0, email="", hashcode=""):
if uid > 0:
return {'USER': getUser(uid=uid)}, 200
elif email != "":
return {'USER': getUser(email=email)}, 200
+ elif hash != "":
+ return {'USER': getUser(hashcode=hashcode)}, 200
diff --git a/backend/app/api/mailsModels.py b/backend/app/api/mailsModels.py
index abc2af1..e928d94 100644
--- a/backend/app/api/mailsModels.py
+++ b/backend/app/api/mailsModels.py
@@ -4,8 +4,8 @@ _NEW_STUD_OF_GROUP = ("Votre compte OLA a été créé !", "Bonjour,
Votr "#URL
Bonne journée !
") _STUD_OF_GROUP = ( -"Vous avez été ajouté à un groupe OLA !", "Bonjour,Votre compte vient d'être ajouté dans l'Outil du "
- "Livret de l'Alternant au groupe #GROUPE. Vous pouvez dès "
+ "Vous avez été ajouté à un groupe OLA !", "Bonjour,
Votre compte vient d'être ajouté dans l'Outil du "
+ "Livret de l'Alternant au groupe #GROUPE. Vous pouvez dès "
"maintenant créer un livret en vous rendant à l'adresse :
"
"#URL
Bonne journée !
") @@ -15,10 +15,10 @@ _NEW_RESP_OF_GROUP = ("Votre compte OLA a été créé !", "Bonjour,Votr "#URL
Bonne journée !
") _RESP_OF_GROUP = ( -"Vous avez été ajouté à un groupe OLA !", "Bonjour,Votre compte vient d'être ajouté dans l'Outil du "
- "Livret de l'Alternant en tant que responsable du groupe #GROUPE. Vous pouvez dès "
- "maintenant y accéder en vous rendant à l'adresse :
"
- "#URL
Bonne journée !
") + "Vous avez été ajouté à un groupe OLA !", "Bonjour,Votre compte vient d'être ajouté dans l'Outil du "
+ "Livret de l'Alternant en tant que responsable du groupe #GROUPE. Vous pouvez dès "
+ "maintenant y accéder en vous rendant à l'adresse :
"
+ "#URL
Bonne journée !
") _NEW_SEC_OF_GROUP = ("Votre compte OLA a été créé !", "Bonjour,Votre compte vient d'être créé dans l'Outil du "
"Livret de l'Alternant en tant que secrétaire du groupe #GROUPE. Vous pouvez dès "
@@ -26,10 +26,10 @@ _NEW_SEC_OF_GROUP = ("Votre compte OLA a été créé !", "Bonjour,
Votre "#URL
Bonne journée !
") _SEC_OF_GROUP = ( -"Vous avez été ajouté à un groupe OLA !", "Bonjour,Votre compte vient d'être ajouté dans l'Outil du "
- "Livret de l'Alternant en tant que secrétaire du groupe #GROUPE. Vous pouvez dès "
- "maintenant y accéder en vous rendant à l'adresse :
"
- "#URL
Bonne journée !
") + "Vous avez été ajouté à un groupe OLA !", "Bonjour,Votre compte vient d'être ajouté dans l'Outil du "
+ "Livret de l'Alternant en tant que secrétaire du groupe #GROUPE. Vous pouvez dès "
+ "maintenant y accéder en vous rendant à l'adresse :
"
+ "#URL
Bonne journée !
") def getMailContent(mail_type, args): diff --git a/backend/app/model.py b/backend/app/model.py index 8f405e4..0c87f5f 100644 --- a/backend/app/model.py +++ b/backend/app/model.py @@ -24,7 +24,7 @@ def getParam(key): return rows.first().value -def getUser(uid=0, email=""): +def getUser(uid=0, email="", hashcode=""): res = None if uid == 0 and email == "": @@ -40,6 +40,11 @@ def getUser(uid=0, email=""): rows = query.execute() res = rows.first() + elif hashcode != "": + query = USER.select(USER.c.hash == hashcode) + rows = query.execute() + res = rows.first() + if res is not None: return {"id": res.id, "email": res.email, "role": res.role, "phone": res.phone, "name": res.name} else: diff --git a/backend/app/urls.py b/backend/app/urls.py index d46618a..a841988 100644 --- a/backend/app/urls.py +++ b/backend/app/urls.py @@ -9,5 +9,6 @@ from app.core import api api.add_resource(SomeApi, '/api/someapi', '/api/someapi/