Yesod auth: redirecting user to registration page

随声附和 提交于 2019-12-07 07:56:49

问题


I'm playing with scaffolded site and i want to send user to the registration page after he logged in for the first time with OpenID or Google Account.

I've came up with this:

getAuthId creds = runDB $ do
        x ←  getBy $ UniqueUser $ credsIdent creds
        case x of
            Just (Entity uid _) → return $ Just uid
            Nothing → do
                return $ Just $ Key (PersistInt64 0)

And in HomeR handler i check for UserId value, showing registration form in case of zero.

This approach works, but seems hackish. What is the proper way to deal with such problem?


回答1:


I would recommend splitting the information up into two entities: a User entity that tracks the user's credentials, and a Profile entity containing the registration information. For example:

User
    ident Text
    UniqueUser ident
Profile
    user UserId
    displayName Text
    UniqueProfile user

In getAuthId, you'll either return an existing UserId, or if one doesn't exist, create a new entry. In HomeR, you'll get if there's a Profile (getBy $ UniqueProfile uid), and if not, display the registration form.



来源:https://stackoverflow.com/questions/11760958/yesod-auth-redirecting-user-to-registration-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!