Beispiel #1
0
 def auth_dialog(self, window):
     d = WindowModalDialog(window, _("Authorization"))
     vbox = QVBoxLayout(d)
     pw = AmountEdit(None, is_int=True)
     msg = _('Please enter your Google Authenticator code')
     vbox.addWidget(QLabel(msg))
     grid = QGridLayout()
     grid.setSpacing(8)
     grid.addWidget(QLabel(_('Code')), 1, 0)
     grid.addWidget(pw, 1, 1)
     vbox.addLayout(grid)
     msg = _(
         'If you have lost your second factor, you need to restore your wallet from seed in order to request a new code.'
     )
     label = QLabel(msg)
     label.setWordWrap(1)
     vbox.addWidget(label)
     vbox.addLayout(Buttons(CancelButton(d), OkButton(d)))
     if not d.exec_():
         return
     return pw.get_amount()
Beispiel #2
0
    def setup_google_auth(self, window, _id, otp_secret):
        vbox = QVBoxLayout()
        if otp_secret is not None:
            uri = "otpauth://totp/%s?secret=%s"%('trustedcoin.com', otp_secret)
            l = QLabel("Please scan the following QR code in Google Authenticator. You may as well use the following key: %s"%otp_secret)
            l.setWordWrap(True)
            vbox.addWidget(l)
            qrw = QRCodeWidget(uri)
            vbox.addWidget(qrw, 1)
            msg = _('Then, enter your Google Authenticator code:')
        else:
            label = QLabel("This wallet is already registered, but it was never authenticated. To finalize your registration, please enter your Google Authenticator Code. If you do not have this code, delete the wallet file and start a new registration")
            label.setWordWrap(1)
            vbox.addWidget(label)
            msg = _('Google Authenticator code:')

        hbox = QHBoxLayout()
        hbox.addWidget(WWLabel(msg))
        pw = AmountEdit(None, is_int = True)
        pw.setFocus(True)
        pw.setMaximumWidth(50)
        hbox.addWidget(pw)
        vbox.addLayout(hbox)

        def set_enabled():
            window.next_button.setEnabled(len(pw.text()) == 6)
        pw.textChanged.connect(set_enabled)

        while True:
            if not window.set_main_layout(vbox, next_enabled=False,
                                          raise_on_cancel=False):
                return False
            otp = pw.get_amount()
            try:
                server.auth(_id, otp)
                return True
            except:
                window.show_message(_('Incorrect password'))
                pw.setText('')
Beispiel #3
0
    def setup_google_auth(self, window, _id, otp_secret):
        vbox = QVBoxLayout()
        window.set_layout(vbox)
        if otp_secret is not None:
            uri = "otpauth://totp/%s?secret=%s"%('trustedcoin.com', otp_secret)
            vbox.addWidget(QLabel("Please scan this QR code in Google Authenticator."))
            qrw = QRCodeWidget(uri)
            vbox.addWidget(qrw, 1)
            msg = _('Then, enter your Google Authenticator code:')
        else:
            label = QLabel("This wallet is already registered, but it was never authenticated. To finalize your registration, please enter your Google Authenticator Code. If you do not have this code, delete the wallet file and start a new registration")
            label.setWordWrap(1)
            vbox.addWidget(label)
            msg = _('Google Authenticator code:')

        hbox = QHBoxLayout()
        hbox.addWidget(QLabel(msg))
        pw = AmountEdit(None, is_int = True)
        pw.setFocus(True)
        hbox.addWidget(pw)
        hbox.addStretch(1)
        vbox.addLayout(hbox)

        b = OkButton(window, _('Next'))
        b.setEnabled(False)
        vbox.addLayout(Buttons(CancelButton(window), b))
        pw.textChanged.connect(lambda: b.setEnabled(len(pw.text())==6))

        while True:
            if not window.exec_():
                return False
            otp = pw.get_amount()
            try:
                server.auth(_id, otp)
                return True
            except:
                window.show_message(_('Incorrect password'))
                pw.setText('')
Beispiel #4
0
    def add_fiat_edit(self):
        self.fiat_e = AmountEdit(self.fiat_unit)
        self.btc_e = self.win.amount_e
        grid = self.btc_e.parent()

        def fiat_changed():
            try:
                fiat_amount = Decimal(str(self.fiat_e.text()))
            except:
                self.btc_e.setText("")
                return
            exchange_rate = self.exchanger.exchange(Decimal("1.0"),
                                                    self.fiat_unit())
            if exchange_rate is not None:
                btc_amount = fiat_amount / exchange_rate
                self.btc_e.setAmount(int(btc_amount * Decimal(100000000)))
                self.btc_e.textEdited.emit("")

        self.fiat_e.textEdited.connect(fiat_changed)

        def btc_changed():
            btc_amount = self.btc_e.get_amount()
            if btc_amount is None:
                self.fiat_e.setText("")
                return
            fiat_amount = self.exchanger.exchange(
                Decimal(btc_amount) / Decimal(100000000), self.fiat_unit())
            if fiat_amount is not None:
                pos = self.fiat_e.cursorPosition()
                self.fiat_e.setText("%.2f" % fiat_amount)
                self.fiat_e.setCursorPosition(pos)

        self.btc_e.textEdited.connect(btc_changed)
        self.btc_e.frozen.connect(
            lambda: self.fiat_e.setFrozen(self.btc_e.isReadOnly()))
        self.win.send_grid.addWidget(self.fiat_e, 4, 3, Qt.AlignHCenter)
Beispiel #5
0
 def add_receive_edit(self):
     self.receive_fiat_e = AmountEdit(self.fiat_unit)
     btc_e = self.win.receive_amount_e
     self.connect_fields(btc_e, self.receive_fiat_e, None)
     self.win.receive_grid.addWidget(self.receive_fiat_e, 2, 3,
                                     Qt.AlignHCenter)