How to make Authlogic sessions for all subdomains

When a user logs in to my site at example.com, I want him to log in when he visits something.example.com. How can i do this? (I use subdomain-fu if necessary)

+3
source share
3 answers

The fix is ​​to add this to production.rb:

if config.action_controller.session
  config.action_controller.session[:domain] = '.your-site.com'
else
  config.action_controller.session = { :domain => '.your-site.com' }
end

I still can't get it to work in development with localhost:3000, but no matter what

0
source

Well, you can simply add the following lines to / etc / hosts after "127.0.0.1 localhost"

127.0.0.1 localhost.com
127.0.0.1 sub.localhost.com

Then edit the /development.rb environment and add

config.action_controller.session = { :domain => '.localhost.com' }

http://localhost.com:3000 , , .

[update] oops, Horace Loeb

+2

Rails3 NoMethodError:

undefined method `session=' for ActionController::Base:Class

, Rails3 , app/config/initializers/session_store.rb :

YourAppName::Application.config.session_store :active_record_store,
    {:key => '_your_namespace_session', :domain => '.yourdomain.com'}

-, .

, , , , :

destroy
  current_user_session.destroy
  flash[:notice] = "You have been logged out"
  redirect_to root_path
end

- user_credentials cookie - yourdomain.com . cookies.delete :user_credentials destroy, :

destroy
  current_user_session.destroy
  cookies.delete :user_credentials
  flash[:notice] = "You have been logged out"
  redirect_to root_path
end

, , cookies[:user_credentials].is_nil? == true. , , , cookies.delete :user_credentials destroy, , . - ?

Update. , - User :

class AddReloginedToUsers < ActiveRecord::Migration
  def change
    add_column :users, :relogined, :boolean, :default => false
  end
end

:

def destroy
  current_user_session.destroy
  if !current_user.relogined
    current_user.relogined = true
    current_user.save
    cookies.delete(:user_credentials)
  end
  session = nil
  flash[:notice] = "You have been logged out"
  redirect_to root_path
end

, , . , - - .

+1

Source: https://habr.com/ru/post/1752349/


All Articles