Yesod auth:将用户重定向到注册页面

arr*_*owd 4 authentication haskell yesod

我正在玩脚手架网站,我希望在用户首次使用OpenID或Google帐户登录后将用户发送到注册页面.

我想出了这个:

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)
Run Code Online (Sandbox Code Playgroud)

HomeR处理程序中我检查UserId值,如果为零则显示注册表单.

这种方法有效,但似乎是hackish.处理这种问题的正确方法是什么?

Mic*_*man 7

我建议将信息分成两个实体:User跟踪用户凭据的Profile实体和包含注册信息的实体.例如:

User
    ident Text
    UniqueUser ident
Profile
    user UserId
    displayName Text
    UniqueProfile user
Run Code Online (Sandbox Code Playgroud)

getAuthId,您将返回现有的UserId,或者如果不存在,则创建一个新条目.在HomeR,你会得到如果有Profile(getBy $ UniqueProfile uid),如果没有,显示注册表格.