-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use 'users' package #8
Comments
Yes, that's a great idea! Funblog is older than users (and has not been updated since), that why it does not use it yet. If you or anyone would like to give it a shot: go ahead :-) Otherwise I will look into it when I some time for that... |
Hm, I could take a stab as I was about to learn how to use Spock with some kind of authentication. However, I am beaten by cabal issues :) |
You could try using https://github.com/commercialhaskell/stack to skip aroud those issues ;) |
Well, I did start with stack. I see that blaze-bootstrap is not on stackage for example. |
You can add dependencies that are not on stackage to stack |
I think it's not there for a reason, there is an upper bound on blaze-html dependency...sorry, it's just I am not proficient at all in those things:) |
Ok, finally built it. Had to fiddle a bit with extra-deps (packages with extra-dep: true) in stack to use my locally built dependencies (as they had some upper bound problems). |
Not sure if I'm on the correct way, but I've run into some problems, so I'm looking for help. I've defined a helper: runUsers action =
runQuery $ \conn ->
let b = Users.Persistent (flip runSqlConn conn)
in action b Then I'm using it to register user, and it works fine. However, when trying to handle login: runUsers $ \b -> Users.authUser b (lr_user loginReq) (Users.PasswordPlain $ lr_password loginReq) 100 I receive Is this because of what I chose for |
What's the error? Are you running two queries in parallel? Can you maybe share all your code? |
Hi, my WIP changes are here: https://github.com/BartAdv/funblog/commit/8dc4c91093669289c58782a4cef22968ab6e1186 |
Hm, currently the tests for persistent run with sqlite, too, w/o a problem. (See https://github.com/agrafix/users/blob/767ebed500a6268826f8550c5e03b5b8223be82d/users-persistent/test/Spec.hs#L18 ). I'd love to look in to it in detail, but it will have to wait until the weekend. |
Is this still WIP? The repo by @BartAdv is now missing. |
I haven't investigated it further, I've forgot that repo had some stuff from me and I've removed it as I thought it's just a clean fork |
I'm currently using Spock together with Users. Maybe this will be useful. My state looks like this: data AppState = AppState { userBackend :: Persistent
} And I'm using this helper function: runUser :: (Persistent -> IO a) -> AppAction ctx foo a
runUser action = do
state <- getState
liftIO $ action (userBackend state) And I use it like this: -- Create a user
post ("users") $ do -- Create user
user <- jsonBody'
res <- runUser (\b -> createUser (b :: Persistent) (user :: User String))
case res of
Right id -> do
setStatus status200
text $ pack . show . fromSqlKey $ (id :: UserId Persistent)
Left err -> do
setStatus status500
text . pack . show $ err I don't know if that is the best way though. The functions in Users takes the backend as their first argument so using |
I think a good way to fix this would be to switch over to a monadic user interface holding the backend inside a reader. |
As in something similar to what Persistent does? What about simply moving the backend parameter to the end? |
Yes, like persistent. Moving the parameter to the end will make the interface akward if you run multiple actions in runUser? |
It's mentioned in Spock page in 'works great with' section, shouldn't it be used here?
The text was updated successfully, but these errors were encountered: