Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/authentication/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 如果登录失败或用户不存在,则使用Desive rails 3重定向到注册页面_Ruby On Rails 3_Authentication_Devise_Ruby On Rails 3.1_Warden - Fatal编程技术网

Ruby on rails 3 如果登录失败或用户不存在,则使用Desive rails 3重定向到注册页面

Ruby on rails 3 如果登录失败或用户不存在,则使用Desive rails 3重定向到注册页面,ruby-on-rails-3,authentication,devise,ruby-on-rails-3.1,warden,Ruby On Rails 3,Authentication,Devise,Ruby On Rails 3.1,Warden,最近我安装了gem'designe',“1.5.2”并尝试在用户不存在时将用户重定向到注册页/注册页。我尝试了多次更改路由,并使用if/else语句修改designe/sessions\u controller中的代码,如果用户身份验证失败,则重定向到注册页,但我想我遗漏了一些重要但简单的内容。我我在找一件像这样的东西 1。用户登录 1.1。如果user.authenticate!如果为true,则向他显示根路径(仪表板/索引) 其他的 重定向到注册/注册页面 我在Desive/sessions

最近我安装了
gem'designe',“1.5.2”
并尝试在用户不存在时将用户重定向到注册页/注册页。我尝试了多次更改路由,并使用if/else语句修改designe/sessions\u controller中的代码,如果用户身份验证失败,则重定向到注册页,但我想我遗漏了一些重要但简单的内容。我我在找一件像这样的东西

1。用户登录
1.1。如果user.authenticate!如果为true,则向他显示根路径(仪表板/索引) 其他的 重定向到注册/注册页面

我在Desive/sessions\u controller中做了许多更改,并创建了新的failure.rb,这样我可以重定向,但所有操作都失败了,我再次登录到同一页面,并显示了预期的flash消息。请帮我解决问题。

routes.rb

  as :user, do
    get '/users/sign_in' => 'devise/sessions#new'
    post '/users/sign_in' => 'devise/sessions#create'

    get '/users/change_password'    => 'devise/registrations#change_password'
    post 'users/update_password' =>  'devise/registrations#update_password'
    post '/users/password'  => 'devise/passwords#create'

    get '/users/password/edit'  => 'devise/passwords#edit'
    put '/users/password'  => 'devise/passwords#update'

  end
  devise_for :users, :controllers => { :"devise/omniauth_callbacks" => "devise/omniauth_callbacks", :confirmations => "devise/confirmations", :'users/sessions' => "sessions", :'devise/passwords' => "devise/passwords" ,
    :'devise/registrations' => "users/registrations"}
<%= form_for(resource_name, :url => users_sign_in_path) do |f| %>
  <div><%= f.label :email %><br />
  <%= f.email_field :email %></div>

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

  <% if devise_mapping.rememberable? -%>
    <div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
  <% end -%>

  <div><%= f.submit "Sign in" %></div>
<% end %>
class SessionsController < Devise::SessionsController

  prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
  prepend_before_filter :allow_params_authentication!, :only => :create
  include Devise::Controllers::InternalHelpers
  layout :false

def new
  p 'in new sessions controller------------------'
  resource = build_resource
    clean_up_passwords(resource)
    respond_with_navigational(resource, stub_options(resource)){ render_with_scope :new }

end


def create
  p "sessions create in sessions controller------
 ##tried to make many changes here using if else,but no result yet
  p params
  self.resource = warden.authenticate!(auth_options)
    set_flash_message(:notice, :signed_in) if is_navigational_format?
    sign_in(resource_name, resource)
    if !session[:return_to].blank?
      redirect_to session[:return_to]
      session[:return_to] = nil
    else
      respond_with resource, :location => after_sign_in_path_for(resource)
    end
  end
end
   config.authentication_keys = [ :email ]
app/views/designe/sessions/new.html.erb

  as :user, do
    get '/users/sign_in' => 'devise/sessions#new'
    post '/users/sign_in' => 'devise/sessions#create'

    get '/users/change_password'    => 'devise/registrations#change_password'
    post 'users/update_password' =>  'devise/registrations#update_password'
    post '/users/password'  => 'devise/passwords#create'

    get '/users/password/edit'  => 'devise/passwords#edit'
    put '/users/password'  => 'devise/passwords#update'

  end
  devise_for :users, :controllers => { :"devise/omniauth_callbacks" => "devise/omniauth_callbacks", :confirmations => "devise/confirmations", :'users/sessions' => "sessions", :'devise/passwords' => "devise/passwords" ,
    :'devise/registrations' => "users/registrations"}
<%= form_for(resource_name, :url => users_sign_in_path) do |f| %>
  <div><%= f.label :email %><br />
  <%= f.email_field :email %></div>

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

  <% if devise_mapping.rememberable? -%>
    <div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
  <% end -%>

  <div><%= f.submit "Sign in" %></div>
<% end %>
class SessionsController < Devise::SessionsController

  prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
  prepend_before_filter :allow_params_authentication!, :only => :create
  include Devise::Controllers::InternalHelpers
  layout :false

def new
  p 'in new sessions controller------------------'
  resource = build_resource
    clean_up_passwords(resource)
    respond_with_navigational(resource, stub_options(resource)){ render_with_scope :new }

end


def create
  p "sessions create in sessions controller------
 ##tried to make many changes here using if else,but no result yet
  p params
  self.resource = warden.authenticate!(auth_options)
    set_flash_message(:notice, :signed_in) if is_navigational_format?
    sign_in(resource_name, resource)
    if !session[:return_to].blank?
      redirect_to session[:return_to]
      session[:return_to] = nil
    else
      respond_with resource, :location => after_sign_in_path_for(resource)
    end
  end
end
   config.authentication_keys = [ :email ]

您描述的是Desive的默认行为。你根本不应该改变路线。。。谢谢@tyler,我更改了路由以设计用户,但在单击signin后,由于没有与[POST]“/sessions/user”匹配的路由,我得到了路由错误…有什么帮助吗???