Skip to content
Browse files

So fancy

  • Loading branch information...
1 parent 8f3c884 commit bc92aa714113ec151e080bc34237bb39b5cf5ce9 @dzhus committed
Showing with 27 additions and 26 deletions.
  1. +27 −26 src/Main.hs
View
53 src/Main.hs
@@ -1,3 +1,5 @@
+{-# LANGUAGE UnicodeSyntax #-}
+
{-|
Command-line tool to manage 'Snap.Snaplet.Auth.AuthManager' database.
@@ -52,10 +54,10 @@ defaultOptions = Options
-- | Save new user in auth backend given user login and password
-mgrSaveUser :: IAuthBackend r =>
+mgrSaveUser :: IAuthBackend r
r
- -> (String, String)
- -> IO AuthUser
+ (String, String)
+ IO AuthUser
mgrSaveUser amgr (l, p) =
let
login = T.pack l
@@ -63,64 +65,63 @@ mgrSaveUser amgr (l, p) =
user' = defAuthUser{userLogin = login}
in
do
- user <- setPassword user' pass
+ user setPassword user' pass
save amgr user
-- | Try to delete user in auth backend given user login
-mgrDeleteUser :: IAuthBackend r => r -> String -> IO ()
+mgrDeleteUser :: IAuthBackend r r String IO ()
mgrDeleteUser amgr l =
let
login = T.pack l
in
do
- user <- lookupByLogin amgr login
+ user lookupByLogin amgr login
case user of
- Just found -> destroy amgr found
- Nothing -> ioError $ userError $
+ Just found destroy amgr found
+ Nothing ioError $ userError $
l ++ ": user not found"
main :: IO ()
main =
let
- options :: [OptDescr (Options -> Options)]
+ options :: [OptDescr (Options Options)]
options =
[
Option ['c'] ["create"]
- (NoArg $ \opts -> opts{optMode = Just Create})
+ (NoArg $ \opts opts{optMode = Just Create})
"Create new user"
, Option ['d'] ["delete"]
- (NoArg $ \opts -> opts{optMode = Just Delete})
+ (NoArg $ \opts opts{optMode = Just Delete})
"Delete user"
, Option ['u'] ["user", "name"]
- (ReqArg (\u opts -> opts{optLogin = Just u}) "USER")
+ (ReqArg (\u opts opts{optLogin = Just u}) "USER")
"User login"
, Option ['p'] ["password"]
- (ReqArg (\p opts -> opts{optPassword = Just p}) "PWD")
+ (ReqArg (\p opts opts{optPassword = Just p}) "PWD")
"User password"
, Option ['j'] ["json"]
- (ReqArg (\j opts -> opts{optJson = j}) "JSONFILE")
+ (ReqArg (\j opts opts{optJson = j}) "JSONFILE")
"JsonFile backend storage file"
]
in
do
-- Parse command-line args into Options opts
- getopts <- getOpt Permute options <$> getArgs
- opts <- case getopts of
- (o, _, []) -> return $ foldl (flip id) defaultOptions o
- (_, _, errs) -> ioError $ userError $
+ getopts getOpt Permute options <$> getArgs
+ opts case getopts of
+ (o, _, []) return $ foldl (flip id) defaultOptions o
+ (_, _, errs) ioError $ userError $
concat errs ++ usageInfo header options
- where header = "Usage: snap-auth-cli [OPTIONS]"
-- Load JSON database using file specified in -j
- amgr <- mkJsonAuthMgr (optJson opts)
-
+ amgr mkJsonAuthMgr (optJson opts)
+
-- Operate depending on mode selected
case (optMode opts, optLogin opts, optPassword opts) of
- (Nothing, _, _) -> ioError (userError "No operation mode selected")
- (_, Nothing, _) -> ioError $ userError "No user selected"
- (Just Delete, Just l, _) -> mgrDeleteUser amgr l
- (Just Create, Just l, Just p) -> mgrSaveUser amgr (l, p)
+ (Nothing, _, _) ioError (userError "No operation mode selected")
+ (_, Nothing, _) ioError $ userError "No user selected"
+ (Just Delete, Just l, _) mgrDeleteUser amgr l
+ (Just Create, Just l, Just p) mgrSaveUser amgr (l, p)
>> return ()
- (Just Create, _, Nothing) -> ioError $ userError "No password set"
+ (Just Create, _, Nothing) ioError $ userError "No password set"

0 comments on commit bc92aa7

Please sign in to comment.
Something went wrong with that request. Please try again.