新手问题 如何配置 Devise,使得注册后,发送确认邮件并登录?

diguage · February 27, 2014 · Last by syj121 replied at May 10, 2017 · 4511 hits

打开 Devise 的确认模块,注册后,会发送确认邮件,但是并不登录。

如何配置 Devise,使得注册后,发送确认邮件,并且网站也是登录状态?

记得有一个参数可设置,不需要 confirm 也能登录的,这样验证邮件没完成验证,用户也可以登录。具体名字忘记了。

这个需求好奇怪?如果直接登录,为什么还要确认邮件?

#2 楼 @Magic 为了确认邮件地址是他本人的(防止输错,或者冒用其他人邮件地址)

先不说需求,直接说实现:那你就关闭 Devise 的邮件确认,在 User Model 里 after_create 时候调用 Devise 的邮件发送方法就好了。

#3 楼 @libuchao 那如何邮件不确认呢?下次不能登录么?

噢 忘了说一点,不要同步发邮件,邮件发送最好异步。

#5 楼 @Magic 是啊,很多互联网服务都是这么做的啊,虽说有些繁琐,但是为了保证数据正确也无可厚非

打开 devise 的 confirmable 模块就好了

开启 confirmable devise :database_authenticatable, .... :confirmable

# ==> Configuration for :confirmable
  # A period that the user is allowed to access the website even without
  # confirming his account. For instance, if set to 2.days, the user will be
  # able to access the website for two days without confirming his account,
  # access will be blocked just in the third day. Default is 0.days, meaning
  # the user cannot access the website without confirming his account.
  config.allow_unconfirmed_access_for = nil #2.days

#9 楼 原来 Devise 默认支持这功能,@miclle 的解决方案好!

我设置,用户注册成功后,会发送邮件进行确认,邮件确认后才能登陆。但是邮件一直发送不成功,想知道怎么回事,也没有报错提示。就是邮箱收不到邮件。

You need to Sign in before reply, if you don't have an account, please Sign up first.