-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_accout.py
More file actions
156 lines (127 loc) · 7.32 KB
/
Copy pathcreate_accout.py
File metadata and controls
156 lines (127 loc) · 7.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.spinner import Spinner
from mongo_connection import data_mongo, user_already_know, email_ok, same_password, is_strong_password, \
number_user, collection, create_data_to_db, secret_question_ok
class CreateUserFunction(BoxLayout):
def build(self):
self.orientation = "vertical"
self.color = [0,0,1,1]
self.black_space()
self.label_creation()
self.username_label()
self.input_username()
self.email_label()
self.input_email()
self.password_label()
self.input_password()
self.password_confirm_label()
self.input_password_confirm()
self.black_space()
self.list_option_password_forget()
self.black_space()
self.secret_answer_label()
self.input_secret_answers()
self.black_space()
self.confirm_account_creation()
self.black_space()
def label_creation(self):
self.creation_message = Label(text="Create your account", color=[0.59,0.239,0.89,1], size_hint=(.2, .2),
pos_hint={'x': .4, 'y': 2}, font_size = 25)
self.add_widget(self.creation_message)
# ----------------------------------------------------------- Username -----------------------------------------------------------#
def username_label(self):
self.message_username = Label(text="What's your username", size_hint=(.2, .2), pos_hint={'x': 0.4})
self.add_widget(self.message_username)
def input_username(self):
self.username_input = TextInput(text="", font_size=20, size_hint=(.4, .17),
pos_hint={'x': 0.30, 'y': 2}, halign="center")
self.add_widget(self.username_input)
# ----------------------------------------------------------- Email -----------------------------------------------------------#
def email_label(self):
self.message_email = Label(text="What's your email address", size_hint=(.2, .2), pos_hint={'x': 0.4})
self.add_widget(self.message_email)
def input_email(self):
self.email_input = TextInput(text="", font_size=20, size_hint=(.4, .17),
pos_hint={'x': 0.30}, halign="center")
self.add_widget(self.email_input)
# ----------------------------------------------------------- Password -----------------------------------------------------------#
def password_label(self):
self.message_password = Label(text="What's your password", size_hint=(.2, .2), pos_hint={'x': 0.4})
self.add_widget(self.message_password)
def input_password(self):
self.password_input = TextInput(text="", font_size=20, size_hint=(.4, .17),
pos_hint={'x': 0.30}, halign="center")
self.add_widget(self.password_input)
def password_confirm_label(self):
self.message_password_confirm = Label(text="Confirm your password", size_hint=(.2, .2), pos_hint={'x': 0.4})
self.add_widget(self.message_password_confirm)
def input_password_confirm(self):
self.password_confirm_input = TextInput(text="", font_size=20, size_hint=(.4, .17),
pos_hint={'x': 0.30}, halign="center")
self.add_widget(self.password_confirm_input)
# ----------------------------------------------------------- Secret Question -----------------------------------------------------------#
def list_option_password_forget(self):
self.option_list = Spinner(text="Choose your question",
values=("Your first pet's name", "your basics school", "your mother's name"),
size_hint=(0.4, .17), pos_hint={'x': 0.3, 'y': 0.8}, background_color=[0.59,0.239,0.89,1])
self.add_widget(self.option_list)
# ----------------------------------------------------------- Secret Answer -----------------------------------------------------------#
def secret_answer_label(self):
self.message_secret_answer = Label(text="Introduce your answer", size_hint=(.2, .15), pos_hint={'x': 0.4})
self.add_widget(self.message_secret_answer)
def input_secret_answers(self):
self.secret_answer = TextInput(text="",
size_hint=(0.4, .17), pos_hint={'x': 0.3, 'y': 0.8}, font_size=20, halign="center")
self.add_widget(self.secret_answer)
# ----------------------------------------------------------- Button -----------------------------------------------------------#
def confirm_account_creation(self):
self.confirmaccountcreation = Button(text="confirm the account creation", size_hint=(.3, .2),
pos_hint={'x': 0.35, 'y' :0.1}, color=[1, 1, 1, 1], background_color=[0.59,0.239,0.89,1])
self.confirmaccountcreation.bind(on_press=self.user_not_know)
self.add_widget(self.confirmaccountcreation)
# ----------------------------------------------------------- Space Graphic -----------------------------------------------------------#
def black_space(self):
self.black = Label(size_hint=(.4, .1))
self.add_widget(self.black)
# ----------------------------------------------------------- Function -----------------------------------------------------------#
def user_not_know(self, instance):
"""
create the user if all the condition are respected
:param instance: /
:return: /
"""
username = self.username_input.text
email = self.email_input.text
password = self.password_input.text
password_confirmed = self.password_confirm_input.text
choice_question = self.option_list.text
answer_secret_question = self.secret_answer.text.upper()
if user_already_know(username):
self.creation_message.text = ("this username is already taken")
else:
if email_ok(email):
if same_password(password, password_confirmed):
if is_strong_password(password):
if secret_question_ok(choice_question, answer_secret_question):
create_data_to_db(username, email, password, choice_question, answer_secret_question)
self.creation_message.text = ("Welcome " + username + " !")
else:
self.creation_message.text = ("You need to choose a question and answer it")
else:
self.creation_message.text = (
"The password need to have minimum 8 caracteres, a digit and a letter")
else:
self.creation_message.text = ("The two password is not the same")
else:
self.creation_message.text = ("This email address is not correct, or already use")
class CreateAccount(App):
def build(self):
Layout = CreateUserFunction()
Layout.build()
return Layout
if __name__ == '__main__':
CreateAccount().run()