TG-124 : Correction du sytème de login + register
This commit is contained in:
		@@ -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');
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								backend/app/OLA_DATA.mysql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								backend/app/OLA_DATA.mysql
									
									
									
									
									
										Normal file
									
								
							@@ -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);
 | 
			
		||||
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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,13 +18,26 @@ 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']:
 | 
			
		||||
        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:
 | 
			
		||||
            if user is not None and password == user.psw:
 | 
			
		||||
                session['user'] = user
 | 
			
		||||
                return {'AUTH_RESULT': 'OK'}, 200
 | 
			
		||||
            else:
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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:
 | 
			
		||||
 
 | 
			
		||||
@@ -9,5 +9,6 @@ from app.core import api
 | 
			
		||||
api.add_resource(SomeApi, '/api/someapi', '/api/someapi/<int:id>')
 | 
			
		||||
api.add_resource(LoginAPI, '/api/login')
 | 
			
		||||
api.add_resource(UserInfoAPI, '/api/userInfo')
 | 
			
		||||
api.add_resource(UserAPI, '/api/user', '/api/user/byuid/<int:uid>', '/api/user/byemail/<string:email>')
 | 
			
		||||
api.add_resource(UserAPI, '/api/user', '/api/user/byuid/<int:uid>', '/api/user/byemail/<string:email>',
 | 
			
		||||
                 '/api/user/byhash/<string:hashcode>')
 | 
			
		||||
api.add_resource(GroupAPI, '/api/group', '/api/group/bygid/<int:gid>', '/api/group/byname/<string:name>')
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user