Yesod.Auth.Email - 设置公共用户标识符

发布于 2024-11-28 11:25:07 字数 443 浏览 1 评论 0原文

我一直在通过使用 Yesod 来重建我的网站来学习它。我开始使用 yesod init 生成的代码。此代码使用 Yesod 自带的身份验证框架,包括 Yesod.Auth.Email,它允许您通过提供电子邮件地址来创建帐户。

我对默认代码的问题是:它将用户标识符设置为其电子邮件地址。如果标识符将在网站上公开使用(例如,识别页面/博客上的评论者),那么您需要用户不介意显示的内容来识别他们。

理想情况下,我希望网站在提交电子邮件地址时或单击链接验证帐户并输入密码时要求提供(唯一的)公共标识符。问题是,这似乎需要更改 Yesod 模块,因为注册/密码表单是在那里定义的。

我可以很容易地做出改变。但我真的不想继续分叉 Yesod 模块来让它们做我想让它们做的事情。是否有另一种方法可以使用现有的 yesod-auth 模块来做到这一点?这完全有可能用框架来完成,但如果是这样,一个小例子将不胜感激。

I've been learning Yesod by using it to rebuild my website. I started off using the code generated by yesod init. This code uses the authentication framework that comes with Yesod, including Yesod.Auth.Email, which allows you to create an account by providing an email address.

The problem I have with the default code is this: it sets the user identifier to their email address. If the identifier is going to be used publicly on the website (e.g. to identify commentators on a page / blog) then you need something which the user won't mind being displayed to identify them.

Ideally, I want the website to ask for a (unique) public identifier either at the point when they submit their email address, or when they click the link to validate the account and type in their password. The problem is that this would appear to require changes to Yesod modules, since the register / password forms are defined there.

I can make the changes easily enough. But I don't really want to keep forking Yesod modules to make them do what I want them to do. Is there another way to do this using the existing yesod-auth modules? It's entirely possible that this can be done with the framework as it is, but if so a small example would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心不设防 2024-12-05 11:25:07

我不确定您使用什么代码在网站上显示用户的身份,但您可以非常轻松地向用户表添加一列:

User
  ...
  publicIdentifier Text Update

并且在您的小村庄中只需插入变量:

#{userPublicIdentifier user}

I'm not sure what code you're using to show the user's identity on the website but you could very easily add a column to the user table:

User
  ...
  publicIdentifier Text Update

and in your hamlet just interpolate the variable:

#{userPublicIdentifier user}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文