Skip to content

Commit

Permalink
continued ui
Browse files Browse the repository at this point in the history
  • Loading branch information
jj-so committed May 14, 2024
1 parent 27d2a7d commit cb5c2a8
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 10 deletions.
72 changes: 70 additions & 2 deletions nitrokeyapp/settings_tab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from nitrokeyapp.device_data import DeviceData
from nitrokeyapp.qt_utils_mix_in import QtUtilsMixIn
from nitrokeyapp.worker import Worker
#from .data import pin_check

from .worker import SettingsWorker

Expand Down Expand Up @@ -57,6 +58,7 @@ def __init__(self, parent: Optional[QWidget] = None) -> None:

fido = QTreeWidgetItem(self.ui.settings_tree)
pintype = SettingsTabState.Fido
fido.setExpanded(False)
name = "FIDO2"
desc = "FIDO2 is an authentication standard that enables secure and passwordless access to online services. It uses public key cryptography to provide strong authentication and protect against phishing and other security threats."

Expand All @@ -80,6 +82,7 @@ def __init__(self, parent: Optional[QWidget] = None) -> None:

otp = QTreeWidgetItem(self.ui.settings_tree)
pintype = SettingsTabState.otp
otp.setExpanded(False)
name = "OTP"
desc = "One-Time Password (OTP) is a security mechanism that generates a unique password for each login session. This password is typically valid for only one login attempt or for a short period of time, adding an extra layer of security to the authentication process. OTPs are commonly used in two-factor authentication systems to verify the identity of users."

Expand All @@ -101,6 +104,10 @@ def __init__(self, parent: Optional[QWidget] = None) -> None:

self.ui.settings_tree.itemClicked.connect(self.show)

self.ui.current_password.textChanged.connect(self.check_credential)
self.ui.new_password.textChanged.connect(self.check_credential)
self.ui.repeat_password.textChanged.connect(self.check_credential)

self.reset()

def field_btn(self) -> None:
Expand All @@ -124,6 +131,15 @@ def field_btn(self) -> None:
self.show_repeat_password_check = self.ui.repeat_password.addAction(icon_check, loc)
self.show_repeat_password_false = self.ui.repeat_password.addAction(icon_false, loc)

self.action_current_password_show.setVisible(False)
self.action_new_password_show.setVisible(False)
self.action_repeat_password_show.setVisible(False)
self.show_current_password_check.setVisible(False)
self.show_current_password_false.setVisible(False)
self.show_repeat_password_check.setVisible(False)
self.show_repeat_password_false.setVisible(False)



# self.line_actions = [
# self.action_current_password_show,
Expand All @@ -134,13 +150,21 @@ def field_btn(self) -> None:
# ]

def show(self, item) -> None:
print("show")
pintype = item.data(1, 0)
if pintype == SettingsTabState.Fido or pintype == SettingsTabState.otp:
self.show_pin(item)
self.collapse_all_except(item)
item.setExpanded(True)
else:
self.edit_pin(item)

def collapse_all_except(self, item):
top_level_items = self.settings_tree.invisibleRootItem().takeChildren()
for top_level_item in top_level_items:
if top_level_item is not item.parent():
top_level_item.setExpanded(False)
self.settings_tree.invisibleRootItem().addChildren(top_level_items)


def show_pin(self, item) -> None:
self.ui.settings_empty.hide()
Expand All @@ -165,11 +189,15 @@ def edit_pin(self, item) -> None:
self.ui.pinsettings_desc.hide()
self.ui.pinsettings_edit.show()

self.ui.current_password.clear()
self.ui.new_password.clear()
self.ui.repeat_password.clear()

self.ui.btn_abort.show()
self.ui.btn_reset.show()
self.ui.btn_save.show()

self.ui.btn_abort.pressed.connect(lambda: self.show_pin(item))
self.ui.btn_abort.pressed.connect(lambda: self.abort(item))
self.ui.btn_save.pressed.connect(lambda: self.save_pin(item))
self.ui.btn_reset.pressed.connect(lambda: self.reset_pin(item))

Expand All @@ -179,6 +207,15 @@ def edit_pin(self, item) -> None:

self.field_btn()

def abort(self, item) -> None:
p_item = item.parent()
self.show(p_item)

# def reset(self) -> None:

# def save(self) -> None:


def act_current_password_show(self) -> None:
self.set_current_password_show(self.ui.current_password.echoMode() == QLineEdit.Password, ) # type: ignore [attr-defined]

Expand Down Expand Up @@ -248,3 +285,34 @@ def set_device_data(
self.ui.nk3_version.setText(version)
self.ui.nk3_variant.setText(variant)
self.ui.nk3_status.setText(init_status)

@Slot()
def check_credential(self) -> None:
current_password = self.ui.current_password.text()
new_password = self.ui.new_password.text()
repeat_password = self.ui.repeat_password.text()

if len(current_password) > 0:
self.action_current_password_show.setVisible(True)
else:
self.action_current_password_show.setVisible(False)

if len(new_password) > 0:
self.action_new_password_show.setVisible(True)
else:
self.action_new_password_show.setVisible(False)

if len(repeat_password) >0:
self.action_repeat_password_show.setVisible(True)
else:
self.action_repeat_password_show.setVisible(False)

if len(repeat_password) > 0 and new_password == repeat_password:
self.show_repeat_password_check.setVisible(True)
self.show_repeat_password_false.setVisible(False)
elif len(repeat_password) == 0 and len(new_password) == 0:
self.show_repeat_password_false.setVisible(False)
self.show_repeat_password_check.setVisible(False)
else:
self.show_repeat_password_false.setVisible(True)
self.show_repeat_password_check.setVisible(False)
28 changes: 22 additions & 6 deletions nitrokeyapp/settings_tab/data.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
from dataclasses import dataclass
from enum import Enum, auto, unique

@dataclass
class Pin:
id: bytes
pintype: Optional[item.data(1, 0)]
name: str
desc: str
from pynitrokey.nk3.secrets_app import SecretsApp, SelectResponse, CCIDInstruction

class pin_check:

def check(self) -> SelectResponse:
check = SecretsApp.select()
return check


# @classmethod
# def check(cls, CCID: CCIDInstruction) -> SelectResponse:
# SecretsApp.select(cls, CCID)

#@dataclass
#class Pin:
# id: bytes
# pintype: Optional[item.data(1, 0)]
# name: str
# desc: str

#cls, secrets: SelectResponse
4 changes: 2 additions & 2 deletions nitrokeyapp/ui/settings_tab.ui
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>1</number>
<number>2</number>
</property>
<widget class="QWidget" name="settings_empty">
<layout class="QGridLayout" name="gridLayout_2">
Expand Down Expand Up @@ -358,7 +358,7 @@
</sizepolicy>
</property>
<property name="echoMode">
<enum>QLineEdit::Normal</enum>
<enum>QLineEdit::Password</enum>
</property>
<property name="dragEnabled">
<bool>false</bool>
Expand Down

0 comments on commit cb5c2a8

Please sign in to comment.