-
-
Save svdberg/3121327 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main :: IO () | |
main = scotty 3000 app | |
app :: ScottyM () | |
app = do | |
get "/favicon.ico" $ html "ಠ_ಠ" | |
get "/:method" $ do | |
r <- request | |
rcon <- liftIO $ R.connect R.defaultConnectInfo {R.connectPort = R.UnixSocket "redis.sock"} | |
auth <- liftIO $ auth r rcon | |
unless (isJust auth) next | |
liftIO someCode | |
auth :: Request -> R.Connection -> IO (Maybe ByteString) | |
auth (Request {requestHeaders=h}) rcon = do | |
case [v | (k, v) <- h, k == "Authorization" ] of | |
[value] -> R.runRedis rcon $ check (decode value) | |
_ -> return Nothing | |
where | |
decode = BS.split ':' . decodeLenient . head . drop 1 . BS.split ' ' | |
check [login, pwd] = FA.checkAuth login pwd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment