apps.common.request_pin: add at_least_once

This commit is contained in:
Jan Pochyla 2016-12-19 11:32:08 +01:00
parent 96ead03e03
commit 59feeed3cb
1 changed files with 5 additions and 4 deletions

View File

@ -78,12 +78,13 @@ async def request_pin_twice(session_id: int) -> str:
return pin_first return pin_first
async def protect_by_pin(session_id: int): async def protect_by_pin(session_id: int, at_least_once: bool=False):
from . import storage from . import storage
while storage.is_locked(): locked = storage.is_locked() or at_least_once
while locked:
pin = await request_pin(session_id) pin = await request_pin(session_id)
storage.unlock(pin, _render_pin_failure) locked = not storage.unlock(pin, _render_pin_failure)
def _render_pin_failure(sleep_ms: int): def _render_pin_failure(sleep_ms: int):
@ -99,7 +100,7 @@ def _get_code_and_label(code: int) -> str:
if code == PinMatrixRequestType.NewFirst: if code == PinMatrixRequestType.NewFirst:
label = 'Enter new PIN' label = 'Enter new PIN'
elif code == PinMatrixRequestType.NewSecond: elif code == PinMatrixRequestType.NewSecond:
label = 'Enter new PIN again' label = 'Enter PIN again'
else: # PinMatrixRequestType.Current else: # PinMatrixRequestType.Current
label = 'Enter PIN' label = 'Enter PIN'
return code, label return code, label