Yesod auth:将用户重定向到注册页面 [英] Yesod auth: redirecting user to registration page

查看:162
本文介绍了Yesod auth:将用户重定向到注册页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用脚手架网站,我想在用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)

并在 HomeR 处理程序中检查UserId值,显示注册表单为零。

这种方法很有效,但看起来很骇人听闻。什么是处理这种问题的正确方法?

解决方案

我建议将信息分成两个实体:a 用户跟踪用户凭证的实体,以及包含注册信息的 Profile 实体。例如:

  User 
ident Text
UniqueUser ident
Profile
user UserId
displayName文本
UniqueProfile用户

getAuthId ,你可以返回一个现有的 UserId ,或者如果一个不存在,创建一个新的条目。在 HomeR 中,如果有 Profile ( getBy $ UniqueProfile uid ),如果没有,则显示注册表单。


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?

解决方案

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.

这篇关于Yesod auth:将用户重定向到注册页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆