Exemplo n.º 1
0
 def test_get_user(self):
     u = user.User()
     rv = self.addUser("Fred Bloggs", "*****@*****.**", "abc123")
     users = u.getUserByEmail('*****@*****.**')
     assert users[0] != None
     users = u.getUser(users[0])
     assert users[0] != None
Exemplo n.º 2
0
 def test_update_user(self):
     u = user.User()
     rv = u.updateUser(21,'fred bloggs1','*****@*****.**','abc1234')
     assert rv == "update successful"
     rv = u.updateUser(21, 'fred bloggs2', '*****@*****.**', 'abc123')
     assert rv == "update successful"
     rv = u.updateUser(21, 'fred bloggs2', '*****@*****.**', '')
     assert rv == "update successful"
Exemplo n.º 3
0
def login():
    if request.method == 'POST':
        phone = request.form["phone"]
        password = request.form["password"]
        user_auth = user.User()
        result = user_auth.user_login(phone=phone,password=password)
        if result["code"] == 0:#rewrite index html
            return redirect("/")
        else:#rewrite error html
            return str(result["message"])
    return render_template("login.html")
Exemplo n.º 4
0
 def user_auth(self, data):
     auth_info = json.loads(data)
     if auth_info["username"] in settings.USER_ACCOUNT:
         if settings.USER_ACCOUNT[auth_info["username"]][
                 "password"] == auth_info["password"]:
             self.login_user = user.User(
                 auth_info["username"],
                 settings.USER_ACCOUNT[auth_info["username"]])
             response_code = "200"
         else:
             response_code = "201"
         self.request.send("response|{0}".format(response_code).encode())
Exemplo n.º 5
0
def register():
    if request.method == 'POST':
        phone = request.form["phone"]
        password = request.form["password"]
        username = request.form["username"]
        ensure_password = request.form["ensure_password"]
        stage_class = request.form["stage_class"]
        user_reg = user.User()
        result = user_reg.user_reg(phone=phone,
                                 username=username,
                                 password=password,
                                 ensure_password=ensure_password,
                                 stage_class=stage_class)
        if result["code"] == 0:
            return redirect("/")
        else:
            return str(result["message"])
    return render_template("register.html")
Exemplo n.º 6
0
def main():
    """ execute all the actions """
    os.system("cls")
    # input("\n\tBienvenu dans l'application Pur Beurre. Cette application a pour fonction"\
    # " de vous montrer que parmi des produits du quotidien vous pouvez trouver un "\
    # "substitut dont la fabrication est respectueuse de l'environnement.\n")

    my_user = us.User("adi", "123", True)
    # input(my_user.id)
    loop = True
    while loop:
        os.system("cls")
        print("\n", "-" * 30, " PAGE D'ACCUEIL ", "-" * 30, "\n")
        if my_user.connected:
            print("Vous êtes connecté(e) en tant que : {}.".format(
                my_user.pseudo))
            answer = input("\nQue voulez-vous faire ?\n"\
                "  1 - Me déconnecter\n"\
                "  2 - Remplacer un aliment, \n"\
                "  3 - Retrouver mes aliments substitués,\n"\
                "  4 - Quitter.\n ->")
        else:
            print("Vous n'êtes pas connecté(e).")
            my_user.pseudo = ""
            my_user.password = ""

            answer = input("\nQue voulez-vous faire ? "\
                " (Par exemple : Taper '1' et entrer pour vous connecter) \n"\
                "  1 - Me connecter, \n"\
                "  2 - Remplacer un aliment, \n"\
                "  3 - Retrouver mes aliments substitués,\n"\
                "  4 - Quitter.\n ->")
##################################################################################### 1
        if answer == "1":
            #depend on my_user.connected
            if my_user.connected:
                my_user.connected = False
                my_user.pseudo = ""
                my_user.password = ""
            else:
                my_db = dbu.DbUser()
                my_user = my_db.authentication(my_user)

##################################################################################### 2
        elif answer == "2":
            # if not my_user.connected:
            #     my_db = dbu.DbUser()
            #     my_user = my_db.authentication(my_user)
            # if not my_user.connected:
            #     print("Retour au menu principal ! ")
            #     time.sleep(1)
            #     continue
            loop = True
            while loop:
                choice = db.Database()
                selected_cat = choice.display_choice_cat(my_user)
                if selected_cat == "menu":
                    break
                selected_prod = choice.display_choice_prod(
                    my_user, selected_cat)
                if selected_prod == "menu":
                    break
                stop = choice.compare_prod_with_sub(selected_cat,
                                                    selected_prod, my_user)
                if stop == "menu":
                    break
                after_search = choice.after_search("3")
                if after_search == "1":
                    url = choice.display_more_info_about_product(selected_prod)
                    webbrowser.open_new(url)
                    after_web = choice.after_search("2")
                    if after_web == "2":
                        break
                elif after_search == "2":
                    pass
                elif after_search == "3":
                    break
                else:
                    break

##################################################################################### 3

        elif answer == "3":
            my_db = dbu.DbUser()
            if not my_user.connected:
                my_user = my_db.authentication(my_user)
            if not my_user.connected:
                print("Retour au menu principal ! ")
                time.sleep(1)
                continue
            #consult_database permit to the user to access the database
            os.system("cls")
            print("\n", "-" * 30, " BASE DE DONNEES ", "-" * 30, "\n")
            chain = my_db.history(my_user)
            print(chain)
            input("Appuyez sur 'entrer' pour revenir au menu principal.")


##################################################################################### 4
        elif answer == "4":
            print("A bientôt !")
            time.sleep(1)
            os.system("cls")
            sys.exit(2)
        else:
            print("Je n'ai pas compris.")
Exemplo n.º 7
0
def hello():
    u = user.User("New", "User")
    return render_template('index.html', name=u.surname)
Exemplo n.º 8
0
 def test_check_passwords(self):
     u = user.User()
     assert u.checkPassword('abc124', 'abc124') == "match"
     assert u.checkPassword('abc124', 'abc123') == "missmatch"
     assert u.checkPassword('', '') == "invalid"
Exemplo n.º 9
0
 def test_get_users(self):
     u = user.User()
     rv = self.addUser("Fred Bloggs", "*****@*****.**", "abc123")
     users = u.getUsers()
     assert users != 'error running query'