reordered functions in UI module

This commit is contained in:
Jonathan Lamothe 2018-12-27 14:26:44 -05:00
parent 318079dca8
commit 0920bff2f5

View File

@ -88,6 +88,39 @@ viewEditMenu = menu "View/Edit Password"
, ( "cancel", mainMenu ) , ( "cancel", mainMenu )
] ]
changeMasterPass :: S.StateT Status IO ()
changeMasterPass = do
oldP <- S.gets $ view masterPass
newP <- req $ reqDefault getMasterPass oldP
S.modify $ set masterPass newP
mainMenu
lockSession :: S.StateT Status IO ()
lockSession = do
lift $ putStrLn "\nsession locked"
pass <- S.gets $ view masterPass
mx <- lift $ runRequest $ prompt "password: " reqPassword
case mx of
Nothing -> lockSession
Just x -> if x == pass
then mainMenu
else lockSession
quit :: S.StateT Status IO ()
quit = return ()
buildData :: S.StateT Status IO PWData
buildData = do
d <- run newPWData
req $ reqIf (confirm "would you like to change the default policy?")
(do
let p = d^.pwPolicy
p <- editPolicy p <|> do
reqIO $ putStrLn "invalid password policy - using default"
return p
return $ set pwPolicy p d)
(return d)
searchServ :: S.StateT Status IO () searchServ :: S.StateT Status IO ()
searchServ = do searchServ = do
svc <- req $ prompt "service name: " reqResp svc <- req $ prompt "service name: " reqResp
@ -132,27 +165,6 @@ changeSalt x = do
showPass x showPass x
servMenu x servMenu x
changeMasterPass :: S.StateT Status IO ()
changeMasterPass = do
oldP <- S.gets $ view masterPass
newP <- req $ reqDefault getMasterPass oldP
S.modify $ set masterPass newP
mainMenu
lockSession :: S.StateT Status IO ()
lockSession = do
lift $ putStrLn "\nsession locked"
pass <- S.gets $ view masterPass
mx <- lift $ runRequest $ prompt "password: " reqPassword
case mx of
Nothing -> lockSession
Just x -> if x == pass
then mainMenu
else lockSession
quit :: S.StateT Status IO ()
quit = return ()
showPass :: String -> S.StateT Status IO () showPass :: String -> S.StateT Status IO ()
showPass x = do showPass x = do
lift $ putStrLn "" lift $ putStrLn ""
@ -165,18 +177,6 @@ showPass x = do
Nothing -> "invalid password data" Nothing -> "invalid password data"
Just pw -> "password for " ++ x ++ ": " ++ pw Just pw -> "password for " ++ x ++ ": " ++ pw
buildData :: S.StateT Status IO PWData
buildData = do
d <- run newPWData
req $ reqIf (confirm "would you like to change the default policy?")
(do
let p = d^.pwPolicy
p <- editPolicy p <|> do
reqIO $ putStrLn "invalid password policy - using default"
return p
return $ set pwPolicy p d)
(return d)
-- TODO: refactor this monstrosity -- TODO: refactor this monstrosity
editPolicy :: PWPolicy -> Request PWPolicy editPolicy :: PWPolicy -> Request PWPolicy
editPolicy p = if validatePWPolicy p editPolicy p = if validatePWPolicy p