class LoginFrame(wx.Frame):

    def __init__(self):
        super(LoginFrame, self).__init__()
        self.res = xrc.XmlResource('../view/login.xrc')
        self.user_controller = UserController()
        self.main_menu = None
        self.inicio_user = None
        self.frame = self.res.LoadFrame(None, 'LoginFrame')
        self.panel = xrc.XRCCTRL(self.frame, 'InicioPanel')
        self.username = xrc.XRCCTRL(self.frame, 'text_user')
        self.password = xrc.XRCCTRL(self.frame, 'text_pass')
        self.button = xrc.XRCCTRL(self.panel, 'sign_in')
        self.frame.Bind(wx.EVT_BUTTON, self.validate_user, self.button)
        self.open = xrc.XRCCTRL(self.panel, 'account')
        self.frame.Bind(wx.EVT_BUTTON, self.open_register, self.open)
        self.frame.Show()

    def open_register(self, evt):
        self.register = RegistroFrame()

    def validate_user(self, evt):
        username = self.username.GetValue()
        password = self.password.GetValue()

        if username and password:
            if self.user_controller.search_user(username, password):
                if username == '@gustavo15' and password == 'gustavo12345':
                    self.frame.Close()
                    self.main_menu = InicioFrame()

                else:
                    self.frame.Close()
                    user = self.user_controller.search_username(username)
                    if user is not False:
                        self.inicio_user = InicioUser(user=user, frame_father=self)

                    else:
                        wx.MessageBox('User is not valid', 'Error', wx.OK | wx.ICON_INFORMATION)

            else:
                wx.MessageBox('User does not exist', 'Error', wx.OK | wx.ICON_ERROR)

        else:
            wx.MessageBox('Fields not entered', 'Error', wx.OK | wx.ICON_ERROR)
Exemple #2
0
class LoginFrame(wx.Frame):
    def __init__(self, *args, **kw):
        super(LoginFrame, self).__init__(*args, **kw)
        self.xml = xrc.XmlResource('../View/Login.xml')
        self.frame = self.xml.LoadFrame(None, 'Login_Frame')
        self.panel = xrc.XRCCTRL(self.frame, 'Login_Panel')
        self.username = xrc.XRCCTRL(self.panel, 'Textctrl_Usuario')
        self.password = xrc.XRCCTRL(self.panel, 'Textctrl_Contrasena')
        self.button_ingresar = xrc.XRCCTRL(self.panel, 'wxID_OK')
        self.button_ccuenta = xrc.XRCCTRL(self.panel, 'wxID_CANCEL')
        self.frame.SetIcon(wx.Icon("../view/System_Images/icon.png"))
        self.frame.Bind(wx.EVT_BUTTON, self.validate_user,
                        self.button_ingresar)
        self.frame.Bind(wx.EVT_BUTTON, self.crear_cuenta, self.button_ccuenta)
        self.user_controller = UserController()
        self.admin_controller = AdminController()
        self.frame.Show()

    def validate_user(self, evt):
        username = self.username.GetValue()
        password = self.password.GetValue()

        if username and password:
            if self.user_controller.search_user(username, password):
                self.frame.Close()
                wx.MessageBox('Eres un Usuario', 'Error',
                              wx.OK | wx.ICON_ERROR)
            elif self.admin_controller.search_admin(username, password):
                self.frame.Close()
                self.menu_admin = MenuPrincipalAdministrador(username)

            else:
                wx.MessageBox('Datos incorrectos o usuario no registrado',
                              'Error', wx.OK | wx.ICON_ERROR)

        else:
            wx.MessageBox('Todos Los Campos Son Obligatorios', 'Error',
                          wx.OK | wx.ICON_ERROR)

    def crear_cuenta(self, evt):
        self.crear_cuenta = CrearCuentaUsuario()