Merge remote-tracking branch 'origin/master'
# Conflicts: # frontend/src/app/login/page-login/page-login.component.ts # frontend/src/environments/environment.ts
This commit is contained in:
commit
b42aa64c57
35 changed files with 913 additions and 371 deletions
BIN
backend/__pycache__/app.cpython-310.pyc
Normal file
BIN
backend/__pycache__/app.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/__pycache__/config.cpython-310.pyc
Normal file
BIN
backend/__pycache__/config.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
backend/__pycache__/fictive_users.cpython-38.pyc
Normal file
BIN
backend/__pycache__/fictive_users.cpython-38.pyc
Normal file
Binary file not shown.
|
|
@ -26,10 +26,10 @@ def create_app(flask_env='development'):
|
|||
print('init_app')
|
||||
db.init_app(app)
|
||||
with app.app_context():
|
||||
print('import routes')
|
||||
#print('import routes')
|
||||
from . import routes
|
||||
app.register_blueprint(routes.bp)
|
||||
print('db.create_all')
|
||||
#print('db.create_all')
|
||||
db.create_all()
|
||||
print('db created')
|
||||
#print('db created')
|
||||
return app
|
||||
|
|
|
|||
BIN
backend/application/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
backend/application/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
backend/application/__pycache__/api_functions.cpython-310.pyc
Normal file
BIN
backend/application/__pycache__/api_functions.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
backend/application/__pycache__/logs_model.cpython-310.pyc
Normal file
BIN
backend/application/__pycache__/logs_model.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
backend/application/__pycache__/responses.cpython-310.pyc
Normal file
BIN
backend/application/__pycache__/responses.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/application/__pycache__/routes.cpython-310.pyc
Normal file
BIN
backend/application/__pycache__/routes.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
backend/application/__pycache__/sessionJWT.cpython-310.pyc
Normal file
BIN
backend/application/__pycache__/sessionJWT.cpython-310.pyc
Normal file
Binary file not shown.
BIN
backend/application/__pycache__/users_model.cpython-310.pyc
Normal file
BIN
backend/application/__pycache__/users_model.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
|
|
@ -50,9 +50,3 @@ def uwp_to_user(uwp):
|
|||
salt = salt0,
|
||||
is_admin = uwp["is_admin"]
|
||||
)
|
||||
|
||||
|
||||
|
||||
TAB_USER = []
|
||||
for uwp in TAB_USER_WITH_PASSWORD:
|
||||
TAB_USER.append(uwp_to_user(uwp))
|
||||
835
backend/test.py
835
backend/test.py
|
|
@ -2,58 +2,92 @@ import unittest
|
|||
from flask_testing import TestCase
|
||||
import json
|
||||
|
||||
from fictive_users import TAB_USER
|
||||
from fictive_users import TAB_USER_WITH_PASSWORD, uwp_to_user
|
||||
|
||||
from application import db, create_app
|
||||
from application.users_model import Users
|
||||
from application.logs_model import Logs
|
||||
|
||||
|
||||
|
||||
|
||||
class BaseTestCase(TestCase):
|
||||
|
||||
def create_app(self):
|
||||
app = create_app('testing')
|
||||
return app
|
||||
|
||||
|
||||
def setUp(self):
|
||||
db.create_all()
|
||||
for user in TAB_USER:
|
||||
db.session.add(user)
|
||||
for uwp in TAB_USER_WITH_PASSWORD:
|
||||
db.session.add(uwp_to_user(uwp))
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
db.session.remove()
|
||||
db.drop_all()
|
||||
|
||||
|
||||
|
||||
|
||||
class FlaskTestCase(BaseTestCase):
|
||||
|
||||
# -- UTILS ---
|
||||
|
||||
# def login(self, email, password):
|
||||
# data0 = json.dumps({
|
||||
# "email": email,
|
||||
# "password": password
|
||||
# })
|
||||
# response = self.client.post('/api/login', data=data0)
|
||||
def login(self, email, password):
|
||||
data0 = {
|
||||
"email": email,
|
||||
"password": password
|
||||
}
|
||||
response = self.client.post('/api/login', json=data0)
|
||||
return response
|
||||
|
||||
|
||||
|
||||
# --- LOGIN ---
|
||||
|
||||
# def test_login_no_fields(self):
|
||||
# data0 = {}
|
||||
# response = self.client.post('/api/login', json={})
|
||||
# print(response.json)
|
||||
# self.assertEqual(response.json['message'], 'Need email, password fields.')
|
||||
def test_login_NoFields_statusCode(self):
|
||||
data0 = {}
|
||||
response = self.client.post('/api/login', json={})
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
# def test_login_empty_fields(self):
|
||||
# data0 = {
|
||||
# "email": "",
|
||||
# "password": "blabla"
|
||||
# }
|
||||
# response = self.client.post('/api/login', json=data0)
|
||||
# self.assertEqual(response.json['message'], 'Empty email and/or password fields.')
|
||||
|
||||
def test_login_wrong_fields(self):
|
||||
def test_login_NoFields_message(self):
|
||||
data0 = {}
|
||||
response = self.client.post('/api/login', json={})
|
||||
self.assertEqual(response.json['message'], 'Need email, password fields.')
|
||||
|
||||
|
||||
def test_login_emptyFields_statusCode(self):
|
||||
data0 = {
|
||||
"email": "",
|
||||
"password": "blabla"
|
||||
}
|
||||
response = self.client.post('/api/login', json=data0)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
|
||||
def test_login_emptyFields_message(self):
|
||||
data0 = {
|
||||
"email": "",
|
||||
"password": "blabla"
|
||||
}
|
||||
response = self.client.post('/api/login', json=data0)
|
||||
self.assertEqual(response.json['message'], 'Empty email and/or password fields.')
|
||||
|
||||
|
||||
def test_login_wrongFields_statusCode(self):
|
||||
data0 = {
|
||||
"email": "nimp@gmail.com",
|
||||
"password": "nimp"
|
||||
}
|
||||
response = self.client.post('/api/login', json=data0)
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
|
||||
def test_login_wrongFields_message(self):
|
||||
data0 = {
|
||||
"email": "nimp@gmail.com",
|
||||
"password": "nimp"
|
||||
|
|
@ -61,7 +95,17 @@ class FlaskTestCase(BaseTestCase):
|
|||
response = self.client.post('/api/login', json=data0)
|
||||
self.assertEqual(response.json['message'], 'Email or password invalid')
|
||||
|
||||
def test_login_success(self):
|
||||
|
||||
def test_login_success_statusCode(self):
|
||||
data0 = {
|
||||
"email": "riri@gmail.com",
|
||||
"password": "ririPass"
|
||||
}
|
||||
response = self.client.post('/api/login', json=data0)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
def test_login_success_message(self):
|
||||
data0 = {
|
||||
"email": "riri@gmail.com",
|
||||
"password": "ririPass"
|
||||
|
|
@ -69,237 +113,598 @@ class FlaskTestCase(BaseTestCase):
|
|||
response = self.client.post('/api/login', json=data0)
|
||||
self.assertEqual(response.json['message'], 'User authenticated.')
|
||||
|
||||
# # --- REGISTER ---
|
||||
|
||||
# def test_register_no_fields(self):
|
||||
# data0 = json.dumps({})
|
||||
# response = self.client.post('/api/register', data=data0)
|
||||
# self.assertIn('Need', response.message)
|
||||
|
||||
# def test_register_empty_fields(self):
|
||||
# data0 = json.dumps({
|
||||
# "email": "",
|
||||
# "password": "blabla",
|
||||
# "nickname": "blabla"
|
||||
# })
|
||||
# response = self.client.post('/api/register', data=data0)
|
||||
# self.assertEqual(response.message, 'Empty email and/or password and/or nickname fields.')
|
||||
# --- REGISTER ---
|
||||
|
||||
# def test_register_already_exist(self):
|
||||
# data0 = json.dumps({
|
||||
# "email": "riri@gmail.com",
|
||||
# "password": "blabla",
|
||||
# "nickname": "blabla"
|
||||
# })
|
||||
# response = self.client.post('/api/register', data=data0)
|
||||
# self.assertIn('already exist', response.message)
|
||||
def test_register_noFields_statusCode(self):
|
||||
response = self.client.post('/api/register', json={})
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
# def test_register_success(self):
|
||||
# data0 = json.dumps({
|
||||
# "email": "loulou@gmail.com",
|
||||
# "password": "loulouPass",
|
||||
# "nickname": "Loulou"
|
||||
# })
|
||||
# response = self.client.post('/api/register', data=data0)
|
||||
# self.assertEqual(response.message, 'User registered.')
|
||||
|
||||
# # --- LOGOUT ---
|
||||
def test_register_noFields_message(self):
|
||||
response = self.client.post('/api/register', json={})
|
||||
self.assertIn('Need', response.json['message'])
|
||||
|
||||
# def test_logout_fail(self):
|
||||
# response = self.client.delete('/api/logout')
|
||||
# self.assertEqual(response.status_code, 500)
|
||||
|
||||
# def test_logout_success(self):
|
||||
# self.login_user()
|
||||
# response = self.client.delete('/api/logout')
|
||||
# self.assertEqual(response.status_code, 200)
|
||||
def test_register_emptyFields_statusCode(self):
|
||||
data0 = {
|
||||
"email": "",
|
||||
"password": "blabla",
|
||||
"nickname": "blabla"
|
||||
}
|
||||
response = self.client.post('/api/register', json=data0)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
# # --- SELF UPDATE ---
|
||||
|
||||
# def test_self_update_not_connected(self):
|
||||
# data0 = json.dumps({})
|
||||
# response = self.client.put('/api/user/update', data=data0)
|
||||
# self.assertEqual(response.status_code, 500)
|
||||
def test_register_emptyFields_message(self):
|
||||
data0 = {
|
||||
"email": "",
|
||||
"password": "blabla",
|
||||
"nickname": "blabla"
|
||||
}
|
||||
response = self.client.post('/api/register', json=data0)
|
||||
self.assertEqual(response.json['message'], 'Empty email and/or password and/or nickname fields.')
|
||||
|
||||
# def test_self_update_no_fields(self):
|
||||
# self.login('riri@gmail.com', 'ririPass')
|
||||
# data0 = json.dumps({})
|
||||
# response = self.client.put('/api/user/update', data=data0)
|
||||
# self.assertIn('Need', response.message)
|
||||
|
||||
# def test_self_update_empty_fields(self):
|
||||
# self.login('riri@gmail.com', 'ririPass')
|
||||
# data0 = json.dumps({
|
||||
# "nickname": "",
|
||||
# "password": "blabla"
|
||||
# })
|
||||
# response = self.client.put('/api/user/update', data=data0)
|
||||
# self.assertEqual(response.message, 'Empty nickname and/or password fields.')
|
||||
def test_register_alreadyExist_statusCode(self):
|
||||
data0 = {
|
||||
"email": "riri@gmail.com",
|
||||
"password": "blabla",
|
||||
"nickname": "blabla"
|
||||
}
|
||||
response = self.client.post('/api/register', json=data0)
|
||||
self.assertEqual(response.status_code, 500)
|
||||
|
||||
# def test_self_update_success(self):
|
||||
# self.login('riri@gmail.com', 'ririPass')
|
||||
# data0 = json.dumps({
|
||||
# "nickname": "Ririri",
|
||||
# "password": "ririPass"
|
||||
# })
|
||||
# response = self.client.put('/api/user/update', data=data0)
|
||||
# self.assertEqual(response.status_code, 200)
|
||||
|
||||
# # --- SELF DELETE ---
|
||||
def test_register_alreadyExist_statusCode(self):
|
||||
data0 = {
|
||||
"email": "riri@gmail.com",
|
||||
"password": "blabla",
|
||||
"nickname": "blabla"
|
||||
}
|
||||
response = self.client.post('/api/register', json=data0)
|
||||
self.assertIn('already exist', response.json['message'])
|
||||
|
||||
# def test_self_delete_not_connected(self):
|
||||
# response = self.client.delete('/api/user/delete')
|
||||
# self.assertEqual(response.status_code, 500)
|
||||
|
||||
# def test_self_delete_success(self):
|
||||
# self.login('donald@gmail.com', 'donaldPass')
|
||||
# response = self.client.delete('/api/user/delete')
|
||||
# self.assertEqual(response.status_code, 200)
|
||||
def test_register_success_statusCode(self):
|
||||
data0 = {
|
||||
"email": "loulou@gmail.com",
|
||||
"password": "loulouPass",
|
||||
"nickname": "Loulou"
|
||||
}
|
||||
response = self.client.post('/api/register', json=data0)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# def test_self_delete_last_admin(self):
|
||||
# self.login('daisy@gmail.com', 'daisyPass')
|
||||
# response = self.client.delete('/api/user/delete')
|
||||
# self.assertEqual(response.message, 'Can\'t delete last admin')
|
||||
|
||||
# # --- admin: CREATE USER ---
|
||||
def test_register_success_message(self):
|
||||
data0 = {
|
||||
"email": "loulou@gmail.com",
|
||||
"password": "loulouPass",
|
||||
"nickname": "Loulou"
|
||||
}
|
||||
response = self.client.post('/api/register', json=data0)
|
||||
self.assertEqual(response.json['message'], 'User registered.')
|
||||
|
||||
# def test_admin_create_not_connected(self):
|
||||
# data0 = json.dumps({})
|
||||
# response = self.client.post('/api/admin/create/user', data=data0)
|
||||
# self.assertEqual(response.message, 'User not authenticated.')
|
||||
|
||||
# def test_admin_create_no_permission(self):
|
||||
# self.login('riri@gmail.com', 'ririPass')
|
||||
# data0 = json.dumps({})
|
||||
# response = self.client.post('/api/admin/create/user', data=data0)
|
||||
# self.assertEqual(response.message, 'User does not have permission.')
|
||||
|
||||
# def test_admin_create_no_fields(self):
|
||||
# self.login('daisy@gmail.com', 'daisyPass')
|
||||
# data0 = json.dumps({})
|
||||
# response = self.client.post('/api/admin/create/user', data=data0)
|
||||
# self.assertIn('Need', response.message)
|
||||
# --- LOGOUT ---
|
||||
|
||||
# def test_admin_create_empty_fields(self):
|
||||
# self.login('daisy@gmail.com', 'daisyPass')
|
||||
# data0 = json.dumps({
|
||||
# "email": "",
|
||||
# "nickname": "Mickey",
|
||||
# "password": "mickeyPass",
|
||||
# "is_admin": true,
|
||||
# })
|
||||
# response = self.client.post('/api/admin/create/user', data=data0)
|
||||
# self.assertEqual(response.message, 'Empty email and/or nickname and/or password and/or is_admin fields.')
|
||||
def test_logout_fail_(self):
|
||||
response = self.client.delete('/api/logout')
|
||||
self.assertEqual(response.status_code, 500)
|
||||
|
||||
# def test_admin_create_already_exist(self):
|
||||
# self.login('daisy@gmail.com', 'daisyPass')
|
||||
# data0 = json.dumps({
|
||||
# "email": "riri@gmail.com",
|
||||
# "passord": "blabla",
|
||||
# "nickname": "blabla",
|
||||
# })
|
||||
# response = self.client.post('/api/admin/create/user', data=data0)
|
||||
# self.assertIn('already exist', response.message)
|
||||
|
||||
# def test_admin_create_success(self):
|
||||
# self.login('daisy@gmail.com', 'daisyPass')
|
||||
# data0 = json.dumps({
|
||||
# "email": "mickey@gmail.com",
|
||||
# "nickname": "Mickey",
|
||||
# "password": "mickeyPass",
|
||||
# "is_admin": true,
|
||||
# })
|
||||
# response = self.client.post('/api/admin/create/user', data=data0)
|
||||
# self.assertEqual(response.message, 'User registered.')
|
||||
def test_logout_success(self):
|
||||
response = self.login("riri@gmail.com", "ririPass")
|
||||
if response.status_code == 200:
|
||||
response = self.client.delete('/api/logout')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
# # --- admin: UPDATE USER ---
|
||||
|
||||
# def test_admin_update_not_connected(self):
|
||||
# data0 = json.dumps({})
|
||||
# response = self.client.put('/api/admin/update/user', data=data0)
|
||||
# self.assertEqual(response.message, 'User not authenticated.')
|
||||
|
||||
# def test_admin_update_no_permission(self):
|
||||
# self.login('riri@gmail.com', 'ririPass')
|
||||
# data0 = json.dumps({})
|
||||
# response = self.client.put('/api/admin/update/user', data=data0)
|
||||
# self.assertEqual(response.message, 'User does not have permission.')
|
||||
# --- SELF UPDATE ---
|
||||
|
||||
# def test_admin_update_no_fields(self):
|
||||
# self.login('daisy@gmail.com', 'daisyPass')
|
||||
# data0 = json.dumps({})
|
||||
# response = self.client.put('/api/admin/update/user', data=data0)
|
||||
# self.assertIn('Need', response.message)
|
||||
def test_selfUpdate_notConnected_statusCode(self):
|
||||
response = self.client.put('/api/user/update', json={})
|
||||
self.assertEqual(response.status_code, 500)
|
||||
|
||||
# def test_admin_update_empty_fields(self):
|
||||
# self.login('daisy@gmail.com', 'daisyPass')
|
||||
# data0 = json.dumps({
|
||||
# "id": 1,
|
||||
# "password": "",
|
||||
# "is_admin": false,
|
||||
# })
|
||||
# response = self.client.put('/api/admin/update/user', data=data0)
|
||||
# self.assertEqual(response.message, 'Empty is_admin and/or password fields.')
|
||||
|
||||
# def test_admin_update_not_exists(self):
|
||||
# self.login('daisy@gmail.com', 'daisyPass')
|
||||
# data0 = json.dumps({
|
||||
# "id": 99,
|
||||
# "password": "",
|
||||
# "is_admin": false,
|
||||
# })
|
||||
# response = self.client.put('/api/admin/update/user', data=data0)
|
||||
# self.assertEqual(response.message, 'User do not exist.')
|
||||
def test_selfUpdate_notConnected_message(self):
|
||||
response = self.client.put('/api/user/update', json={})
|
||||
self.assertEqual(response.json['message'], 'User not authenticated.')
|
||||
|
||||
# def test_admin_update_success(self):
|
||||
# self.login('daisy@gmail.com', 'daisyPass')
|
||||
# data0 = json.dumps({
|
||||
# "id": 1,
|
||||
# "password": "roroPass",
|
||||
# "is_admin": false,
|
||||
# })
|
||||
# response = self.client.put('/api/admin/update/user', data=data0)
|
||||
# self.assertEqual(response.status_code, 200)
|
||||
|
||||
# # --- admin: DELETE USER ---
|
||||
def test_selfUpdate_noFields_statusCode(self):
|
||||
response = self.login("riri@gmail.com", "ririPass")
|
||||
if response.status_code == 200:
|
||||
response = self.client.put('/api/user/update', json={})
|
||||
self.assertEqual(response.status_code, 400)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
# def test_admin_delete_not_connected(self):
|
||||
# response = self.client.delete('/api/admin/delete/user')
|
||||
# self.assertEqual(response.message, 'User not authenticated.')
|
||||
|
||||
# def test_admin_delete_no_permission(self):
|
||||
# self.login('riri@gmail.com', 'ririPass')
|
||||
# response = self.client.delete('/api/admin/delete/user')
|
||||
# self.assertEqual(response.message, 'User does not have permission.')
|
||||
def test_selfUpdate_noFields_message(self):
|
||||
response = self.login("riri@gmail.com", "ririPass")
|
||||
if response.status_code == 200:
|
||||
response = self.client.put('/api/user/update', json={})
|
||||
self.assertIn('Need', response.json['message'])
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
# def test_admin_delete_no_fields(self):
|
||||
# self.login('daisy@gmail.com', 'daisyPass')
|
||||
# data0 = json.dumps({})
|
||||
# response = self.client.delete('/api/admin/delete/user')
|
||||
# self.assertIn('Need', response.message)
|
||||
|
||||
# def test_admin_delete_not_exists(self):
|
||||
# self.login('daisy@gmail.com', 'daisyPass')
|
||||
# data0 = json.dumps({"id": 99})
|
||||
# response = self.client.delete('/api/admin/delete/user')
|
||||
# self.assertEqual(response.message, 'User do not exist.')
|
||||
def test_selfUpdate_emptyFields_statusCode(self):
|
||||
response = self.login("riri@gmail.com", "ririPass")
|
||||
if response.status_code == 200:
|
||||
data0 = {
|
||||
"nickname": "",
|
||||
"password": "blabla"
|
||||
}
|
||||
response = self.client.put('/api/user/update', json=data0)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
# def test_admin_delete_success(self):
|
||||
# self.login('daisy@gmail.com', 'daisyPass')
|
||||
# data0 = json.dumps({"id": 2})
|
||||
# response = self.client.delete('/api/admin/delete/user', data=data0)
|
||||
# self.assertEqual(response.status_code, 200)
|
||||
|
||||
# # --- LIST OF USER ---
|
||||
def test_selfUpdate_emptyFields_message(self):
|
||||
response = self.login("riri@gmail.com", "ririPass")
|
||||
if response.status_code == 200:
|
||||
data0 = {
|
||||
"nickname": "",
|
||||
"password": "blabla"
|
||||
}
|
||||
response = self.client.put('/api/user/update', json=data0)
|
||||
self.assertEqual(response.json['message'], 'Empty nickname and/or password fields.')
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_self_update_success_statusCode(self):
|
||||
response = self.login("riri@gmail.com", "ririPass")
|
||||
if response.status_code == 200:
|
||||
data0 = {
|
||||
"nickname": "Ririri",
|
||||
"password": "ririPass"
|
||||
}
|
||||
response = self.client.put('/api/user/update', json=data0)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
|
||||
# --- SELF DELETE ---
|
||||
|
||||
def test_selfDelete_notConnected_statusCode(self):
|
||||
response = self.client.delete('/api/user/delete')
|
||||
self.assertEqual(response.status_code, 500)
|
||||
|
||||
|
||||
def test_selfDelete_notConnected_message(self):
|
||||
response = self.client.delete('/api/user/delete')
|
||||
self.assertEqual(response.json['message'], 'User not authenticated.')
|
||||
|
||||
|
||||
def test_selfDelete_success_statusCode(self):
|
||||
response = self.login('riri@gmail.com', 'ririPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.delete('/api/user/delete')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_selfDelete_success_message(self):
|
||||
response = self.login('riri@gmail.com', 'ririPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.delete('/api/user/delete')
|
||||
self.assertEqual(response.json['message'], 'User deleted.')
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_selfDelete_last_admin_statusCode(self):
|
||||
response = response = self.login('riri@gmail.com', 'ririPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.delete('/api/user/delete')
|
||||
if response.status_code == 200:
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.delete('/api/user/delete')
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_selfDelete_last_admin_message(self):
|
||||
response = self.login('donald@gmail.com', 'donaldPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.delete('/api/user/delete')
|
||||
if response.status_code == 200:
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.delete('/api/user/delete')
|
||||
self.assertEqual(response.json['message'], 'Can\'t delete last admin')
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
|
||||
# --- admin: CREATE USER ---
|
||||
|
||||
def test_adminCreate_notConnected_statusCode(self):
|
||||
response = self.client.post('/api/admin/create/user', json={})
|
||||
self.assertEqual(response.status_code, 500)
|
||||
|
||||
|
||||
def test_adminCreate_notConnected_message(self):
|
||||
response = self.client.post('/api/admin/create/user', json={})
|
||||
self.assertEqual(response.json['message'], 'User not authenticated.')
|
||||
|
||||
|
||||
def test_adminCreate_noPermission_statusCode(self):
|
||||
response = self.login('riri@gmail.com', 'ririPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.post('/api/admin/create/user', json={})
|
||||
self.assertEqual(response.status_code, 500)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminCreate_noPermission_message(self):
|
||||
response = self.login('riri@gmail.com', 'ririPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.post('/api/admin/create/user', json={})
|
||||
self.assertEqual(response.json['message'], 'User does not have permission.')
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminCreate_noFields_statusCode(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.post('/api/admin/create/user', json={})
|
||||
self.assertEqual(response.status_code, 400)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminCreate_noFields_message(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.post('/api/admin/create/user', json={})
|
||||
self.assertIn('Need', response.json['message'])
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminCreate_emptyFields_statusCode(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
data0 = {
|
||||
"email": "",
|
||||
"nickname": "Mickey",
|
||||
"password": "mickeyPass",
|
||||
"is_admin": True,
|
||||
}
|
||||
response = self.client.post('/api/admin/create/user', json=data0)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminCreate_emptyFields_message(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
data0 = {
|
||||
"email": "",
|
||||
"nickname": "Mickey",
|
||||
"password": "mickeyPass",
|
||||
"is_admin": True,
|
||||
}
|
||||
response = self.client.post('/api/admin/create/user', json=data0)
|
||||
self.assertEqual(response.json['message'], 'Empty email and/or nickname and/or password and/or is_admin fields.')
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminCreate_alreadyExist_statusCode(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
data0 = {
|
||||
"email": "riri@gmail.com",
|
||||
"passord": "blabla",
|
||||
"nickname": "blabla",
|
||||
}
|
||||
response = self.client.post('/api/admin/create/user', json=data0)
|
||||
self.assertEqual(response.status_code, 500)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminCreate_alreadyExist_message(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
data0 = {
|
||||
"email": "riri@gmail.com",
|
||||
"passord": "blabla",
|
||||
"nickname": "blabla",
|
||||
}
|
||||
response = self.client.post('/api/admin/create/user', json=data0)
|
||||
self.assertIn('already exist', response.json['message'])
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminCreate_success_statusCode(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
data0 = {
|
||||
"email": "mickey@gmail.com",
|
||||
"nickname": "Mickey",
|
||||
"password": "mickeyPass",
|
||||
"is_admin": True,
|
||||
}
|
||||
response = self.client.post('/api/admin/create/user', json=data0)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminCreate_success_message(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
data0 = {
|
||||
"email": "mickey@gmail.com",
|
||||
"nickname": "Mickey",
|
||||
"password": "mickeyPass",
|
||||
"is_admin": True,
|
||||
}
|
||||
response = self.client.post('/api/admin/create/user', json=data0)
|
||||
self.assertEqual(response.json['message'], 'User registered.')
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
|
||||
# --- admin: UPDATE USER ---
|
||||
|
||||
def test_adminUpdate_notConnected_statusCode(self):
|
||||
response = self.client.put('/api/admin/update/user', json={})
|
||||
self.assertEqual(response.status_code, 500)
|
||||
|
||||
|
||||
def test_adminUpdate_notConnected_message(self):
|
||||
response = self.client.put('/api/admin/update/user', json={})
|
||||
self.assertEqual(response.json['message'], 'User not authenticated.')
|
||||
|
||||
|
||||
def test_adminUpdate_noPermission_statusCode(self):
|
||||
response = self.login('riri@gmail.com', 'ririPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.put('/api/admin/update/user', json={})
|
||||
self.assertEqual(response.status_code, 500)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminUpdate_noPermission_message(self):
|
||||
response = self.login('riri@gmail.com', 'ririPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.put('/api/admin/update/user', json={})
|
||||
self.assertEqual(response.json['message'], 'User does not have permission.')
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminUpdate_noFields_statusCode(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.put('/api/admin/update/user', json={})
|
||||
self.assertEqual(response.status_code, 400)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminUpdate_noFields_message(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.put('/api/admin/update/user', json={})
|
||||
self.assertIn('Need', response.json['message'])
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminUpdate_emptyFields_statusCode(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
data0 = {
|
||||
"id": 1,
|
||||
"password": "",
|
||||
"is_admin": False,
|
||||
}
|
||||
response = self.client.put('/api/admin/update/user', json=data0)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminUpdate_emptyFields_message(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
data0 = {
|
||||
"id": 1,
|
||||
"password": "",
|
||||
"is_admin": False,
|
||||
}
|
||||
response = self.client.put('/api/admin/update/user', json=data0)
|
||||
self.assertEqual(response.json['message'], 'Empty is_admin and/or password fields.')
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminUpdate_notExists_statusCode(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
data0 = {
|
||||
"id": 99,
|
||||
"password": "blabla",
|
||||
"is_admin": False
|
||||
}
|
||||
response = self.client.put('/api/admin/update/user', json=data0)
|
||||
self.assertEqual(response.status_code, 500)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminUpdate_notExists_message(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
data0 = {
|
||||
"id": 99,
|
||||
"password": "blabla",
|
||||
"is_admin": False
|
||||
}
|
||||
response = self.client.put('/api/admin/update/user', json=data0)
|
||||
self.assertEqual(response.json['message'], 'User do not exist.')
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminUpdate_success_message(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
data0 = {
|
||||
"id": 1,
|
||||
"password": "roroPass",
|
||||
"is_admin": False,
|
||||
}
|
||||
response = self.client.put('/api/admin/update/user', json=data0)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminUpdate_success_statusCode(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
data0 = {
|
||||
"id": 1,
|
||||
"password": "roroPass",
|
||||
"is_admin": False,
|
||||
}
|
||||
response = self.client.put('/api/admin/update/user', json=data0)
|
||||
self.assertIn("updated", response.json['message'])
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
|
||||
# --- admin: DELETE USER ---
|
||||
|
||||
def test_adminDelete_notConnected_statusCode(self):
|
||||
response = self.client.delete('/api/admin/delete/user')
|
||||
self.assertEqual(response.status_code, 500)
|
||||
|
||||
|
||||
def test_adminDelete_notConnected_message(self):
|
||||
response = self.client.delete('/api/admin/delete/user')
|
||||
self.assertEqual(response.json['message'], 'User not authenticated.')
|
||||
|
||||
|
||||
def test_adminDelete_noPermission_statusCode(self):
|
||||
response = self.login('riri@gmail.com', 'ririPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.delete('/api/admin/delete/user')
|
||||
self.assertEqual(response.status_code, 500)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminDelete_noPermission_message(self):
|
||||
response = self.login('riri@gmail.com', 'ririPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.delete('/api/admin/delete/user')
|
||||
self.assertEqual(response.json['message'], 'User does not have permission.')
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminDelete_noFields_statusCode(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.delete('/api/admin/delete/user', json={})
|
||||
self.assertEqual(response.status_code, 400)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminDelete_no_fields(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.delete('/api/admin/delete/user', json={})
|
||||
self.assertIn('Need', response.json['message'])
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminDelete_notExists_statusCode(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
data0 = {"id": 99}
|
||||
response = self.client.delete('/api/admin/delete/user', json=data0)
|
||||
self.assertEqual(response.status_code, 500)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminDelete_notExists_message(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
data0 = {"id": 99}
|
||||
response = self.client.delete('/api/admin/delete/user', json=data0)
|
||||
self.assertEqual(response.json['message'], 'User do not exist.')
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminDelete_success_statusCode(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
data0 = {"id": 2}
|
||||
response = self.client.delete('/api/admin/delete/user', json=data0)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
def test_adminDelete_success_message(self):
|
||||
response = self.login('daisy@gmail.com', 'daisyPass')
|
||||
if response.status_code == 200:
|
||||
data0 = {"id": 2}
|
||||
response = self.client.delete('/api/admin/delete/user', json=data0)
|
||||
self.assertEqual(response.json['message'], 'User deleted.')
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
|
||||
# --- LIST OF USER ---
|
||||
|
||||
def test_listOfUsers_fail(self):
|
||||
response = self.client.get('/api/users')
|
||||
self.assertEqual(response.status_code, 500)
|
||||
|
||||
|
||||
def test_listOfUsers_success(self):
|
||||
response = self.login('riri@gmail.com', 'ririPass')
|
||||
if response.status_code == 200:
|
||||
response = self.client.get('/api/users?order_by=nickname')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
else:
|
||||
self.assertEqual(True, False)
|
||||
|
||||
# def test_list_of_users_fail(self):
|
||||
# response = self.client.get('/api/users')
|
||||
# self.assertEqual(response.status_code, 500)
|
||||
|
||||
# def test_list_of_users_success(self):
|
||||
# self.login('riri@gmail.com', 'ririPass')
|
||||
# response = self.client.get('/api/users')
|
||||
# self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
|
||||
<div class="btnContainer">
|
||||
<button mat-button class="btnAjouter" (click)="onAdd()">
|
||||
<button mat-button class="btnAjouter" (click)="onCreate()">
|
||||
<mat-icon>add_circle</mat-icon> Ajouter un utilisateur
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import {AfterViewInit, Component, ViewChild} from '@angular/core';
|
||||
import {MatTableDataSource} from "@angular/material/table";
|
||||
import {FictitiousDatasService} from "../../../common/services/fictitiousDatas/fictitious-datas.service";
|
||||
import {MatSort} from "@angular/material/sort";
|
||||
import {MatPaginator} from "@angular/material/paginator";
|
||||
import {MatDialog} from "@angular/material/dialog";
|
||||
|
|
@ -8,6 +7,7 @@ import {PopupCreatePersonComponent} from "../popup-create-person/popup-create-pe
|
|||
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||
import {PopupUpdatePersonAdminComponent} from "../popup-update-person-admin/popup-update-person-admin.component";
|
||||
import {PopupDeleteProfilComponent} from "../../../common/components/popup-delete-profil/popup-delete-profil.component";
|
||||
import {MessageService} from "../../../common/services/message/message.service";
|
||||
|
||||
|
||||
|
||||
|
|
@ -25,17 +25,26 @@ export class PageUserListComponent implements AfterViewInit
|
|||
configSnackBar = { duration: 2000, panelClass: "custom-class" };
|
||||
|
||||
|
||||
constructor( private fictitiousDatasService: FictitiousDatasService,
|
||||
constructor( private messageService: MessageService,
|
||||
public dialog: MatDialog,
|
||||
private snackBar: MatSnackBar) { }
|
||||
|
||||
|
||||
ngAfterViewInit(): void
|
||||
{
|
||||
// Faux code
|
||||
let tabPerson = this.fictitiousDatasService.getTabPerson(5);
|
||||
this.messageService
|
||||
.get('users?order_by=nickname')
|
||||
.subscribe(retour => this.ngAfterViewInitCallback(retour), err => this.ngAfterViewInitCallback(err));
|
||||
}
|
||||
|
||||
// Vrai code ...
|
||||
|
||||
ngAfterViewInitCallback(retour: any): void
|
||||
{
|
||||
if(retour.status !== "success") {
|
||||
console.log(retour);
|
||||
}
|
||||
else {
|
||||
let tabPerson: { id: number, email: string, nickname: string, is_admin: boolean }[] = retour.data;
|
||||
tabPerson = tabPerson.map( person => {
|
||||
if(!person.is_admin) return Object.assign(person, {role: "utilisateur"});
|
||||
else return Object.assign(person, {role: "admin"});
|
||||
|
|
@ -44,6 +53,7 @@ export class PageUserListComponent implements AfterViewInit
|
|||
this.dataSource.sort = this.sort;
|
||||
this.dataSource.paginator = this.paginator;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
applyFilter(event: Event)
|
||||
|
|
@ -53,20 +63,21 @@ export class PageUserListComponent implements AfterViewInit
|
|||
}
|
||||
|
||||
|
||||
// Appuie sur le bouton "add"
|
||||
onAdd(): void
|
||||
// Appuie sur le bouton "create"
|
||||
onCreate(): void
|
||||
{
|
||||
const config = { width: '50%' };
|
||||
this.dialog
|
||||
.open(PopupCreatePersonComponent, config)
|
||||
.afterClosed()
|
||||
.subscribe( person => {
|
||||
.subscribe( retour => {
|
||||
|
||||
if((person === null) || (person === undefined)) {
|
||||
if((retour === null) || (retour === undefined))
|
||||
{
|
||||
this.snackBar.open( "Opération annulée", "", this.configSnackBar);
|
||||
}
|
||||
else {
|
||||
this.dataSource.data.push(person);
|
||||
this.dataSource.data.push(retour.data);
|
||||
this.dataSource.data = this.dataSource.data;
|
||||
this.dataSource = this.dataSource;
|
||||
this.snackBar.open( "L'utilisateur a bien été créé ✔", "", this.configSnackBar);
|
||||
|
|
@ -85,14 +96,15 @@ export class PageUserListComponent implements AfterViewInit
|
|||
this.dialog
|
||||
.open(PopupUpdatePersonAdminComponent, config)
|
||||
.afterClosed()
|
||||
.subscribe( personUpdated => {
|
||||
.subscribe( retour => {
|
||||
|
||||
if((personUpdated === null) || (personUpdated === undefined)) {
|
||||
if((retour === null) || (retour === undefined))
|
||||
{
|
||||
this.snackBar.open("Opération annulée", "", this.configSnackBar);
|
||||
}
|
||||
else {
|
||||
const index = this.dataSource.data.findIndex( elt => (elt.id === personToUpdate.id));
|
||||
this.dataSource.data.splice(index, 1, personUpdated);
|
||||
this.dataSource.data.splice(index, 1, retour.data);
|
||||
this.dataSource.data = this.dataSource.data;
|
||||
this.dataSource = this.dataSource;
|
||||
this.snackBar.open("L'utilisateur a bien été modifié ✔", "", this.configSnackBar);
|
||||
|
|
@ -115,11 +127,16 @@ export class PageUserListComponent implements AfterViewInit
|
|||
this.dialog
|
||||
.open(PopupDeleteProfilComponent, config)
|
||||
.afterClosed()
|
||||
.subscribe( personUpdated => {
|
||||
.subscribe( retour => {
|
||||
|
||||
if((personUpdated === null) || (personUpdated === undefined)) {
|
||||
if((retour === null) || (retour === undefined))
|
||||
{
|
||||
this.snackBar.open("Opération annulée", "", this.configSnackBar);
|
||||
}
|
||||
else if(retour.status === "error")
|
||||
{
|
||||
this.snackBar.open(retour.message, "", this.configSnackBar);
|
||||
}
|
||||
else {
|
||||
const index = this.dataSource.data.findIndex( elt => (elt.id === personToDelete.id));
|
||||
this.dataSource.data.splice(index, 1);
|
||||
|
|
@ -127,7 +144,6 @@ export class PageUserListComponent implements AfterViewInit
|
|||
this.dataSource = this.dataSource;
|
||||
this.snackBar.open("L'utilisateur a bien été supprimé ✔", "", this.configSnackBar);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,13 +52,19 @@ export class PopupCreatePersonComponent
|
|||
// Callback de 'onValider'
|
||||
onValiderCallback(retour: any)
|
||||
{
|
||||
if(retour.status === 'error')
|
||||
if(retour.status === 'success')
|
||||
{
|
||||
this.dialogRef.close(retour);
|
||||
}
|
||||
else if(retour.status === 'error')
|
||||
{
|
||||
console.log(retour);
|
||||
this.dialogRef.close(null);
|
||||
this.errorMessage = retour.message;
|
||||
this.hasError = true;
|
||||
}
|
||||
else {
|
||||
this.dialogRef.close(this.person);
|
||||
console.log(retour);
|
||||
this.dialogRef.close(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import { PageRegistryComponent } from './user/page-registry/page-registry.compon
|
|||
import { PopupDeleteProfilComponent } from './common/components/popup-delete-profil/popup-delete-profil.component';
|
||||
import {MatSortModule} from "@angular/material/sort";
|
||||
import { PopupUpdatePersonAdminComponent } from './admin/userList/popup-update-person-admin/popup-update-person-admin.component';
|
||||
import {HttpClientModule} from "@angular/common/http";
|
||||
|
||||
|
||||
|
||||
|
|
@ -51,6 +52,7 @@ import { PopupUpdatePersonAdminComponent } from './admin/userList/popup-update-p
|
|||
AppRoutingModule,
|
||||
FormsModule,
|
||||
BrowserAnimationsModule,
|
||||
HttpClientModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatButtonModule,
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@
|
|||
</div>
|
||||
|
||||
<!-- Deconnexion -->
|
||||
<button mat-button class="btnDeconnexion" (click)="onDeconnexion()" routerLink="/">
|
||||
<button mat-button class="btnDeconnexion" (click)="onDeconnexion()" routerLink="/login">
|
||||
Deconnexion
|
||||
</button>
|
||||
|
||||
|
|
@ -100,7 +100,7 @@
|
|||
</div>
|
||||
|
||||
<!-- Deconnexion -->
|
||||
<button mat-button class="btnDeconnexion" (click)="onDeconnexion()" routerLink="/">
|
||||
<button mat-button class="btnDeconnexion" (click)="onDeconnexion()" routerLink="/login">
|
||||
Deconnexion
|
||||
</button>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import {Component, Input, OnInit} from '@angular/core';
|
||||
import {ProfilService} from "../../services/profil/profil.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-navbar',
|
||||
|
|
@ -9,9 +10,14 @@ export class NavbarComponent implements OnInit
|
|||
{
|
||||
@Input() pour = "login";
|
||||
|
||||
constructor() { }
|
||||
constructor(private profilService: ProfilService) { }
|
||||
|
||||
ngOnInit(): void {}
|
||||
|
||||
onDeconnexion(): void {}
|
||||
onDeconnexion(): void
|
||||
{
|
||||
this.profilService.setId(-1);
|
||||
this.profilService.setIsAdmin(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@
|
|||
<div class="row myRow">
|
||||
<div class="col-6 myLabel">Rôle:</div>
|
||||
<div class="col-6 myValue">
|
||||
<span *ngIf="!person.is_admin">utilisateur</span>
|
||||
<span *ngIf="person.is_admin">admin</span>
|
||||
<span *ngIf="this.from === 'user'">utilisateur</span>
|
||||
<span *ngIf="this.from === 'admin'">admin</span>
|
||||
</div>
|
||||
|
||||
<!-- boutons -->
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@ import { Component, OnInit } from '@angular/core';
|
|||
import {MatDialog} from "@angular/material/dialog";
|
||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||
import {PopupUpdateProfilComponent} from "../popup-update-profil/popup-update-profil.component";
|
||||
import {FictitiousDatasService} from "../../services/fictitiousDatas/fictitious-datas.service";
|
||||
import {Router} from "@angular/router";
|
||||
import {PopupDeleteProfilComponent} from "../popup-delete-profil/popup-delete-profil.component";
|
||||
import {MessageService} from "../../services/message/message.service";
|
||||
import {HttpParams} from "@angular/common/http";
|
||||
import {ProfilService} from "../../services/profil/profil.service";
|
||||
|
||||
|
||||
|
||||
|
|
@ -19,31 +21,42 @@ export class PageProfilComponent implements OnInit
|
|||
id: "",
|
||||
nickname: "",
|
||||
email: "",
|
||||
hash_pass: "",
|
||||
is_admin: false,
|
||||
};
|
||||
from: string = "" ;
|
||||
configSnackbar = { duration: 3000, panelClass: "custom-class" };
|
||||
|
||||
|
||||
constructor( public dialog: MatDialog,
|
||||
constructor( private messageService: MessageService,
|
||||
private profilService: ProfilService,
|
||||
public dialog: MatDialog,
|
||||
private snackBar: MatSnackBar,
|
||||
private fictitiousDatasService: FictitiousDatasService,
|
||||
private router: Router ) { }
|
||||
|
||||
|
||||
ngOnInit(): void
|
||||
{
|
||||
// faux code
|
||||
if(this.router.url.startsWith("/user")) {
|
||||
this.person = this.fictitiousDatasService.getUser();
|
||||
this.from = "user" ;
|
||||
}
|
||||
else if(this.router.url.startsWith("/admin")){
|
||||
this.person = this.fictitiousDatasService.getAdmin();
|
||||
this.from = "admin" ;
|
||||
if(this.router.url.startsWith("/user")) this.from = "user" ;
|
||||
else if(this.router.url.startsWith("/admin")) this.from = "admin" ;
|
||||
|
||||
let params = new HttpParams()
|
||||
params = params.set("order", "");
|
||||
params = params.set("id", this.profilService.getId());
|
||||
this.messageService
|
||||
.get("user", params)
|
||||
.subscribe(ret => this.ngOnInitCallback(ret), err => this.ngOnInitCallback(err));
|
||||
}
|
||||
|
||||
// Vrai code ...
|
||||
|
||||
// Callback de ngOnInit
|
||||
ngOnInitCallback(retour: any): void
|
||||
{
|
||||
if(retour.status !== "success") {
|
||||
console.log(retour);
|
||||
}
|
||||
else {
|
||||
this.person = retour.data[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -64,15 +77,8 @@ export class PageProfilComponent implements OnInit
|
|||
// Callback de onModifier
|
||||
onModifierCallback(retour: any): void
|
||||
{
|
||||
if((retour === null) || (retour === undefined))
|
||||
{
|
||||
const config = { duration: 1000, panelClass: "custom-class" };
|
||||
this.snackBar.open( "Opération annulé", "", config);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.person = retour;
|
||||
}
|
||||
if((retour === null) || (retour === undefined)) this.snackBar.open( "Opération annulé", "", this.configSnackbar);
|
||||
else if(retour.status === "success") this.person = retour.data;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -96,15 +102,9 @@ export class PageProfilComponent implements OnInit
|
|||
// Callback de onSupprimer
|
||||
onSupprimerCallback(retour: any): void
|
||||
{
|
||||
if((retour === null) || (retour === undefined))
|
||||
{
|
||||
const config = { duration: 1000, panelClass: "custom-class" };
|
||||
this.snackBar.open( "Opération annulé", "", config);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.router.navigateByUrl("/login");
|
||||
}
|
||||
if((retour === null) || (retour === undefined)) this.snackBar.open( "Opération annulé", "", this.configSnackbar);
|
||||
else if(retour.status === "error") this.snackBar.open(retour.message, "", this.configSnackbar);
|
||||
else if(retour.status === "success") this.router.navigateByUrl("/login");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import {Component, Inject, OnInit} from '@angular/core';
|
||||
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||
import {MessageService} from "../../services/message/message.service";
|
||||
import {HttpParams} from "@angular/common/http";
|
||||
|
||||
|
||||
|
||||
|
|
@ -10,19 +12,58 @@ import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
|||
})
|
||||
export class PopupDeleteProfilComponent implements OnInit
|
||||
{
|
||||
id: number;
|
||||
me: boolean = false; // on se supprime soi-même
|
||||
email: string = "";
|
||||
|
||||
constructor( public dialogRef: MatDialogRef<PopupDeleteProfilComponent>,
|
||||
|
||||
constructor( private messageService: MessageService,
|
||||
public dialogRef: MatDialogRef<PopupDeleteProfilComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any ) { }
|
||||
|
||||
|
||||
ngOnInit(): void {
|
||||
this.id = this.data.id;
|
||||
this.me = this.data.me;
|
||||
this.email = this.data.email;
|
||||
}
|
||||
|
||||
onValider(): void {
|
||||
this.dialogRef.close(true);
|
||||
|
||||
// Appuie sur 'valider'
|
||||
onValider(): void
|
||||
{
|
||||
if(this.me)
|
||||
{
|
||||
this.messageService
|
||||
.delete("user/delete")
|
||||
.subscribe(ret => this.onValiderCallback(ret), err => this.onValiderCallback(err));
|
||||
}
|
||||
else {
|
||||
let params = new HttpParams();
|
||||
params = params.set("id", this.id);
|
||||
this.messageService
|
||||
.delete("admin/delete", params)
|
||||
.subscribe(ret => this.onValiderCallback(ret), err => this.onValiderCallback(err));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Callback de onValider
|
||||
onValiderCallback(retour: any): void
|
||||
{
|
||||
if(retour.status === "success")
|
||||
{
|
||||
this.dialogRef.close(retour);
|
||||
}
|
||||
else if(retour.status === "error")
|
||||
{
|
||||
console.log(retour);
|
||||
this.dialogRef.close(retour);
|
||||
}
|
||||
else {
|
||||
console.log(retour);
|
||||
this.dialogRef.close(null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {Component, Inject, OnInit} from '@angular/core';
|
||||
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||
import {CheckEmailService} from "../../services/checkEmail/check-email.service";
|
||||
import {HashageService} from "../../services/hashage/hashage.service";
|
||||
import {MessageService} from "../../services/message/message.service";
|
||||
|
||||
|
||||
|
||||
|
|
@ -20,10 +20,10 @@ export class PopupUpdateProfilComponent implements OnInit
|
|||
errorMessage: string = "" ;
|
||||
|
||||
|
||||
constructor( public dialogRef: MatDialogRef<PopupUpdateProfilComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||
private checkEmailService: CheckEmailService,
|
||||
private hashageService: HashageService ) { }
|
||||
constructor( private checkEmailService: CheckEmailService,
|
||||
private messageService: MessageService,
|
||||
public dialogRef: MatDialogRef<PopupUpdateProfilComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any ) { }
|
||||
|
||||
|
||||
ngOnInit(): void
|
||||
|
|
@ -33,7 +33,6 @@ export class PopupUpdateProfilComponent implements OnInit
|
|||
id: person.id,
|
||||
nickname: person.nickname,
|
||||
email: person.email,
|
||||
hash_pass: person.hash_pass,
|
||||
is_admin: person.is_admin
|
||||
};
|
||||
}
|
||||
|
|
@ -45,13 +44,14 @@ export class PopupUpdateProfilComponent implements OnInit
|
|||
this.checkField();
|
||||
if(!this.hasError)
|
||||
{
|
||||
if(this.changePassword) this.personCopy.hash_pass = this.hashageService.run(this.newPassword);
|
||||
const data = { user: this.personCopy };
|
||||
|
||||
// ...
|
||||
|
||||
// Faux code
|
||||
this.onValiderCallback({ status: "success"});
|
||||
let data: any = {nickname: this.personCopy.nickname};
|
||||
if(this.changePassword) data = {
|
||||
nickname: this.personCopy.nickname,
|
||||
password: this.newPassword
|
||||
};
|
||||
this.messageService
|
||||
.put("user/update", data)
|
||||
.subscribe(ret => this.onValiderCallback(ret), err => this.onValiderCallback(err));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -59,14 +59,19 @@ export class PopupUpdateProfilComponent implements OnInit
|
|||
// Callback de 'onValider'
|
||||
onValiderCallback(retour: any)
|
||||
{
|
||||
if(retour.status === 'error')
|
||||
if(retour.status === "success")
|
||||
{
|
||||
this.dialogRef.close(retour);
|
||||
}
|
||||
else if(retour.status === "error")
|
||||
{
|
||||
console.log(retour);
|
||||
this.dialogRef.close(null);
|
||||
this.errorMessage = retour.message;
|
||||
this.hasError = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dialogRef.close(this.personCopy);
|
||||
else {
|
||||
console.log(retour);
|
||||
this.dialogRef.close(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,38 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {HttpClient, HttpParams} from "@angular/common/http";
|
||||
import {Observable} from "rxjs";
|
||||
import {environment} from "../../../../environments/environment";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MessageService {
|
||||
export class MessageService
|
||||
{
|
||||
|
||||
constructor( private http: HttpClient ) { }
|
||||
|
||||
post(url: string, data: any): Observable<any>
|
||||
{
|
||||
const urlComplete = environment.debutUrl + url ;
|
||||
return this.http.post<any>(urlComplete, data, {withCredentials: true});
|
||||
}
|
||||
|
||||
get(url: string, params:HttpParams = new HttpParams()): Observable<any>
|
||||
{
|
||||
const urlComplete = environment.debutUrl + url ;
|
||||
return this.http.get<any>(urlComplete,{ withCredentials: true, params: params });
|
||||
}
|
||||
|
||||
put(url: string, data: any): Observable<any>
|
||||
{
|
||||
const urlComplete = environment.debutUrl + url ;
|
||||
return this.http.put<any>(urlComplete, data, {withCredentials: true});
|
||||
}
|
||||
|
||||
delete(url: string, params:HttpParams = new HttpParams()): Observable<any>
|
||||
{
|
||||
const urlComplete = environment.debutUrl + url ;
|
||||
return this.http.delete<any>(urlComplete,{withCredentials: true});
|
||||
}
|
||||
|
||||
constructor() { }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,40 @@ import { Injectable } from '@angular/core';
|
|||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ProfilService {
|
||||
export class ProfilService
|
||||
{
|
||||
|
||||
constructor()
|
||||
{
|
||||
this.setId(-1);
|
||||
this.setIsAdmin(false);
|
||||
}
|
||||
|
||||
getId(): number
|
||||
{
|
||||
let idString = localStorage.getItem('id');
|
||||
if(idString === null) return -1;
|
||||
else return parseInt(idString);
|
||||
}
|
||||
|
||||
setId(id: number): void
|
||||
{
|
||||
localStorage.setItem('id', id.toString());
|
||||
}
|
||||
|
||||
getIsAdmin(): boolean
|
||||
{
|
||||
let isAdminString = localStorage.getItem('isAdmin');
|
||||
if(isAdminString === "T") return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
setIsAdmin(isAdmin: boolean): void
|
||||
{
|
||||
let isAdminString = "" ;
|
||||
if(isAdmin) isAdminString = "T";
|
||||
else isAdminString = "F";
|
||||
localStorage.setItem('isAdmin', isAdminString);
|
||||
}
|
||||
|
||||
constructor() { }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import {Component} from '@angular/core';
|
||||
import {Router} from "@angular/router";
|
||||
import {MessageService} from "../../common/services/message/message.service";
|
||||
import {HashageService} from "../../common/services/hashage/hashage.service";
|
||||
import {environment} from "../../../environments/environment";
|
||||
import {ProfilService} from "../../common/services/profil/profil.service";
|
||||
|
||||
|
||||
|
||||
|
|
@ -21,40 +20,40 @@ export class PageLoginComponent
|
|||
|
||||
constructor( private messageService: MessageService,
|
||||
private router: Router,
|
||||
private hashageService: HashageService ) { }
|
||||
private profilService: ProfilService ) { }
|
||||
|
||||
|
||||
// Appuie sur le bouton "seConnecter"
|
||||
onSeConnecter(): void
|
||||
{
|
||||
console.log("test env: "+environment.api_url);
|
||||
this.checkField();
|
||||
if(!this.hasError)
|
||||
{
|
||||
let data = {
|
||||
const data = {
|
||||
email: this.email,
|
||||
hash_pass: this.hashageService.run(this.password)
|
||||
password: this.password
|
||||
};
|
||||
console.log(data);
|
||||
/*
|
||||
this.messageService
|
||||
.sendMessage('user/auth', data)
|
||||
.subscribe( retour => this.callbackSeConnecter(retour))
|
||||
*/
|
||||
.post('login', data)
|
||||
.subscribe( retour => this.onSeConnecterCallback(retour), err => this.onSeConnecterCallback(err));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Callback de "onSeConnecter"
|
||||
callbackSeConnecter(retour: any): void
|
||||
onSeConnecterCallback(retour: any): void
|
||||
{
|
||||
if(retour.status !== 200)
|
||||
if(retour.status !== "success")
|
||||
{
|
||||
this.errorMessage = retour.error.data.reason;
|
||||
console.log(retour);
|
||||
this.errorMessage = retour.message;
|
||||
this.hasError = true;
|
||||
}
|
||||
else {
|
||||
//this.router.navigateByUrl( '/search' );
|
||||
this.profilService.setId(retour.data.id);
|
||||
this.profilService.setIsAdmin(retour.data.is_admin)
|
||||
if(retour.data.is_admin) this.router.navigateByUrl('admin/userList');
|
||||
else this.router.navigateByUrl('user/userList');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import {Router} from "@angular/router";
|
|||
import {CheckEmailService} from "../../common/services/checkEmail/check-email.service";
|
||||
import {MatDialog} from "@angular/material/dialog";
|
||||
import {PopupConfirmRegisterComponent} from "../popup-confirm-register/popup-confirm-register.component";
|
||||
import {MessageService} from "../../common/services/message/message.service";
|
||||
|
||||
|
||||
|
||||
|
|
@ -27,8 +28,8 @@ export class PageRegisterComponent
|
|||
errorMessage: string = "";
|
||||
|
||||
|
||||
constructor( private hashageService: HashageService,
|
||||
private checkEmailService: CheckEmailService,
|
||||
constructor( private checkEmailService: CheckEmailService,
|
||||
private messageService: MessageService,
|
||||
private router: Router,
|
||||
public dialog: MatDialog ) { }
|
||||
|
||||
|
|
@ -39,18 +40,14 @@ export class PageRegisterComponent
|
|||
this.checkField();
|
||||
if(!this.hasError)
|
||||
{
|
||||
this.person.hash_pass = this.hashageService.run(this.password);
|
||||
|
||||
// FAUX CODE
|
||||
const retour = { status: "succes", data: {} };
|
||||
this.onValiderCallback(retour);
|
||||
|
||||
// VRAI CODE
|
||||
/*
|
||||
const data = {
|
||||
email: this.person.email,
|
||||
nickname: this.person.nickname,
|
||||
is_admin: false
|
||||
};
|
||||
this.messageService
|
||||
.sendMessage('register', this.user)
|
||||
.subscribe(retour => this.onValiderCallback(retour));
|
||||
*/
|
||||
.post('register', data)
|
||||
.subscribe( retour => this.onValiderCallback(retour), err => this.onValiderCallback(err));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -58,16 +55,17 @@ export class PageRegisterComponent
|
|||
// Callback de "onValider"
|
||||
onValiderCallback(retour: any): void
|
||||
{
|
||||
if(retour.status === "error")
|
||||
if(retour.status !== "success")
|
||||
{
|
||||
console.log(retour);
|
||||
this.errorMessage = retour.message;
|
||||
this.hasError = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
this.dialog
|
||||
.open(PopupConfirmRegisterComponent, {})
|
||||
.afterClosed()
|
||||
.subscribe(retour => this.router.navigateByUrl("/"));
|
||||
.subscribe(retour => this.router.navigateByUrl("/login"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ import {AfterViewInit, Component, ViewChild} from '@angular/core';
|
|||
import {MatTableDataSource} from "@angular/material/table";
|
||||
import {MatSort} from "@angular/material/sort";
|
||||
import {MatPaginator} from "@angular/material/paginator";
|
||||
import {FictitiousDatasService} from "../../common/services/fictitiousDatas/fictitious-datas.service";
|
||||
import {MatDialog} from "@angular/material/dialog";
|
||||
import {MessageService} from "../../common/services/message/message.service";
|
||||
|
||||
|
||||
|
||||
|
|
@ -15,22 +14,29 @@ import {MatDialog} from "@angular/material/dialog";
|
|||
export class PageRegistryComponent implements AfterViewInit
|
||||
{
|
||||
displayedColumns: string[] = [ "nickname", "email", "role" ];
|
||||
dataSource: MatTableDataSource<any>;
|
||||
dataSource: MatTableDataSource<any> = new MatTableDataSource<any>();
|
||||
@ViewChild(MatSort) sort: MatSort;
|
||||
@ViewChild(MatPaginator) paginator: MatPaginator;
|
||||
|
||||
|
||||
constructor( private fictitiousDatasService: FictitiousDatasService,
|
||||
public dialog: MatDialog ) { }
|
||||
constructor( private messageService: MessageService ) { }
|
||||
|
||||
|
||||
ngAfterViewInit(): void
|
||||
{
|
||||
// Faux code
|
||||
let tabPerson = this.fictitiousDatasService.getTabPerson(5);
|
||||
this.messageService
|
||||
.get('users?order_by=nickname')
|
||||
.subscribe(retour => this.ngAfterViewInitCallback(retour), err => this.ngAfterViewInitCallback(err));
|
||||
}
|
||||
|
||||
// Vrai code ...
|
||||
|
||||
ngAfterViewInitCallback(retour: any): void
|
||||
{
|
||||
if(retour.status !== "success") {
|
||||
console.log(retour);
|
||||
}
|
||||
else {
|
||||
let tabPerson: { id: number, email: string, nickname: string, is_admin: boolean }[] = retour.data;
|
||||
tabPerson = tabPerson.map( person => {
|
||||
if(!person.is_admin) return Object.assign(person, {role: "utilisateur"});
|
||||
else return Object.assign(person, {role: "admin"});
|
||||
|
|
@ -39,9 +45,10 @@ export class PageRegistryComponent implements AfterViewInit
|
|||
this.dataSource.sort = this.sort;
|
||||
this.dataSource.paginator = this.paginator;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
applyFilter(event: Event)
|
||||
applyFilter(event: Event): void
|
||||
{
|
||||
const filterValue = (event.target as HTMLInputElement).value;
|
||||
this.dataSource.filter = filterValue.trim().toLowerCase();
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
// This file can be replaced during build by using the `fileReplacements` array.
|
||||
// `ng build` replaces `environment.ts` with `environment.prod.ts`.
|
||||
// The list of file replacements can be found in `angular.json`.
|
||||
|
||||
export const environment = {
|
||||
production: false,
|
||||
api_url: '${API_URL}'
|
||||
debutUrl: "http://127.0.0.1:5000/api/"
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue