implemented password changing

This commit is contained in:
Jonathan Lamothe 2018-12-26 15:43:13 -05:00
parent 0f6cbc0b24
commit 318079dca8
2 changed files with 19 additions and 3 deletions

View File

@ -116,9 +116,22 @@ servMenu x = menu x
editPassMenu :: String -> S.StateT Status IO () editPassMenu :: String -> S.StateT Status IO ()
editPassMenu x = menu (x ++ " : Edit Password") editPassMenu x = menu (x ++ " : Edit Password")
[ ( "cancel", servMenu x ) [ ( "generate new password", changeSalt x )
, ( "cancel", servMenu x )
] ]
changeSalt :: String -> S.StateT Status IO ()
changeSalt x = do
db <- S.gets $ view database
case pwGetService x db of
Nothing -> mainMenu
Just serv -> do
salt <- run newPWSalt
let serv' = set pwSalt salt serv
S.modify $ over database (pwSetService x serv')
showPass x
servMenu x
changeMasterPass :: S.StateT Status IO () changeMasterPass :: S.StateT Status IO ()
changeMasterPass = do changeMasterPass = do
oldP <- S.gets $ view masterPass oldP <- S.gets $ view masterPass
@ -154,7 +167,7 @@ showPass x = do
buildData :: S.StateT Status IO PWData buildData :: S.StateT Status IO PWData
buildData = do buildData = do
d <- S.StateT $ return . newPWData d <- run newPWData
req $ reqIf (confirm "would you like to change the default policy?") req $ reqIf (confirm "would you like to change the default policy?")
(do (do
let p = d^.pwPolicy let p = d^.pwPolicy

View File

@ -20,7 +20,7 @@ License along with this program. If not, see
-} -}
module Util (menu, req, tryReq, confirm) where module Util (menu, run, req, tryReq, confirm) where
import Control.Monad (join) import Control.Monad (join)
import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Class (lift)
@ -52,6 +52,9 @@ menuItem (str, x) = (str, return x)
reqState :: Request (S.StateT s IO a) -> S.StateT s IO a reqState :: Request (S.StateT s IO a) -> S.StateT s IO a
reqState = join . req reqState = join . req
run :: Monad m => (s -> (a, s)) -> S.StateT s m a
run f = S.StateT $ return . f
req :: Request a -> S.StateT s IO a req :: Request a -> S.StateT s IO a
req = lift . fmap fromJust . runRequest . required req = lift . fmap fromJust . runRequest . required