getAdminR :: Handler Html
getAdminR = do
    at <- (liftM2 (,) `on` lookupGetParam) "action" "target"
    case at of
        (Just "noapprove_user", Just u) -> setApprove u False >> redirect AdminR
        (Just "approve_user"  , Just u) -> setApprove u True  >> redirect AdminR
        (Just "update_media"  ,      _) -> giveUrlRenderer mempty
        (Just _,_)                      -> invalidArgs ["Unknown action!"]
        (     _,_)                      -> do
            (formWidget, encType) <- generateFormPost newboardForm
            let form = renderFormH $ myForm
                  MsgBoardCreate encType AdminR
                  formWidget (submitButtonI MsgBoardCreate) FormMissing

            users <- runDB $ selectList [] [Asc UserUsername]
            defaultLayout $ do
                navigation "Admin"
                setTitle "Adminstration"
                $(widgetFile "admin")
  where
    (disapprove, approve) = ("disapprove_user", "approve_user") :: (Text, Text)
    usert = ((,,) <$> userUsername
                  <*> userComment
                  <*> (\v -> if' (userValid v) disapprove approve)
            ) . entityVal

    setApprove name value = runDB $
        updateWhere [UserUsername ==. name] [UserValid =. value]
getAdminR :: Handler Html
getAdminR = do
    at <- (liftM2 (,) `on` lookupGetParam) "action" "target"
    case at of
        (Just "noapprove_user", Just u) -> setApprove u False >> redirect AdminR
        (Just "approve_user"  , Just u) -> setApprove u True  >> redirect AdminR
        (Just "update_media"  ,      _) -> giveUrlRenderer mempty
        (Just _,_)                      -> invalidArgs ["Unknown action!"]
        (     _,_)                      -> do
            (formWidget, encType) <- generateFormPost newboardForm
            let form = renderFormH $ myForm
                  MsgBoardCreate encType AdminR
                  formWidget (submitButtonI MsgBoardCreate) FormMissing

            users <- runDB $ selectList [] [Asc UserUsername]
            defaultLayout $ do
                navigation "Admin"
                setTitle "Adminstration"
                $(widgetFile "admin")
  where
    (disapprove, approve) = ("disapprove_user", "approve_user") :: (Text, Text)
    usert = ((,,) <$> userUsername
                  <*> userComment
                  <*> (\v -> if' (userValid v) disapprove approve)
            ) . entityVal

    setApprove name value = runDB $
        updateWhere [UserUsername ==. name] [UserValid =. value]
getAdminR = do
    at <- (liftM2 (,) `on` lookupGetParam) "action" "target"
    case at of
        (Just "noapprove_user", Just u) -> setApprove u False >> redirect AdminR
        (Just "approve_user"  , Just u) -> setApprove u True  >> redirect AdminR
        (Just "update_media"  ,      _) -> giveUrlRenderer mempty
        (Just _,_)                      -> invalidArgs ["Unknown action!"]
        (     _,_)                      -> do
            (formWidget, encType) <- generateFormPost newboardForm
            let form = renderFormH $ myForm
                  MsgBoardCreate encType AdminR
                  formWidget (submitButtonI MsgBoardCreate) FormMissing

            users <- runDB $ selectList [] [Asc UserUsername]
            defaultLayout $ do
                navigation "Admin"
                setTitle "Adminstration"
                $(widgetFile "admin")
  where
    (disapprove, approve) = ("disapprove_user", "approve_user") :: (Text, Text)
    usert = ((,,) <$> userUsername
                  <*> userComment
                  <*> (\v -> if' (userValid v) disapprove approve)
            ) . entityVal

    setApprove name value = runDB $
        updateWhere [UserUsername ==. name] [UserValid =. value]