summaryrefslogtreecommitdiff
path: root/app_alphajob/main.py
blob: 11f4cc12c90b3c92b4e08ff8f9b04e737a81c5b2 (plain)
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


import sys
from os.path import join
from PyQt5 import QtWidgets, QtGui
from database import dbuser

class mainWindow(QtWidgets.QMainWindow):

    VERSION = 0.1
    
    def __init__(self):
        super(mainWindow, self).__init__()
        logo = join("./ressources", "icon.ico")
        self.setWindowIcon(QtGui.QIcon(logo))
        menu = self.menuBar()
        menu_options = menu.addMenu("Options")
        btn_apropos = QtWidgets.QAction("A propos", self)
        btn_apropos.triggered.connect(self.a_propos)
        menu_options.addAction(btn_apropos)
        self.setWindowTitle("Alphajob")
        self.home()

    def home(self):
        self.label1 = QtWidgets.QLabel("Home page")
        btn1 = QtWidgets.QPushButton("Aller à la page de connexion")
        btn1.clicked.connect(self.page_login)

        self.layoutMain = QtWidgets.QVBoxLayout()

        self.layoutMain.addWidget(self.label1)
        self.layoutMain.addWidget(btn1)

        if hasattr(self, "mainWidget"):
            self.mainWidget.deleteLater()
        self.mainWidget = QtWidgets.QWidget()
        self.mainWidget.setLayout(self.layoutMain)
        self.setCentralWidget(self.mainWidget)
        self.show()

    def page_login(self):
        btnAccueil = QtWidgets.QPushButton("Accueil")
        btnAccueil.clicked.connect(self.home)
        self.emailConnexion = QtWidgets.QLineEdit("Email")
        self.passwordConnexion = QtWidgets.QLineEdit("Password")
        btnConnexion = QtWidgets.QPushButton("Connexion")
        btnConnexion.clicked.connect(self.login)

        self.layoutMain = QtWidgets.QVBoxLayout()
        self.layoutNavigation = QtWidgets.QHBoxLayout()
        self.layoutPassword = QtWidgets.QHBoxLayout()
        self.layoutPasswordWidgets = QtWidgets.QVBoxLayout()

        self.layoutMain.addLayout(self.layoutNavigation)
        self.layoutNavigation.addWidget(btnAccueil)
        self.layoutNavigation.addStretch()

        self.layoutMain.addLayout(self.layoutPassword)
        self.layoutPassword.addStretch()
        self.layoutPassword.addLayout(self.layoutPasswordWidgets)
        self.layoutPassword.addStretch()

        self.layoutPasswordWidgets.addWidget(self.emailConnexion)
        self.layoutPasswordWidgets.addWidget(self.passwordConnexion)
        self.layoutPasswordWidgets.addWidget(btnConnexion)

        self.mainWidget.deleteLater()
        self.mainWidget = QtWidgets.QWidget()
        self.mainWidget.setLayout(self.layoutMain)
        self.setCentralWidget(self.mainWidget)

    def login(self):
        user = dbuser.DbUser()
        if user.check_exist_email(self.emailConnexion.text()):
            res = user.check_user_credential(
                    self.emailConnexion.text(),
                    self.passwordConnexion.text()
                )
            if res:
                QtWidgets.QMessageBox.information(                       
                        self,
                        "Connexion",
                        "Vous êtes connecté"
                    )
            else:
                QtWidgets.QMessageBox.warning(                       
                        self,
                        "Connexion",
                        "Mauvaise combinaison mail & mot de passe"
                    )
        else:
            QtWidgets.QMessageBox.warning(                       
                    self,
                    "Connexion",
                    "Mauvais email"
                )


    def a_propos(self):
        QtWidgets.QMessageBox.information(
            self,
            "A propos",
            "Logiciel pour mon dossier professionnel.\
            <br>Version: %s\
            <br>Auteur: Debulois Quentin\
            <br>Code source: \
            <a href='https://git.debulois.fr/'>git.debulois.fr/</a>" % self.VERSION
            )


if __name__ == "__main__":
    def main():
        """Démarrage de l'app
        """
        app = QtWidgets.QApplication(sys.argv)
        GUI = mainWindow()
        sys.exit(app.exec_())

    main()