-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Manuel Leduc
committed
May 3, 2016
1 parent
0be4657
commit 53316d5
Showing
4 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
/.stack-work | ||
/dist | ||
/*.iml | ||
/out | ||
/.idea |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,11 @@ name: kreg | |
version: 0.1.0.0 | ||
synopsis: Initial project template from stack | ||
description: Please see README.md | ||
homepage: https://github.com/Daroth/kreg#readme | ||
homepage: https://github.com/manuelleduc/kreg-haskell#readme | ||
license: BSD3 | ||
license-file: LICENSE | ||
author: Daroth | ||
maintainer: [email protected] | ||
author: Manuel Leduc | ||
maintainer: [email protected] | ||
copyright: beerware | ||
category: draft | ||
build-type: Simple | ||
|
@@ -17,6 +17,10 @@ library | |
hs-source-dirs: src | ||
exposed-modules: Lib | ||
build-depends: base >= 4.7 && < 5 | ||
, wreq | ||
, http-client | ||
, aeson | ||
, lens | ||
default-language: Haskell2010 | ||
|
||
executable kreg-exe | ||
|
@@ -27,6 +31,7 @@ executable kreg-exe | |
, kreg | ||
, optparse-generic | ||
, haskeline | ||
|
||
default-language: Haskell2010 | ||
|
||
test-suite kreg-test | ||
|
@@ -40,4 +45,4 @@ test-suite kreg-test | |
|
||
source-repository head | ||
type: git | ||
location: https://github.com/Daroth/kreg | ||
location: https://github.com/manuelleduc/kreg-haskell |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,7 @@ module Lib | |
( someFunc | ||
) where | ||
|
||
import Registry.Client (auth) | ||
|
||
someFunc :: IO () | ||
someFunc = putStrLn "someFunc" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module Registry.Client (auth, AuthResponseBody(..)) where | ||
|
||
import GHC.Generics | ||
import Data.Aeson | ||
import qualified Network.Wreq as R | ||
import Control.Lens ((^?)) | ||
import Control.Exception as E | ||
import Network.HTTP.Client (HttpException(StatusCodeException)) | ||
|
||
data Auth = Auth { | ||
username :: String, | ||
password :: String, | ||
rememberMe :: Bool | ||
} deriving (Generic) | ||
|
||
data AuthResponseBody = AuthResponseBody { | ||
id_token :: String | ||
} deriving (Generic, Show) | ||
|
||
instance ToJSON Auth | ||
instance FromJSON AuthResponseBody | ||
|
||
baseUrlServer = "http://localhost:8080/" | ||
authenticateResource = baseUrlServer ++ "api/authenticate" | ||
|
||
--auth :: String -> String -> IO (Maybe AuthResponseBody) | ||
auth login password = | ||
let handler e@(StatusCodeException _ _ _) = return Nothing | ||
authObj = Auth login password False | ||
operations = do r <- R.post authenticateResource (toJSON authObj) | ||
(body :: R.Response AuthResponseBody) <- R.asJSON r | ||
return (body ^? R.responseBody) | ||
in operations `E.catch` handler |