I have a web project for a hobby. Very simple, just learn Haskell and web programming. For clarity, I use the Snap framework. And I have the following code (site.com/auth handler):
auth :: MonadSnap m => m ByteString
auth = withSession $ \s -> do
Just user <- getPostParam "user"
Just password <- getPostParam "password"
if user == "demi" && password == "1234"
then redirect "/"
else redirect "/login"
withSessionreads the current session and starts the function in the parameter. Here I encounter a problem: the user gets permission, and I want to put the new value into the session sand run the code with it. What is the best way to do this? How do you do this? Suppose the code below is also used s.
Another question: can I somehow make the context accessible transparently in the handler (for example auth) and other functions? I donβt want to pull the whole context (for example, a database connection, a session, and possibly another) in all functions with a type parameter ctx:
findGoodies :: MonadSnap m => MyContext -> String -> m String
checkCaptcha :: MonadSnap m => MyContext -> m Bool
breakingNews :: MonadSnap m => MyContext -> m ByteString
Ideally, I want to have a function withContext, but the context can be changed during request processing. I think I can decide that it defines my monad (right?), But I already need to use Monap Monap, and I canβt extend it (this is also a question)?
Hopefully I will say this quite clearly to help me.
source
share