【问题标题】:Setting a Time-Zone breaks Devise Authenthication设置时区会破坏设备身份验证
【发布时间】:2016-07-27 18:07:49
【问题描述】:

我将 和devise-token-auth 一起使用。

我在我的用户模型中做了这个并且效果很好:

before_create :skip_confirmation!

# Include default devise modules.
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

我能够创建帐户,并自动确认。 对于其他内容,我需要通过将以下内容添加到我的 application.rb 来更改应用程序的时区。

config.time_zone = 'Europe/Berlin'
config.active_record.default_timezone = 'Europe/Berlin'

时区的东西也可以,但由于未知原因,创建用户停止了。如果我创建一个并尝试登录,则会出现此错误:

A confirmation email was sent to your account at '...'. You must follow the instructions in the email before your account can be activated

在使用新时区创建帐户后,在我的数据库中,用户记录的每个时间戳值都已正确插入(使用新时区)。

我该如何解决这个问题?

【问题讨论】:

    标签: ruby-on-rails-5 devise ruby-on-rails devise devise-confirmable


    【解决方案1】:

    我相信,出于某种原因,Devise 用于在users 表上设置confirmed_at 字段的时区早于“欧洲/柏林”时区。因此,当 Devise 检查 confirmed_at 是否设置为当前日期/时间之前的日期/时间时,它会返回 false。

    解决方案:尝试重新启动服务器以查看是否更新。

    更新

    我查看了Devise::Models 并看到以下代码:

      def skip_confirmation!
        self.confirmed_at = Time.now.utc
      end
    
      def confirmed?
        !!confirmed_at
      end
    

    这基本上让我相信最好在 UTC 中设置应用程序时间,然后使用像 Local Time 这样的 Gem 进行转换

    【讨论】:

    • 这没有帮助。我重新启动了整个服务器,该服务器也将“欧洲/柏林”作为时区。
    猜你喜欢
    • 2012-08-22
    • 1970-01-01
    • 1970-01-01
    • 2022-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-16
    • 2012-03-06
    相关资源
    最近更新 更多