设计注册确认 [英] Devise registration confirmation
问题描述
我在我的项目中拥有用户和管理员角色。我用Devise创建了我的身份验证。
在我的管理员角色中,我没有任何确认。在我的用户模型中,我有以下内容:
$ p $ devise:database_authenticatable,:confirmable,:recoverable,
:rememberable, :trackable,:validatable,:timeoutable,:regisable
#设置模型的可访问(或保护)属性
attr_accessible:email,:username,:prename,:surname,:phone, :street,:number,:location,
:password,:password_confirmation
比如:
class DeviseCreateUsers< ActiveRecord :: Migration
def self.up
create_table(:users)do | t |
t.database_authenticatable:null => false
t.confirmable
t.recoverable
t.rememberable
t.trackable
t.timeoutable
t.validateable
t.string :用户名
t.string:姓氏
t.string:姓氏
t.string:电话
t.string:街道
t.integer:电话号码
t.string:location
t.timestamps
end
$ b add_index:users,:email,:unique => true
add_index:users,:confirmation_token,:unique => true
add_index:users,:reset_password_token,:unique => true
add_index:users,:username,:unique => true
add_index:users,:prename,:unique => false
add_index:users,:surname,:unique => false
add_index:users,:phone,:unique => false
add_index:users,:street,:unique => false
add_index:users,:number,:unique => false
add_index:users,:location,:unique => false
end
def self.down
drop_table:users
end
end
在我的routes.rb中添加了以下语句:
map。 devise_for:admins
map.devise_for:users,:path_names => {:sign_up => register,:sign_in => login}
map.root:controller => main
用户注册后,我被重定向到控制器 如果我打开控制台,我会在日志中看到确认邮件文本,但我已经登录。我无法解释原因。有人有想法吗? 如果我从日志中复制确认标记并确认我的帐户,我可以登录,但如果我不确认,我也可以登录。 main
与闪光通知您已成功注册,并且已登录。但我不想登录,因为我还没有确认我的新用户帐户。
$ b
config.confirm_within = 2.days
如果将其设置为0,则应该得到期望的结果。
I have a User and an Admin role in my project. I created my authentication with Devise.
In my admin role I don't have any confirmation. In my User model I have the following:
devise :database_authenticatable, :confirmable, :recoverable,
:rememberable, :trackable, :validatable, :timeoutable, :registerable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :username, :prename, :surname, :phone, :street, :number, :location,
:password, :password_confirmation
My migration looks like:
class DeviseCreateUsers < ActiveRecord::Migration
def self.up
create_table(:users) do |t|
t.database_authenticatable :null => false
t.confirmable
t.recoverable
t.rememberable
t.trackable
t.timeoutable
t.validateable
t.string :username
t.string :prename
t.string :surname
t.string :phone
t.string :street
t.integer :number
t.string :location
t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :confirmation_token, :unique => true
add_index :users, :reset_password_token, :unique => true
add_index :users, :username, :unique => true
add_index :users, :prename, :unique => false
add_index :users, :surname, :unique => false
add_index :users, :phone, :unique => false
add_index :users, :street, :unique => false
add_index :users, :number, :unique => false
add_index :users, :location, :unique => false
end
def self.down
drop_table :users
end
end
In my routes.rb I added following statements:
map.devise_for :admins
map.devise_for :users, :path_names => { :sign_up => "register", :sign_in => "login" }
map.root :controller => "main"
After user registration I am redirected to the controller main
with the flash notice, "You have signed up successfully," and I am logged in. But I don´t want to be logged in, because I have not confirmed my new user account yet.
If I open the console I see in the logs the confirmation mail text, but I am already logged in. I can´t explain why. Does anyone have an idea?
If I copy out the confirmation-token from the logs and confirm my account, I can log in, but if I don´t confirm, I also can log in.
In config/initializers/devise.rb there is a line to set the amount of time a user has to confirm before they're locked out.
config.confirm_within = 2.days
If you set that to 0, you should get the desired outcome.
这篇关于设计注册确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!