Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Classeur1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user;password;privilege1;privilege2
Lolo;lolo123;;
mallo;mallo456;;X
49 changes: 49 additions & 0 deletions Connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from pymongo import MongoClient
import bcrypt

cluster = MongoClient(
"mongodb+srv://Logan:lolo123@cluster0.igyjs.mongodb.net/ecole?retryWrites=true&w=majority")
db = cluster.testdb
collection = db.testcollection


class Connection:
def __init__(self, username, password):
self.username = username
self.__password = password

def __str__(self):
return f"Bonjour {self.username}"

@property
def check_user_exist(self):
"""
:param username: the username of the user
:return: 1 if the user exist, 0 if the user dont exist
"""
users_elements = 0
for i in collection.find({"username": self.username}):
users_elements = + 1
if users_elements > 0:
return True
else:
return False

@property
def get_user_data_from_db(self):
if self.check_user_exist:
user_data = {}
data = collection.find({"username": self.username})
for i in data:
for key, value in i.items():
user_data[key] = value
return True, user_data
else:
return False

@property
def check_password(self):
dic_data = self.get_user_data_from_db
password_register_in_database = dic_data["password"]
password_crypted = bytes(self.__password, encoding="utf-8")
return bcrypt.checkpw(password_crypted, password_register_in_database)
40 changes: 40 additions & 0 deletions PasswordForget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from Connection import Connection, collection
from utilities_lib import check_password_strength, upper_function, hashed_password
import bcrypt


class PasswordForget(Connection):
def __init__(self, username, password=''):
Connection.__init__(self, username, password)

@property
def data_user(self):
self.data = self.get_user_data_from_db
return self.data

@property
def search_secret_question(self):
dic_user = self.data_user
secret_question = dic_user["secret_choice"]
text = "Your secret question is : " + secret_question
return text

def check_secret_answer(self, answer):
self.answer = upper_function(answer)
secret_answer_in_database = self.data_user["secret_answer"]
answer_crypted = bytes(self.answer, encoding="utf-8")
return bcrypt.checkpw(answer_crypted, secret_answer_in_database)

def update_password(self, password):
self.password = password
self.userdata = self.data_user
if check_password_strength(self.password):
self.new_password = hashed_password(password)
self.userdata["password"] = self.new_password
collection.replace_one({"username": self.username}, self.userdata)
else:
return False


a = PasswordForget("Printemps")
print(a.update_password("Tutu1234"))
60 changes: 60 additions & 0 deletions Register.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from utilities_lib import check_password_strength, upper_function, hashed_password, hashed_secret_answer
from Connection import Connection, collection
import re

class Register:
def __init__(self, username, password, password_confirmed, email, secret_question, secret_answer):
self.username = username
self.password = password
self.password_confirmed = password_confirmed
self.email = email
self.secret_question = secret_question
self.secret_answer = upper_function(secret_answer)

@property
def check_email_exist(self):
"""
check if email address
:return: True if the email is correct and if it exist in the database, False if the email address does exist in the database
and Invalid Email if the email address is not valid
"""
users_elements = 0
regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
if re.fullmatch(regex, self.email):
for i in collection.find({"email": self.email}):
users_elements = + 1
if users_elements > 0:
return True
else:
return False
else:
return "Invalid Email"

@property
def check_user_exist(self):
"""
:return: True if the user exist in the data
"""
users_elements = 0
for i in collection.find({"username": self.username}):
users_elements = + 1
if users_elements > 0:
return True
else:
return False

@property
def insert_user_data_to_db(self):
if self.check_email_exist or self.check_user_exist:
return False
else:
role = []
data = {"username": self.username, "email": self.email,
"password": hashed_password(self.password), "secret_question": self.secret_question,
"secret_answer": hashed_secret_answer(self.secret_answer), "role": role}
collection.insert_one(data)
return True


a = Register("Verum", "Lola1234", "Lola1234", "vrm@gmail.com", "Your first pet's name", "Crock")
print(a.insert_user_data_to_db)
80 changes: 80 additions & 0 deletions admin_add_role.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.spinner import Spinner
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from function import determine_all_role, modify_role
from function import manage_roles, determine_all_role


class AddRole(BoxLayout):
def build(self):
self.orientation = "vertical"
self.welcome()
self.warning()
self.id_admin()
self.admin_user()
self.list_option_role()
self.roles_choice()
self.role_choosen()
self.apply_modification()

def welcome(self):
self.label_welcome = Label(text="Welcome in the Admin Page", color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.label_welcome)

def warning(self):
self.label_warning = Label(text="If you are not a admin, you can not do everything", color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.label_warning)

def id_admin(self):
self.label_id_admin = Label(text="Please enter your username", color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.label_id_admin)

def admin_user(self):
self.input_admin_user = TextInput(pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.input_admin_user)

def list_option_role(self):
self.option_list = Spinner(text="Choose do remove or add",
values=("Add role", "Remove role"),
size_hint=(0.4, .01), pos_hint={'x': 0.3, 'y': 0.8}, background_color=[0.59,0.239,0.89,1])
self.add_widget(self.option_list)

def roles_choice(self):
self.label_role_chosen = Label(text="Choose the role to remove, you can choose betwenn : " + str(determine_all_role()), color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.label_role_chosen)

def role_choosen(self):
self.input_role_choosen = TextInput(pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.input_role_choosen)

def apply_modification(self):
self.button_apply = Button(text="Apply", size_hint=(.3, .02),
pos_hint={'x': 0.35, 'y' :0.1}, color=[1, 1, 1, 1], background_color=[0.59,0.239,0.89,1])
self.button_apply.bind(on_press=self.modify_role)
self.add_widget(self.button_apply)

def modify_role(self, instance):
user = self.input_admin_user.text
choice = self.option_list.text
role = self.input_role_choosen.text
message = modify_role(user, choice, role)
self.label_role_chosen.text = ("The new role list : " + str(message) + " " + str(determine_all_role()))
list_roles = determine_all_role()
self.label_welcome.text = str(list_roles)

class WindowTwo(App):
def build(self):
Layout = AddRole()
Layout.build()
return Layout


if __name__ == '__main__':
WindowTwo().run()
123 changes: 123 additions & 0 deletions admin_give_role_to_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.spinner import Spinner
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from function import manage_roles, determine_all_role, search_user_role


class GiveRole(BoxLayout):
def build(self):
self.orientation = "vertical"
self.welcome()
self.id_admin()
self.admin_user()
self.id_user_to_up()
self.user()
self.button_search_user()
self.role_from_user()
self.list_role()
self.role()
self.list_option_role()
self.validation_button()

def welcome(self):
self.label_welcome = Label(text="Welcome in the Admin Page", color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.label_welcome)

def warning(self):
self.label_warning = Label(text="If you are not a admin, you can not do everything", color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.label_warning)

def id_admin(self):
self.label_id_admin = Label(text="Please enter your username", color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.label_id_admin)

def admin_user(self):
self.input_admin_user = TextInput(pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.input_admin_user)

def id_user_to_up(self):
self.label_id_user_to_up = Label(text="Enter the name of the user to whom to give a role", color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.label_id_user_to_up)

def user(self):
self.input_user = TextInput(pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.input_user)

def button_search_user(self):
self.button_search_username = Button(text="Search user", size_hint=(.3, .02),
pos_hint={'x': 0.35, 'y' :0.1}, color=[1, 1, 1, 1], background_color=[0.59,0.239,0.89,1])
self.button_search_username.bind(on_press=self.search_role_user)
self.add_widget(self.button_search_username)


def role_from_user(self):
self.user_roles_label = Label(text="This is the role(s) that the user already has", color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.user_roles_label)

def id_role(self):
self.label_id_role = Label(text="Enter the name of the role you want to give", color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.label_id_role)

def list_role(self):
self.label_list_role = Label(text="Enter the name of the user to whom to give a role \n You can choose one if this : " + str(determine_all_role()), color=[0.59, 0.239, 0.89, 1],
pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.label_list_role)

def role(self):
self.input_role = TextInput(pos_hint={'x': 0.25, 'y': 0.9}, size_hint=(.5, .01))
self.add_widget(self.input_role)

def list_option_role(self):
self.option_list = Spinner(text="Choose do remove or add",
values=("Add role", "Remove role"),
size_hint=(0.4, .01), pos_hint={'x': 0.3, 'y': 0.8}, background_color=[0.59,0.239,0.89,1])
self.add_widget(self.option_list)


def validation_button(self):
self.button_of_validation = Button(text="Give role", size_hint=(.3, .02),
pos_hint={'x': 0.35, 'y' :0.1}, color=[1, 1, 1, 1], background_color=[0.59,0.239,0.89,1])
self.button_of_validation.bind(on_press=self.give_role)
self.add_widget(self.button_of_validation)

# ----------------------------------------------------------- Space Graphic -----------------------------------------------------------#

def black_space(self):
self.black = Label(size_hint=(.4, .1))
self.add_widget(self.black)


def search_role_user(self, instance):
self.user_roles_label.text = "This is the role(s) that the user already has " + str(search_user_role(self.input_admin_user.text, self.input_user.text))


def give_role(self, instance):
admin = self.input_admin_user.text
user = self.input_user.text
role = self.input_role.text.upper()
add_remove = self.option_list.text
response = manage_roles(admin, user, add_remove, role)
self.label_welcome.text = str(response)





class Window(App):
def build(self):
Layout = GiveRole()
Layout.build()
return Layout


if __name__ == '__main__':
Window().run()
Loading