Clase login:
Clase login
import sys
import time
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget
from PyQt5 import uic
import Con_pos
from Registro import Registro
class Login(QWidget):
def __init__(self):
QWidget.__init__(self)
uic.loadUi("Login.ui", self)
self.registro.clicked.connect(self.view_Registro)
self.ingresar.clicked.connect(self.autenticar)
def autenticar(self):
pid = self.getPID()
con = Con_pos.con_pos()
user = self.in_login.text()
password = self.in_pass.text()
print(password)
fecha = time.strftime("%X") + " " + time.strftime("%x")
if user != "" and password != "":
consulta = ''' SELECT "id_user" FROM "User" WHERE "id_user" = '%s' ; ''' %(user)
c_user = con.consulta(consulta)
print(c_user)
consulta = ''' SELECT "pass" FROM "User" WHERE "id_user" = '%s' ;''' %(user)
c_pass = con.consulta(consulta)
if c_user != None:
c_pass = c_pass[0]
print("test")
print(c_pass)
if c_pass == password:
consulta = ''' INSERT INTO "sesion" VALUES ('%s', '%s', '%s'); '''%(fecha ,pid, user)
con.insertar(consulta)
def getPID(self):
con = Con_pos.con_pos()
func = "pg_backend_pid"
pid = con.call_proc(func)
pid = pid[0][0]
return pid
def view_Registro(self):
pass
reg = Registro.Registro()
reg.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
login = Login()
login.show()
sys.exit(app.exec())
Clase Registro
Clase Registro:
import sys
import time
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5 import uic
import Con_pos
import error_log as error
class Registro(QMainWindow):
con = Con_pos.con_pos()
def __init__(self):
QMainWindow.__init__(self)
uic.loadUi("Registro.ui", self)
self.btn_reg.clicked.connect(self.validar_nombre)
def validar_nombre(self):
fecha = time.strftime("%X") + " " + time.strftime("%x")
usuario = self.user_tx_input.text()
password = self.pass_tx_input.text()
if usuario != "":
pid = self.getPID()
consul = '''SELECT "id_user" FROM "User" WHERE "id_user" = '%s'; ''' % (usuario)
res_con = Registro.con.consulta(consul)
if not res_con:
ins_user = '''INSERT INTO "User" VALUES ('%s', '%s') ''' % (usuario, password)
ins_sesion = ''' INSERT INTO "sesion" VALUES ('%s', %s,'%s') ''' % (fecha, pid, usuario)
Registro.con.insertar(ins_user)
Registro.con.insertar(ins_sesion)
else:
err = error.error_dia()
err.etiqueta.setText("El usuario %s ya esta en uso" % (usuario))
err.exec()
def getPID(self):
func = "pg_backend_pid"
pid = Registro.con.call_proc(func)
pid = pid[0][0]
return pid
if __name__ == "__main__":
app = QApplication(sys.argv)
ventana = Registro()
ventana.show()
sys.exit(app.exec())