implemented service renaming
This commit is contained in:
parent
8b71454445
commit
f686fb7412
38
app/UI.hs
38
app/UI.hs
|
@ -70,20 +70,19 @@ mainMenu =
|
|||
addPassword :: S.StateT Status IO ()
|
||||
addPassword = do
|
||||
svc <- req $ prompt "service name: " reqResp
|
||||
db <- S.gets $ view database
|
||||
if pwHasService svc db
|
||||
then do
|
||||
ifServExists svc
|
||||
(do
|
||||
edit <- req (confirm $
|
||||
"The service already exists in the database.\n" ++
|
||||
"Would you like to edit it?")
|
||||
if edit
|
||||
then servMenu svc
|
||||
else mainMenu
|
||||
else do
|
||||
else mainMenu)
|
||||
(do
|
||||
d <- buildData
|
||||
setService svc d
|
||||
showPass svc
|
||||
servMenu svc
|
||||
servMenu svc)
|
||||
|
||||
viewEditMenu :: S.StateT Status IO ()
|
||||
viewEditMenu = menu "View/Edit Password"
|
||||
|
@ -145,6 +144,7 @@ servMenu x = menu x
|
|||
[ ( "show password", showPass x >> servMenu x )
|
||||
, ( "edit password", editPassMenu x )
|
||||
, ( "remove service", removeServ x )
|
||||
, ( "rename service", renameServ x )
|
||||
, ( "back", mainMenu )
|
||||
]
|
||||
|
||||
|
@ -161,10 +161,34 @@ removeServ x = do
|
|||
"Are you sure you want to delete the password for " ++ x ++ "?"
|
||||
if go
|
||||
then do
|
||||
S.modify $ over database $ pwRemoveService x
|
||||
removeServ' x
|
||||
mainMenu
|
||||
else servMenu x
|
||||
|
||||
removeServ' :: String -> S.StateT Status IO ()
|
||||
removeServ' = S.modify . over database . pwRemoveService
|
||||
|
||||
renameServ :: String -> S.StateT Status IO ()
|
||||
renameServ x = do
|
||||
y <- req $ prompt "new service name: " reqResp
|
||||
if x == y
|
||||
then servMenu x
|
||||
else ifServExists y
|
||||
(do
|
||||
overwrite <- req $ confirm $
|
||||
y ++ " already exists.\n" ++
|
||||
"Would you like to overwrite it?"
|
||||
if overwrite
|
||||
then renameServ' x y
|
||||
else servMenu x)
|
||||
(renameServ' x y)
|
||||
|
||||
renameServ' :: String -> String -> S.StateT Status IO ()
|
||||
renameServ' x y = withService x mainMenu $ \d -> do
|
||||
removeServ' x
|
||||
setService y d
|
||||
servMenu y
|
||||
|
||||
changeSalt :: String -> S.StateT Status IO ()
|
||||
changeSalt x = withService x mainMenu $ \d -> do
|
||||
salt <- run newPWSalt
|
||||
|
|
12
app/Util.hs
12
app/Util.hs
|
@ -24,6 +24,7 @@ module Util
|
|||
( menu
|
||||
, run
|
||||
, withService
|
||||
, ifServExists
|
||||
, setService
|
||||
, req
|
||||
, tryReq
|
||||
|
@ -82,6 +83,17 @@ withService srv fb act = do
|
|||
Nothing -> fb
|
||||
Just x -> act x
|
||||
|
||||
ifServExists
|
||||
:: String
|
||||
-> S.StateT Status IO a
|
||||
-> S.StateT Status IO a
|
||||
-> S.StateT Status IO a
|
||||
ifServExists s x y = do
|
||||
db <- S.gets $ view database
|
||||
if pwHasService s db
|
||||
then x
|
||||
else y
|
||||
|
||||
setService :: String -> PWData -> S.StateT Status IO ()
|
||||
setService k = S.modify . over database . pwSetService k
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user