我一直在试图找出这2天。我通过电子邮件确认确认用户帐户(通过Devise)。我终于完成了所有这些工作,但重要的是要验证一个人拥有他们声称拥有的电子邮件。因此,每当用户更改电子邮件时,我都需要再次确认。设计 - 用户编辑电子邮件后确认
为了做到这一点,我创建了registrations_controller
并覆盖了update
方法。主要基于Devise的设计,但我检查是否需要根据更新发送确认。
# registrations_controller.rb
def update
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
send_confirmation = false
if params[:user][:email] != resource.email
send_confirmation = true
end
if resource.update_with_password(params[resource_name])
set_flash_message :notice, :updated if is_navigational_format?
sign_in resource_name, resource, :bypass => true
if send_confirmation
resource.update_attributes(:confirmed_at => nil, :confirmation_sent_at => nil)
resource.send_confirmation_instructions
end
respond_with resource, :location => after_update_path_for(resource)
else
clean_up_passwords(resource)
respond_with_navigational(resource){ render_with_scope :edit }
end
end
我的问题是我不知道在哪里能够改变它被重定向到哪里。我有一个页面,解释“已发送电子邮件以确认您的电子邮件”。但如果我试图在用户点击“更新帐户”后登录send_confirmation_instructions
之后登录(推送到登录屏幕),然后当他们通过电子邮件确认帐户时,他们被引导到我想要的页面给他们看。
我有一个自定义的守望者策略与它的一些看跌期权,我也写了图谋在放之前过滤:
# registrations_controller.rb
def authenticate_scope!
puts "RegistrationsController :: authenticate_scope!"
puts "action : #{params[:action]}"
super
end
所以看起来它试图对用户进行认证。日志内容如下:
...
Redirected to http://localhost:3000/users/edit
Completed 302 Found in 3537ms
RegistrationsController :: authenticate_scope!
action : edit
Started GET "https://stackoverflow.com/users/edit" for 127.0.0.1 at 2011-06-08 11:42:09 -0500
Processing by RegistrationsController#edit as HTML
User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = 19 LIMIT 1
Completed in 83ms
Warden::Strategies authenticate!
Warden::Strategies params: {"action"=>"new", "controller"=>"sessions"}
Started GET "https://stackoverflow.com/users/sign_in" for 127.0.0.1 at 2011-06-08 11:42:10 -0500
Processing by SessionsController#new as HTML
...
那么,我该如何控制它被重定向到哪里?我是否正确重置了“确认”属性?