# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'login.ui'
#
# Created by: PyQt5 UI code generator 5.15.1
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
from info import Info_UI
from dialog2 import Dialog_UI
from table2 import Table_UI
from zeep import Client

client = Client(wsdl="http://127.0.0.1:8000/index.php/soap?wsdl")


class Login_UI(object):
    email = None

    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(400, 132)
        self.pushButton = QtWidgets.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(270, 20, 111, 51))
        font = QtGui.QFont()
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.pushButton.setFont(font)
        self.pushButton.setObjectName("pushButton")
        self.widget = QtWidgets.QWidget(Dialog)
        self.widget.setGeometry(QtCore.QRect(20, 20, 233, 54))
        self.widget.setObjectName("widget")
        self.gridLayout = QtWidgets.QGridLayout(self.widget)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
        self.gridLayout.setObjectName("gridLayout")
        self.label = QtWidgets.QLabel(self.widget)
        font = QtGui.QFont()
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
        self.lineEdit = QtWidgets.QLineEdit(self.widget)
        self.lineEdit.setObjectName("lineEdit")
        self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1)
        self.label_2 = QtWidgets.QLabel(self.widget)
        font = QtGui.QFont()
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
        self.lineEdit_2 = QtWidgets.QLineEdit(self.widget)
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.gridLayout.addWidget(self.lineEdit_2, 1, 1, 1, 1)

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)
        self.pushButton.clicked.connect(self.infoPage)

    def infoPage(self):
        # the info page
        email = self.lineEdit.text()
        mdp = self.lineEdit_2.text()
        response = client.service.authentificate(email, mdp)
        if response == "NOK":
            Dialog_UI.info = "Accés Refusé "
            self.Form = QtWidgets.QWidget()
            self.ui = Dialog_UI()
            self.ui.setupUi(self.Form)
            self.Form.show()
        else:
            mylist = list()
            Info_UI.emailUser = email
            self.Form = QtWidgets.QWidget()
            self.ui = Info_UI()
            self.ui.setupUi(self.Form)
            self.Form.show()
            listUser = client.service.list(Info_UI.emailUser)
            if listUser["_value_1"] == None:
                number_of_users = 0
            else:
                number_of_users = len(listUser["_value_1"])
            for i in range(0, number_of_users):
                mylist.append(
                    listUser["_value_1"][i]["_value_1"][0:4] + listUser["_value_1"][i]["_value_1"][4]["_value_1"])
            Table_UI.listOfUser = mylist

            Dialog.hide()

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
        self.pushButton.setText(_translate("Dialog", "LOGIN"))
        self.label.setText(_translate("Dialog", "Email"))
        self.label_2.setText(_translate("Dialog", "Password"))


if __name__ == "__main__":
    import sys

    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QDialog()
    ui = Login_UI()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())
