Beispiel #1
0
 def __init__(self, master):
     self.master = master
     self.user = User()
     self.idcon = ""
     self.user.idmail = StringVar()
     self.user.password = StringVar()
     self.user.nom = StringVar()
     self.user.age = IntVar()
     self.user.niveau = ""
     self.user.score = 0
     self.acf = Frame(self.master, padx=30, pady=30)
     self.qcpf = Frame(self.master, padx=30, pady=30)
     self.crf = Frame(self.master, padx=30, pady=30)
     self.widgets()
Beispiel #2
0
 def get_one_by_id(self, id):
     if id == None or id < 0:
         return None
     self.cursor.execute("SELECT * from projekt.user where id=%d ;" % id)
     records_user = self.cursor.fetchone()
     if records_user == None:
         return None
     new_user = User()
     new_user.id = records_user[0]
     new_user.name = records_user[1]
     new_user.surename = records_user[2]
     new_user.login = records_user[3]
     new_user.password = records_user[4]
     new_user.lastlogin = records_user[5]
     new_user.lastlogintime = records_user[6]
     return new_user
Beispiel #3
0
 def test_update_parameter_none(self):
     user = User()
     user.id = 1
     user.name = 'Tomas'
     user.surename = 'Krystof'
     user.login = '******'
     user.password = None
     result = self.user_repository.update(user)
     self.assertEqual(result, None)
Beispiel #4
0
 def test_user_delete_valid(self):
     user = User()
     user.id = 3
     user.name = 'Johny'
     user.surename = 'Knoxville'
     user.login = '******'
     user.password = 12345
     self.user_repository.add_new_user(user)
     self.user_repository.user_delete(3)
Beispiel #5
0
 def test_add_new_user_parameter_none(self):
     user = User()
     user.id = 2
     user.name = None
     user.surename = 'Sochan'
     user.login = '******'
     user.password = 12345
     result = self.user_repository.add_new_user(user)
     self.assertEqual(result, None)
Beispiel #6
0
 def get_all(self):
     self.cursor.execute("SELECT * from projekt.user ;")
     records_user = self.cursor.fetchall()
     if records_user == None:
         return None
     user_list = []
     for user in records_user:
         new_user = User()
         new_user.id = user[0]
         new_user.name = user[1]
         new_user.surename = user[2]
         new_user.login = user[3]
         new_user.password = user[4]
         new_user.lastlogin = user[5]
         new_user.lastlogintime = user[6]
         user_list.append(new_user)
     return user_list
Beispiel #7
0
 def user_select(self, login_result, pass_result):
     if login_result == None or pass_result == None:
         return None
     user_select_query = "SELECT * from projekt.user where login=%s and password=%s"
     parameters = (str(login_result), str(pass_result))
     self.cursor.execute(user_select_query, parameters)
     selected_user = self.cursor.fetchone()
     if selected_user != None:
         new_user = User()
         new_user.id = selected_user[0]
         new_user.name = selected_user[1]
         new_user.surename = selected_user[2]
         new_user.login = selected_user[3]
         new_user.password = selected_user[4]
         new_user.lastlogin = selected_user[5]
         new_user.lastlogintime = selected_user[6]
         return new_user
     else:
         return None
Beispiel #8
0
 def test_add_new_user_valid(self):
     user = User()
     user.id = 2
     user.name = 'Jaroslav'
     user.surename = 'Sochan'
     user.login = '******'
     user.password = 12345
     self.user_repository.add_new_user(user)
     self.assertEqual(user.id, 2)
     self.assertEqual(user.name, 'Jaroslav')
     self.assertEqual(user.surename, 'Sochan')
     self.assertEqual(user.login, 'Jaro')
     self.assertEqual(user.password, 12345)
Beispiel #9
0
 def test_update_valid(self):
     user = User()
     user.id = 1
     user.name = 'Tomas'
     user.surename = 'Krystof'
     user.login = '******'
     user.password = 1234
     self.user_repository.update(user)
     self.assertEqual(user.id, 1)
     self.assertEqual(user.name, 'Tomas')
     self.assertEqual(user.surename, 'Krystof')
     self.assertEqual(user.login, 'Toso')
     self.assertEqual(user.password, 1234)
Beispiel #10
0
from Classes.user import User

# Put in a counter of users, to see what user of the app is currently in. We're gonna have to input FILE I/O
# for eachUser in UserLog.txt
#   create and load next user
# return User
User1 = User()





def helloWorld(statement): # 1-1 && 1-2
    print(f"Here's your statement: {statement}")

def getNameAge(UserNumber): # 1-3


    userInput = input(f"Alpha001: Username: "******"Alpha001: Shorter Username: "
            # Needs reset of input functionality

        UserNumber.userName = userInput

        


    age = input(f'Alpha001: Age: ')
    if age:
                ).upper().strip()
                if resp != 'Y' or resp != 'YES':
                    bank = get_bank()
            continue
        except ValueError:
            print('Please input a number')
            continue


def get_date_created():
    while True:
        resp = input('When was this account created? Please insert date in the format: (Month-Day-Year) ') \
            .strip().split('-')
        try:
            created = datetime.datetime(int(resp[2]), int(resp[0]),
                                        int(resp[1]))
            return created
        except ValueError:
            print(
                'Date of Birth not entered in correct format. Please try again.'
            )
            continue


account1 = Account(1, 134562, 352.89, 'test1', 8)
x = datetime.now()
user1 = User('Jaxon', 'Terrell', 'test1', 'hhrS15513', x, 123456789,
             '*****@*****.**', 1)
account = add_account(user1)
print(account)
Beispiel #12
0
 def setUp(self):
     self.user = User("spiderman", "*****@*****.**", "maryJaneparker")
     self.new_recipe = Recipes("Rolex recipe",
                               "Obtain ingredients - eggs and chapatis",
                               "546")
Beispiel #13
0
class userTestCase(unittest.TestCase):
    def setUp(self):
        self.user = User("spiderman", "*****@*****.**", "maryJaneparker")
        self.new_recipe = Recipes("Rolex recipe",
                                  "Obtain ingredients - eggs and chapatis",
                                  "546")

    #Test if the user has Username Variable
    def test_username(self):
        self.assertEqual(self.user.username,
                         "spiderman",
                         msg="Username is invalid")

    #Test if the user has Email Variable
    def test_emailaddress(self):
        self.assertEqual(self.user.email,
                         "*****@*****.**",
                         msg="Email is Invalid")

    #Test if the user has Password Variable
    def test_password(self):
        self.assertEqual(self.user.password,
                         "maryJaneparker",
                         msg="Password is invaid")

    #Test if the User can be registered
    def test_registerUser(self):
        self.user.registerUser(
            ["spiderman", "*****@*****.**", "maryJaneparker"])
        self.assertEqual(
            self.user.database,
            [["spiderman", "*****@*****.**", "maryJaneparker"]],
            msg="User Not Registered")

    #Test Import of Recipes class to make sure the user can interact with a recipe
    def test_recipe_class(self):
        self.assertIsInstance(self.new_recipe,
                              Recipes,
                              msg='Object is not an instance of the  class')

    #Test if user can create a recipe
    def test_create_recipe(self):
        self.assertTrue(self.user.create_recipe(self.new_recipe))

    def test_recipe_to_create_already_exists(self):
        recipe1 = Recipes("Rolex recipe",
                          "Obtain ingredients - eggs and chapatis", "546")
        self.user.recipes = {"546": recipe1}
        self.assertFalse(self.user.create_recipe(recipe1))

    def test_new_recipe_stored_in_dictionary(self):
        self.assertEqual(type(self.user.get_recipes()),
                         dict,
                         msg='Output is not a dictionary')

    def test_a_recipe_is_returned_when_an_id_is_specified(self):
        recipe1 = Recipes("Rolex recipe",
                          "Obtain ingredients - eggs and chapatis", "546")
        self.user.recipes = {"546": recipe1}
        self.assertEqual(self.user.get_recipe("546"), recipe1)

    def test_none_is_returned_for_recipe_doesnot_exist(self):
        self.assertIsNone(self.user.get_recipe("Sandwich"))

    def test_edit_recipe(self):
        self.user.create_recipe(self.new_recipe)
        self.assertTrue(
            self.user.edit_recipe("Sandwich",
                                  "Obtain ingredients-bread ,salads,bacon",
                                  "546"))

    def test_recipe_to_edit_doesnt_exists(self):
        recipe1 = Recipes("Rolex recipe",
                          "Obtain ingredients - eggs and chapatis", "546")
        self.user.create_recipe(recipe1)
        self.assertFalse(
            self.user.edit_recipe("Sandwich",
                                  "Obtain ingredients-bread ,salads,bacon",
                                  "548"))

    def test_del_recipe(self):
        self.user.create_recipe(self.new_recipe)
        self.assertTrue(self.user.del_recipe("546"))

    def test_recipe_to_delete_doesnt_exists(self):
        recipe1 = Recipes("Rolex recipe",
                          "Obtain ingredients - eggs and chapatis", "546")
        self.user.create_recipe(recipe1)
        self.assertFalse(self.user.del_recipe("548"))
Beispiel #14
0
class main():
    def __init__(self, master):
        self.master = master
        self.user = User()
        self.idcon = ""
        self.user.idmail = StringVar()
        self.user.password = StringVar()
        self.user.nom = StringVar()
        self.user.age = IntVar()
        self.user.niveau = ""
        self.user.score = 0
        self.acf = Frame(self.master, padx=30, pady=30)
        self.qcpf = Frame(self.master, padx=30, pady=30)
        self.crf = Frame(self.master, padx=30, pady=30)
        self.widgets()

    def set_date(self):
        temps = datetime.now()
        self.times = temps.hour * 360 + temps.minute * 60
        self.today = temps.date()
        self.iddate = self.today.year * 10000 + self.today.month * 100 + self.today.day

    def difDate(
        self, dat
    ):  #prend une date en parametre et retourne la difference avec la date actuelle en jours pour compter le nombre jours d'inactivite
        dif = self.today - dat
        dif = dif.days
        return dif

    def login(self):
        find_user = ("SELECT * FROM user WHERE idmail = ? AND password = ?")
        cursur.execute(find_user, [(self.user.idmail.get()),
                                   (self.user.password.get())])
        if cursur.fetchall():
            #Message d'acceuil
            self.set_date()  #recuperer la date d'aujourd'hui
            find_niveau = ("SELECT niveau FROM user WHERE idmail = ? ")
            cursur.execute(find_niveau, [(self.user.idmail.get())])
            niveau = cursur.fetchone()  #recuperer son niveau
            find_score = ("SELECT score FROM user WHERE idmail = ?")
            cursur.execute(find_score, [(self.user.idmail.get())])
            score = cursur.fetchone()  #recuperer son score
            find_nom = ("SELECT nom FROM user WHERE idmail = ?")
            cursur.execute(find_nom, [(self.user.idmail.get())])
            nom = cursur.fetchone()  #recuperer son nom
            find_dateid = (
                "SELECT iddate FROM session WHERE idmail = ? ORDER BY iddate DESC"
            )
            cursur.execute(find_dateid, [(self.user.idmail.get())])
            dateid = cursur.fetchone(
            )  #recuperer l'id de sa derniere date de connection
            if dateid != None:
                find_dateid = ("SELECT * FROM date WHERE iddate = ? ")
                cursur.execute(find_dateid, [(dateid[0])])
                dates = cursur.fetchone()
                dat = date(dates[3], dates[2], dates[1])
                if score != None:
                    if self.iddate == dateid[0]:
                        concat = "Bienvenue " + nom[
                            0] + "\nDerniere connexion : Aujourdhui\nScore actuel : " + str(
                                score[0]) + "\nNiveau : " + str(niveau[0])
                        ms.showinfo("Bonjour", concat)
                    else:
                        inactif = self.difDate(dat)
                        if inactif == 1:
                            concat = "Bienvenue " + nom[
                                0] + "\nDerniere connexion : Hier\n" + "Score actuel : " + str(
                                    score[0]) + "\nNiveau : " + str(niveau[0])
                        else:
                            concat = "Bienvenue " + nom[
                                0] + "\nDerniere connexion :/!\ Il y'a " + str(
                                    inactif
                                ) + " jour(s)\nScore actuel : " + str(
                                    score[0]) + "\nNiveau : " + str(niveau[0])
                        ms.showinfo("Bonjour", concat)
            else:
                concat = "Bienvenue a bord\nJe pense que c'est votre premiere fois ici\nO_0 Allez au travail !!"
                ms.showinfo("Hello !", concat)
            #Insertion des donnees de la date
            find_date = ("SELECT * FROM date WHERE iddate = ? ")
            cursur.execute(find_date, [(self.iddate)])
            if cursur.fetchall():
                pass
            else:
                insert_date = (
                    "INSERT INTO date(iddate,jour,mois,annee) VALUES (?,?,?,?)"
                )
                cursur.execute(insert_date, [(self.iddate), (self.today.day),
                                             (self.today.month),
                                             (self.today.year)])
                db.commit()
            #Insertion des donnees de la session
            insert_session = (
                "INSERT INTO session(idsession,idmail,iddate,heureConnect,heureDeconnect) VALUES(?,?,?,?,?)"
            )
            cursur.execute(insert_session, [(None), (self.user.idmail.get()),
                                            (self.iddate), (self.times),
                                            (None)])
            db.commit()
            self.acceuil()
        else:
            ms.showerror("Oops!! ",
                         "Nom d'utilisateur ou Mot de passe incorrect !")

        #re-initialisation a leurs valeurs par defaut
        self.user.idmail.set("")
        self.user.password.set("")

    def new_user(self):
        find_user = ("SELECT * FROM user WHERE idmail = ? ")
        cursur.execute(find_user, [(self.user.idmail.get())])
        if cursur.fetchall():
            ms.showerror("Oops", "Nom d'utilisateur existant")
        else:
            try:
                mypassword = self.user.gen_password(10)
                insert = "INSERT INTO user(idmail,password,nom,age,niveau,score) VALUES (?,?,?,?,?,?)"
                cursur.execute(insert,
                               [(self.user.idmail.get()), (mypassword),
                                (self.user.nom.get()), (self.user.age.get()),
                                (self.user.set_niveau(self.user.age.get())),
                                (0)])
                db.commit()
                ms.showinfo("Success!!", "Compte cree avec succes")
                concat = "Mot de passe genere : " + mypassword + "\n/!\ A ne pas communiquer"
                ms.showinfo("Success!!", concat)
                self.log()
            except:
                ms.showinfo(
                    "Erreurs rencontres",
                    "Conseil:\n-L'age saisi est une valeur entiere\n-L'age est compris entre [1,18["
                )
        #re-initialisation a leurs valeurs par defaut
        self.user.idmail.set("")
        self.user.password.set("")
        self.user.nom.set("")
        self.user.age.set(0)
        self.user.niveau = ""
        self.user.score = 0

    def acceuil(self):
        self.idcon = self.user.idmail.get()
        self.user.password.set("")
        self.logf.pack_forget()
        self.head['text'] = " Genie en Herbe | Acceuil"
        self.acf.pack()

    def qpc(self):
        self.acf.pack_forget()
        self.head['text'] = " Questions pour un Champion"
        self.qcpf.pack()

    def game1qpc(self):
        age = 0
        self.chiffre = Chiffre(self.master)
        self.chiffre.idmail = self.idcon
        self.chiffre.acceuil = self.acf
        find_user = ("SELECT age FROM user WHERE idmail = ? ")
        cursur.execute(find_user, [(self.idcon)])
        age = cursur.fetchone()
        find_niveau = ("SELECT niveau FROM user WHERE idmail = ? ")
        cursur.execute(find_niveau, [(self.idcon)])
        test_niveau = cursur.fetchone()
        if age[0] > 9:
            niveau = "Niveau : " + str(test_niveau[0])
            ms.showinfo("Acces autorise", niveau)
            self.qcpf.pack_forget()
            self.chiffre.widgets()
        else:
            niveau = "Votre niveau : " + str(
                test_niveau[0]) + " ne vous permet pas d'acceder a ce jeu"
            ms.showerror("Niveau Insuffisant", niveau)

    def math(self):
        self.acf.pack_forget()
        self.head['text'] = " Mathematiques "
        self.mathf.pack()

    def game2math(self):
        self.mathf.pack_forget()
        self.calcul = Calcul(self.master)
        self.calcul.acceuil = self.acf
        self.calcul.idmail = self.idcon
        self.calcul.widgets()

    def log(self):
        self.user.idmail.set("")
        self.user.password.set("")
        self.crf.pack_forget()
        self.head['text'] = " LOGIN "
        self.logf.pack()

    def cr(self):
        self.user.idmail.set("")
        self.user.password.set("")
        self.user.nom.set("")
        self.user.age.set(0)
        self.user.niveau = ""
        self.user.score = 0
        self.head['text'] = " CREATION DE COMPTE "
        self.logf.pack_forget()
        self.crf.pack()

    def widgets(self):
        self.head = Label(root,
                          text=" Genie En Herbe | Connection",
                          width=30,
                          font=('bold', 15))
        self.head.pack()
        #Debut Interface de connection
        self.logf = Frame(self.master, padx=30, pady=30)
        Label(self.logf,
              text="M@il: ",
              width=15,
              font=('bold', 14),
              padx=10,
              pady=10).grid(row=0, sticky=W)
        Entry(self.logf,
              textvariable=self.user.idmail,
              width=25,
              font=('calibri', 13)).grid(row=0, column=1, sticky=E)

        Label(self.logf,
              text="Password: "******"*").grid(row=1, column=1, sticky=E)

        Button(self.logf,
               text="  Login ",
               width=15,
               fg='green',
               font=('bold', 14),
               command=self.login).grid(row=2, column=0, sticky=W)
        Button(self.logf,
               text="  Inscription ",
               width=15,
               fg='grey',
               font=('bold', 14),
               command=self.cr).grid(row=2, column=1, sticky=E)
        self.logf.pack()
        #Fin Interface de connection

        #Debut Interface creation de compte
        Label(self.crf,
              text="Fullname: ",
              width=15,
              font=('bold', 14),
              padx=10,
              pady=10).grid(sticky=W)
        Entry(self.crf,
              textvariable=self.user.nom,
              width=25,
              font=('calibri', 13)).grid(row=0, column=1, sticky=E)

        Label(self.crf,
              text="M@il: ",
              width=15,
              font=('bold', 14),
              padx=10,
              pady=10).grid(row=1, column=0, sticky=W)
        Entry(self.crf,
              textvariable=self.user.idmail,
              width=25,
              font=('calibri', 13)).grid(row=1, column=1, sticky=E)

        Label(self.crf,
              text="Age: ",
              width=15,
              font=('bold', 14),
              padx=10,
              pady=10).grid(row=3, column=0, sticky=W)
        Entry(self.crf, textvar=self.user.age, width=25,
              font=('calibri', 13)).grid(row=3, column=1, sticky=E)

        Button(self.crf,
               text=" Retour -> ",
               width=15,
               fg='red',
               font=('bold', 14),
               command=self.log).grid(row=6, column=0, sticky=W)
        Button(self.crf,
               text=" Valider ",
               width=15,
               fg='green',
               font=('bold', 14),
               command=self.new_user).grid(row=6, column=1, sticky=E)
        Label(self.crf,
              text="/!\ NB : Mot de passe genere",
              padx=10,
              pady=10,
              fg='red',
              font=('cambria', 10)).grid(row=7)
        #Fin Interface creation de compte

        #Debut Interface d'acceuil
        Button(self.acf,
               text=" Mathematiques ",
               width=30,
               padx=10,
               pady=15,
               fg='green',
               font=('calibri', 14),
               command=self.math).grid(sticky=W)
        Button(self.acf,
               text=" Questions pour un champion ",
               width=30,
               padx=10,
               pady=15,
               fg='blue',
               font=('calibri', 14),
               command=self.qpc).grid(row=1, sticky=W)
        #Fin Interface d'acceuil

        #Debut Interface questions pour un champion
        Button(self.qcpf,
               text=" Chiffre a Lettre ",
               width=40,
               padx=40,
               pady=10,
               font=('calibri', 14),
               command=self.game1qpc).grid(sticky=W)
        #Fin Interface

        #Debut Interface Mathematiques
        self.mathf = Frame(self.master, padx=30, pady=30)
        Button(self.mathf,
               text=" Calcul Mental ",
               width=40,
               padx=40,
               pady=10,
               font=('calibri', 14),
               command=self.game2math).grid(sticky=W)
Beispiel #15
0
            break
        if result_user_change == 'yes':
            result_user_del = input(
                'Do you want to delete an user? type yes or no: ')

            if result_user_del == 'yes':
                result_user_delete = input(
                    'Type id of the user you want to delete: ')
                result = user_repository.user_delete(result_user_delete)

            result_user_in = input(
                'Do you want to add an user? type yes or no: ')
            if result_user_in == 'no':
                break
            if result_user_in == 'yes':
                user = User()
                book = Book()
                user.id = input('Type id of the user you want to add: ')
                user.name = input('Type name of the user you want to add: ')
                user.surename = input(
                    'Type surename of the user you want to add: ')
                user.login = input('Type login of the user you want to add: ')
                user.password = input(
                    'Type password of the user you want to add: ')
                user_repository.add_new_user(user)

                book.name_of_the_book = input(
                    'Type new book for the new user here: ')
                book.author = input('Type author for the book: ')

                book_repository.add_new_book(book)