Fwd: happstack-authenticate 2

12 views
Skip to first unread message

Corentin Dupont

unread,
Jul 26, 2015, 6:15:44 PM7/26/15
to ha...@googlegroups.com
Hello,
I'm trying to update my app to the new version of happstack-authenticate.
One question: is there a way to use this library without Javascript / AngularJS?

Thanks,
Corentin

Jeremy Shaw

unread,
Jul 26, 2015, 6:20:58 PM7/26/15
to HAppS
Yes and no.

A major goal of the new happstack-authenticate was to decouple the backend from the UI. So it is supposed to be possible to use the library with alternative UIs. That said, at the moment the only developed UI is the angularjs version.

Developing the new happstack-authenticate library was enough to make me first fall in love with, and then grow to hate angularjs. Now that GHCJS is a lot more mature, it would be great to redo the UI using a ghcjs based clientside library.

- jeremy

--
You received this message because you are subscribed to the Google Groups "HAppS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to happs+un...@googlegroups.com.
To post to this group, send email to ha...@googlegroups.com.
Visit this group at http://groups.google.com/group/happs.
For more options, visit https://groups.google.com/d/optout.

Corentin Dupont

unread,
Jul 27, 2015, 4:48:28 PM7/27/15
to Jeremy Shaw, ha...@googlegroups.com
I obtained good results by excluding acidAuth from the withAcid method.
Now I can see the login page but no fields are displayed!
I coded it like that:

loginPage :: Html
loginPage = do
  H.div $ p $ "Welcome to Nomyx!"
  H.div ! customAttribute "ng-controller" "UsernamePasswordCtrl" $ do
    H.div ! customAttribute "up-authenticated" "False" $ do
      h2 "Login"
      customLeaf (stringTag "up-login-inline") True
    H.div ! customAttribute "up-authenticated" "True" $ do
      h2 "Logout"
      p "You have successfully logged in! Click the link below to logout."
      customLeaf (stringTag "up-request-reset-password") True
    h2 "Create A New Account"
    customLeaf (stringTag "up-signup-password") True

The attributes and custom fields seems to be completely ignored.



On Mon, Jul 27, 2015 at 3:09 PM, Corentin Dupont <corenti...@gmail.com> wrote:
Hello,
thanks for the help.
I'm still struggling with the new way to authenticate.
In Clckwrk I could see:

data Acid = Acid
    { -- acidAuthenticate :: AcidState AuthenticateState
      acidProfileData  :: AcidState ProfileDataState
    , acidCore         :: AcidState CoreState
    , acidNavBar       :: AcidState NavBarState
    }


I have a similar structure:

data Profiles = Profiles
    { acidAuth        :: AcidState AuthenticateState,
    --  acidProfile     :: AcidState ProfileState,
      acidProfileData :: AcidState ProfileDataState}

I saw you commented acidAuthenticate. Should I remove it as well? I don't have a system of plugins like you have.

I have a withAcid function:

withAcid :: Maybe FilePath -- ^ state directory
         -> (Profiles -> IO a) -- ^ action
         -> IO a
withAcid mBasePath f = do
    let basePath = fromMaybe "_state" mBasePath
    bracket (openLocalStateFrom (basePath </> "auth")        initialAuthenticateState) createCheckpointAndClose $ \auth ->
  --  bracket (openLocalStateFrom (basePath </> "profile")     initialProfileState)     createCheckpointAndClose $ \profile ->
    bracket (openLocalStateFrom (basePath </> "profileData") initialProfileDataState)  createCheckpointAndClose $ \profileData ->
        f (Profiles
auth profileData)

I use withAcid in the main:

main = do
   ... 
   withAcid (Just $ saveDir </> profilesDir) $ \acid -> do
      tvSession <- atomically $ newTVar
acid
      forkIO $ launchWebServer tvSession (Network host port)



Then I access the state latter:

login ts = do
  (Profiles authenticateState _) <- liftIO $ atomically $ readTVar ts
  mUserId <- getUserId authenticateState


This seems to be the cause of the conflict seen before (state/authenticate/core/open.lock: Locked by 18674: resource busy).
Is it still the correct way to do?

Thanks,
C



On Mon, Jul 27, 2015 at 12:15 AM, Jeremy Shaw <jer...@seereason.com> wrote:
Hello,

Sorry there is not. Though it would be nice if there was :)

The rewrite is very significant. It is possible to migrate the old data though by using the migrate found here:

https://github.com/Happstack/happstack-authenticate-0

The aims of the new happstack-authenticate are to make it easier to:

 1. add alternative authentication backends (ldap, etc)
 2. write single page applications (aka, the server is just a JSON API, and all the rendering happens on the client)
 3. change the UI

At the moment, the only UI available requires angularjs. Well, this project was enough to make my first love and then hate angularjs. Fortunately, we now have ghcjs available! But, we do not have a definitive clientside haskell framework yet. Though we have two different ones in development at seereason at the moment :)

Regarding the issue in the other email -- I think your conclusion is correct. The issue with the .lock file would occur if you tried to open the same acid-state files twice, which would happen if you had two different version of happstack-authenticate in the same application.

Hopefully this helps some. Sorry the documentation is not better. Knowing that I want to redo the UI in haskell instead of angularjs makes me less inclined to write really good porting documentation. Especially with no real idea of how many people are actually using the old happstack-authenticate directly and want to upgrade.

- jeremy



On Wed, Jul 22, 2015 at 8:34 AM, Corentin Dupont <corenti...@gmail.com> wrote:
Hi again,
I'm trying to update to happstack-authenticate 2, is there a migration guide?
What are the essential differences?
Thanks,
Corentin



Corentin Dupont

unread,
Jul 27, 2015, 4:49:37 PM7/27/15
to Jeremy Shaw, ha...@googlegroups.com
PS. I use blaze-html instead of HSX.

Corentin Dupont

unread,
Aug 3, 2015, 7:02:06 AM8/3/15
to Jeremy Shaw, ha...@googlegroups.com, haskell
Hello,

I'm a bit confused about the routeAuthenticate and authenticateState bits in the new happstack-authenticate.

It seems that I have to do this in the beginning of my application:

(_, routeAuthenticate, authenticateState) <-
      liftIO $ initAuthentication Nothing (const $ return True)
        [ initPassword "http://localhost:8000/#resetPassword" "example.org"
        , initOpenId]


Where this should be done? In the main? If possible I'd prefer to delay it because my main is web-agnotic.
Where should I store those two values? Should I put them in my monad stack (I have a StateT)?
Is the routeAuthenticate really necessary? It looks a bit cumbersome to carry it around everywhere in the states.

Thanks,
Corentin
Reply all
Reply to author
Forward
0 new messages