def login_(): em = EntityManager() db = em.get_db() userId = -1 questions = [ inquirer.RequiredText("email", "Addresse email"), inquirer.Password("password", "Mot de passe") ] while "Verfication de l'utilisateur": try: answers = inquirer.prompt(questions) if len(answers.keys()) != 2: return False username = answers["email"] password = answers["password"] #cuGetTypeBien = db.cursor(dictionary=True) users = Personne.where( "email= '{}' AND mot_de_passe='{}' LIMIT 0,1".format( username, password)) #userRes = cuGetTypeBien.fetchall() if len(users) == 1: g = Gui() g.user = users[0] userId = users[0].id break print("L'utilisateur n'existe pas") except KeyboardInterrupt: return False return True
def register_(): print("Hello new user, please fill out the following form \n\n") entity = Personne() answers = None fields = [ "nom", "prenom", ] questions = [ inquirer.Text("nom", message="Nouveau nom"), inquirer.Text("prenom", message="Nouveau prénom"), inquirer.List("genre", message="Genre", choices=["Homme", "Femme", "Agender", "Pangender", "Androgyne", "Genre fluide"]), inquirer.Email("email","Email"), inquirer.Password("mot_de_passe", message="Mot de passe") ] while "Create a user uniquely with his email": answers = inquirer.prompt(questions) if answers is None or not len(answers.keys()) : return False #check if user doesn't aready exist #TODO change he email field to actual email table field if len(Personne.where("`email` = '{}'".format(answers["email"]))) > 0: print("Un utilisateur avec l'email {} existe déjà...\n\n".format(answers["email"])) else: break logging.debug("Creating user (%s) with values %s", entity, answers) for field, value in answers.items(): setattr(entity, field, value) logging.debug("Entite personne %s", entity) print("\nMerci, maintenant nous voulons encore recuillir votre adresse \n") ad_data = get_address() if not len(ad_data.keys()): return False adresse = Addresse.create(**ad_data) p = Personne(**answers) p.adresse_id = adresse.id p.save() logging.debug("personne %s", p) g = Gui() g.user = p print("Utilisateur crée avec succès!") Page.wait_input() return True