设计sign_up忽略remember_me值

发布于 2024-12-04 21:18:41 字数 1524 浏览 0 评论 0原文

我刚刚开始使用 Devise。我有一个:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me
end

并且我已将我的sign_up视图更改为:

<h2>Sign up</h2>

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>

  <div><%= f.label :email %><%= f.email_field :email %></div>

  <div><%= f.label :password %><%= f.password_field :password %></div>

  <div><%= f.label :password_confirmation %><%= f.password_field :password_confirmation %></div>

  <div><%= f.label :contact_me %><%= f.check_box :contact_me %></div>

  <div><%= f.label :remember_me %><%= f.check_box :remember_me %></div>

  <div><%= f.submit "Sign up" %></div>
<% end %>

<%= render :partial => "devise/shared/links" %>

但是,检查POST响应,我可以在注册后看到在Cookie:中设置的remember_user_token,无论我是否勾选“记住我”或不勾选。有人知道这是为什么,以及如何阻止它吗?

相比之下,登录仅在勾选该框时才设置该 cookie,正如预期的那样。

I'm just getting started with Devise. I have a:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me
end

and I've altered my sign_up view to:

<h2>Sign up</h2>

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>

  <div><%= f.label :email %><%= f.email_field :email %></div>

  <div><%= f.label :password %><%= f.password_field :password %></div>

  <div><%= f.label :password_confirmation %><%= f.password_field :password_confirmation %></div>

  <div><%= f.label :contact_me %><%= f.check_box :contact_me %></div>

  <div><%= f.label :remember_me %><%= f.check_box :remember_me %></div>

  <div><%= f.submit "Sign up" %></div>
<% end %>

<%= render :partial => "devise/shared/links" %>

However, checking the POST response, I can see the remember_user_token set in Cookie: after sign-up whether I ticked "Remember me" or not. Anyone know why that is, and how to stop it?

By comparison, signing in only sets that cookie if the box is ticked, as expected.

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

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

发布评论

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

评论(1

甩你一脸翔 2024-12-11 21:18:41

我现在您正在使用 for_for,但我使用 form_tag ...这样的代码适用于我的项目:

.form
  = form_tag new_user_session_path do  
    = email_field_tag 'user[email]', nil, :placeholder => "Ваш e-mail", :required => true
    = password_field_tag 'user[password]', nil, :placeholder => "Ваш пароль", :required => true
    .submit-area
        = submit_tag "Вход", :class => "orange-button"
        = check_box_tag 'user[remember_me]', true
        .login-link
          Запомнить меня

所以该部分可以正常工作:

= check_box_tag 'user[remember_me]', true

I now that you are using for_for, but i use form_tag... Such code works on my project:

.form
  = form_tag new_user_session_path do  
    = email_field_tag 'user[email]', nil, :placeholder => "Ваш e-mail", :required => true
    = password_field_tag 'user[password]', nil, :placeholder => "Ваш пароль", :required => true
    .submit-area
        = submit_tag "Вход", :class => "orange-button"
        = check_box_tag 'user[remember_me]', true
        .login-link
          Запомнить меня

So that part will work fine:

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