Esempio n. 1
0
class PreferencesWidget(NUTWidget):

    def __init__(self, parent=0, *args, **kwargs):
        super(PreferencesWidget, self).__init__(parent=parent, *args, **kwargs)
        self.title = PageTitle(u"Modification des options")
        self.intro = PageIntro(u"Ci-dessous, des informations techniques " \
                               u"nécessaire au bon fonctionnement du système.\n" \
                               u"Modifiez les uniquement sur demande expresse" \
                               u"de la DRS ou du service technique.") 
        vbox = QtGui.QVBoxLayout()
        gridbox = QtGui.QGridLayout()
        vbox.addWidget(self.title)
        vbox.addWidget(self.intro)

        self.number_field = EnterTabbedLineEdit()
        self.number_field.setValidator(QtGui.QIntValidator(0, 99999999, self))
        self.number_field.setText(options.SRV_NUM)
        self.number_label = FormLabel(u"Numéro de téléphone du &serveur")
        self.number_label.setBuddy(self.number_field)
        self.number_error = ErrorLabel(u"")
        self.number_success = SuccessLabel(u"Les modifications ont bien été enregistrés.")
        self.number_success.setVisible(False)

        self.save_button = QtGui.QPushButton(u"&Enregistrer")
        self.save_button.setAutoDefault(True)
        self.save_button.clicked.connect(self.do_save)

        gridbox.addWidget(self.number_success, 0, 0)
        gridbox.addWidget(self.number_label, 1, 0)
        gridbox.addWidget(self.number_field, 1, 1)
        gridbox.addWidget(self.number_error, 1, 2)
        gridbox.addWidget(self.save_button, 3, 0)
        
        # adds stretched column + row at end to fill-up space
        gridbox.setColumnStretch(2, 1)
        gridbox.setRowStretch(5, 10)
        vbox.addLayout(gridbox)
        self.setLayout(vbox)
        # set focus to username field
        self.setFocusProxy(self.number_field)

    def is_complete(self):
        """ form has been completly filled or not. Sets error messages """        

        complete = True        

        # reset login error
        self.number_error.clear()    
        self.number_success.setVisible(False)    

        # username is required
        if not self.number_field.text():
            self.number_error.setText(u"Le numéro du serveur ne peut être vide.")
            complete = False
        else:
            self.number_error.clear()        

        return complete

    def do_save(self):
        """ calls login and adjust UI """

        number = unicode(self.number_field.text()).strip()

        # check completeness
        if not self.is_complete():
            return 

        try:
            options.update('SRV_NUM', number)
        except Exception as e:
            print(e)
            self.number_error.setText(u"Impossible d'enregistrer le numéro.")
        else:
            self.number_success.setVisible(True)

    @classmethod
    def require_logged_user(self):
        return False
Esempio n. 2
0
File: login.py Progetto: yeleman/nut
class LoginWidget(NUTWidget):

    title = u"Identification"

    def __init__(self, parent=0, *args, **kwargs):

        super(LoginWidget, self).__init__(parent=parent, *args, **kwargs)

        
        self.title = PageTitle(u"Identifiez vous!")
        self.intro = PageIntro(u"Vous devez vous identifier pour pouvoir "
                               u"utiliser le système.\n"
                               u"Si vous ne vous êtes jamais identifié, vous "
                               u"devrez procéder à une identification distante "
                               u"qui prendra environ 3mn.")

        vbox = QtGui.QVBoxLayout()
        gridbox = QtGui.QGridLayout()

        # page title
        vbox.addWidget(self.title)
        vbox.addWidget(self.intro)

        # username field
        self.username_field = EnterTabbedLineEdit()
        self.username_label = FormLabel(u"&Identifiant")
        self.username_label.setBuddy(self.username_field)
        self.username_error = ErrorLabel(u"")

        # password field
        self.password_field = EnterTabbedLineEdit()
        self.password_field.setEchoMode(QtGui.QLineEdit.PasswordEchoOnEdit)
        self.password_label = FormLabel(u"Mot de &passe")
        self.password_label.setBuddy(self.password_field)
        self.password_error = ErrorLabel(u"")

        # login button
        self.login_button = QtGui.QPushButton(u"&S'identifier")
        self.login_button.setAutoDefault(True)
        self.login_button.clicked.connect(self.do_login)

        # login error
        self.login_error = ErrorLabel("")

        # grid layout
        gridbox.addWidget(self.username_label, 0, 0)
        gridbox.addWidget(self.username_field, 0, 1)
        gridbox.addWidget(self.username_error, 0, 2)
        gridbox.addWidget(self.password_label, 1, 0)
        gridbox.addWidget(self.password_field, 1, 1)
        gridbox.addWidget(self.password_error, 1, 2)
        gridbox.addWidget(self.login_button, 2, 0)
        gridbox.addWidget(self.login_error, 3, 1)

        # adds stretched column + row at end to fill-up space
        gridbox.setColumnStretch(2, 1)
        gridbox.setRowStretch(5, 10)

        vbox.addLayout(gridbox)
        self.setLayout(vbox)

        # set focus to username field
        self.setFocusProxy(self.username_field)

    def default_focus(self):
        # direct focus to username field
        return self.username_field

    @classmethod
    def require_logged_user(self):
        return False

    def is_complete(self):
        """ form has been completly filled or not. Sets error messages """

        complete = True

        # reset login error
        self.login_error.clear()

        # username is required
        if not self.username_field.text():
            self.username_error.setText(u"L'identifiant est requis.")
            complete = False
        else:
            self.username_error.clear()

        # password is required
        if not self.password_field.text():
            self.password_error.setText(u"Le mot de passe est requis.")
            complete = False
        else:
            self.password_error.clear()
        return complete

    def do_login(self):
        """ calls login and adjust UI """

        username = unicode(self.username_field.text()).strip()
        password = unicode(self.password_field.text()).strip()

        # check completeness
        if not self.is_complete():
            return

        try:
            user = offline_login(username=username,
                                 password=password)
        except UsernameNotFound:
            # Username is not in database.
            # ask user whether to retype or perform remote login
            box = QtGui.QMessageBox.question(self, u"Êtes vous sûr?",
                    u"Vous avez tapé “%s” comme identifiant. "
                    u"Cet identifiant est inconnu sur cet ordinateur (ce qui"
                    u" est normal lors de la première identification).\n"
                    u"Voulez-vous re-saisir votre identifiant (annuler cette "
                    u"page) ou voulez-vous procéder à une identification "
                    u"distante ?\n\nContinuer avec une identification "
                    u"distante ?" % username,
                    QtGui.QMessageBox.Cancel | QtGui.QMessageBox.Yes, QtGui.QMessageBox.Yes)
            if box == QtGui.QMessageBox.Cancel:
                return
            else:
                # trigger online_login
                dialog = self.open_dialog(RemoteLogin,
                                          username=username,
                                          password=password)
                return

        if not user:
            self.login_error.setText(u"Le mot de passe fournis est erroné.")
            return

        # store User object to main window
        self.main_window._user = user

        # go to dashboard
        self.change_main_context(DashboardWidget)

    def process_event(self, event):
        if event.type == event.LOGIN_SUCCESS \
           or event.type == event.LOGIN_FAILED:
            box = QtGui.QMessageBox.information(self,
                        u"Identification réussie!",
                        u"Bravo!\nLe serveur vous a reconnu et a envoyé les "
                        u"informations relatives à vote centre de santé.\n"
                        u"À partir de maintenant, vous pouvez vous identifier "
                        u"directement avec cet identifiant.")
            event.discard()
            self.do_login()
Esempio n. 3
0
class SIMManagementWidget(NUTWidget):

    title = u"Gestion SIM"

    def __init__(self, parent=0, *args, **kwargs):

        super(SIMManagementWidget, self).__init__(parent=parent,
                                                  *args, **kwargs)

        self.title = PageTitle(u"Gestion de la carte SIM")
        self.intro = PageIntro(u"Afin de pouvoir transmettre les rapports par "
                               u"SMS, vous devez vérifier que la carte SIM "
                               u"du modem dispose de crédit.\n"
                               u"Indiquez l'opérateur de la carte SIM et le "
                               u"numéro de la carte de recharge.\n\n"
                               u"Vous pouvez aussi transférer du crédit sur "
                               u"le numéro de la carte SIM.")

        vbox = QtGui.QVBoxLayout()
        gridbox = QtGui.QGridLayout()

        # page title
        vbox.addWidget(self.title)
        vbox.addWidget(self.intro)

        # operator choice
        self.operator_field = QtGui.QComboBox(self)
        for operator in OPERATORS:
            self.operator_field.addItem(operator.get('name', u'?'))
        self.operator_label = FormLabel(u"&Opérateur")
        self.operator_label.setBuddy(self.operator_field)
        self.operator_error = ErrorLabel(u"")

        # balance button
        self.balance_button = QtGui.QPushButton(u"&Vérifier le solde")
        self.balance_button.setAutoDefault(True)
        self.balance_button.clicked.connect(self.do_balance)
        self.balance_button.setVisible(True)
        self.balance_label = FormLabel(u"&Crédit disponible")
        self.balance_label.setBuddy(self.balance_button)
        self.balance_response = ErrorLabel(u"")

        # card field
        self.card_field = EnterTabbedLineEdit()
        regexp = QtCore.QRegExp(u'\d{1,18}')
        self.card_field.setValidator(QtGui.QRegExpValidator(regexp, self))
        self.card_label = FormLabel(u"&Numéro de la carte")
        self.card_label.setBuddy(self.card_field)
        self.card_error = ErrorLabel(u"")

        # submit button
        self.send_button = QtGui.QPushButton(u"&Envoyer")
        self.send_button.setAutoDefault(False)
        self.send_button.clicked.connect(self.do_send)

        # submit error
        #self.send_response = ErrorLabel("")

        # progress bar is loading-animated (no progress)
        self.progress_bar = QtGui.QProgressBar()
        self.progress_bar.setMinimum(0)
        self.progress_bar.setMaximum(0)
        self.progress_bar.setValue(0)
        self.progress_bar.setVisible(False)

        self.progress_label = QtGui.QLabel(u"En attente de la réponse du " \
                                             u"serveur…")
        self.progress_label.setVisible(False)

        # grid layout
        gridbox.addWidget(self.balance_label, 0, 0)
        gridbox.addWidget(self.balance_button, 0, 1)
        gridbox.addWidget(self.balance_response, 0, 2)

        gridbox.addWidget(self.operator_label, 1, 0)
        gridbox.addWidget(self.operator_field, 1, 1)
        gridbox.addWidget(self.operator_error, 1, 2)
        gridbox.addWidget(self.card_label, 2, 0)
        gridbox.addWidget(self.card_field, 2, 1)
        gridbox.addWidget(self.card_error, 2, 2)
        gridbox.addWidget(self.send_button, 3, 1)
        #gridbox.addWidget(self.send_response, 4, 2)

        # adds stretched column + row at end to fill-up space
        gridbox.setColumnStretch(2, 1)
        gridbox.setRowStretch(5, 10)

        vbox.addLayout(gridbox)
        self.setLayout(vbox)

        # set focus to username field
        self.setFocusProxy(self.card_field)

    def display_balance(self, balance):
        self.balance_response.setText(balance)
        self.balance_response.setVisible(True)
    
    def hide_balance(self):
        self.balance_response.setVisible(False)

    def display_topup(self, topup):
        self.card_error.setText(topup)
        self.card_error.setVisible(True)
    
    def hide_topup(self):
        self.card_error.clear()
        
    def default_focus(self):
        # direct focus to username field
        return self.card_field

    @classmethod
    def require_logged_user(self):
        return False

    def do_balance(self):
        operator = OPERATORS[self.operator_field.currentIndex()]
        self.open_dialog(UssdDialog,
                         action='balance',
                         operator=operator,
                         peer=self)
        return

    def is_complete(self):
        """ form has been completly filled or not. Sets error messages """

        complete = True

        # reset send error
        #self.send_response.clear()

        # card number is required
        if not self.card_field.text():
            self.card_error.setText(u"Le numéro de carte de recharge"
                                    u" est requis.")
            complete = False
        else:
            self.card_error.clear()

        return complete

    def do_send(self):

        # check completeness
        if not self.is_complete():
            return

        operator = OPERATORS[self.operator_field.currentIndex()]
        card = int(self.card_field.text())
        
        self.open_dialog(UssdDialog,
                         action='topup',
                         operator=operator,
                         card=card,
                         peer=self)
        return