2012-03-02 28 views
7

Tôi có một ứng dụng mà người dùng có thể đăng nhập vào tên miền phụ của công ty họ.đường ray 3.2 tên miền phụ và đưa ra

Tôi sử dụng thiết lập. Và mã này chuyển hướng người dùng tạo miền gốc tới tên miền phụ.

def after_sign_in_path_for(resource_or_scope) 
    scope = Devise::Mapping.find_scope!(resource_or_scope) 
    subdomain_name = current_user.firm.subdomain 
    if current_subdomain.nil? 
    # logout of root domain and login by token to subdomain 
    token = Devise.friendly_token 
    current_user.loginable_token = token 
    current_user.save 
    sign_out(current_user) 
    flash[:notice] = nil 
    home_path = valid_user_url(token, :subdomain => subdomain_name) 
    return home_path 
    else 
    if subdomain_name != current_subdomain.name 
     # user not part of current_subdomain 
     sign_out(current_user) 
     flash[:notice] = nil 
     flash[:alert] = "Sorry, invalid user or password for subdomain" 
    end 
    end 
    super 
end 

Nó hoạt động siêu trong chrome, firefox, opera và safari, nhưng nó không hoạt động trong IE9. Tôi không nhận được bất kỳ thông báo lỗi nào. Mẫu đăng nhập tôi thấy rằng người dùng được sigend trong và khi người dùng được chuyển hướng đến trang chủ anh/cô ấy là trái phép. Có ai có ý tưởng về những gì đang xảy ra không? Tạo nhật ký.

Processing by SessionsController#create as HTML 
Parameters: {"utf8"=>"✓", 
"authenticity_token"=>"JaffZi9f+Uyovuya8wR2u7LjG9w/3wdUDqTqONt/kFM=", 
"user"=>{"email 
"=>"[email protected]", "password"=>"[FILTERED]", "remember_me"=>"0"}, 
"commit"=>"Sign in"} 
User Load (0.0ms) SELECT "users".* FROM "users" WHERE 
"users"."email" = ''[email protected]' LIMIT 1 
(0.0ms) begin transaction 
(1.0ms) UPDATE "users" SET 
"last_sign_in_at" = '2012-03-02 20:46:06.658370', 
"current_sign_in_at" = '2012-03- 
02 20:56:29.481286', "sign_in_count" = 41, 
"updated_at" = '2012-03-02 20:56:29.482286' WHERE "users"."id" = 1 
[paperclip] Saving attachments. 
(62.0ms) commit transaction 
Firm Load (0.0ms) SELECT "firms".* FROM "firms" WHERE "firms"."id" = 1 LIMIT 1 
Firm Load (0.0ms) SELECT "firms".* FROM "firms" WHERE "firms"."subdomain" = 'den' LIMIT 1 
CACHE (0.0ms) SELECT "firms".* FROM "firms" WHERE "firms"."subdomain" = 'den' LIMIT 1 
Redirected to http://den.lvh.me:3000/ 
Completed 302 Found in 182ms (ActiveRecord: 0.0ms) 


Started GET "/" for 127.0.0.1 at 2012-03-02 21:56:29 +0100 
Processing by PrivateController#statistics as HTML 
Firm Load (0.0ms) SELECT "firms".* FROM "firms" WHERE "firms"."subdomain" = 'den' LIMIT 1 
Completed 401 Unauthorized in 2ms 


Started GET "https://stackoverflow.com/users/sign_in" for 127.0.0.1 at 2012-03-02 21:56:29 +0100 
Processing by SessionsController#new as HTML 
Rendered devise/_links.erb (2.0ms) 
Rendered devise/sessions/new.html.erb within layouts/registration (13.0ms) 
Completed 200 OK in 27ms (Views: 26.0ms | ActiveRecord: 0.0ms) 
+0

Bạn có nghĩ ra điều này không? – Kirk

+0

tên miền cookie của bạn là gì? IE có thể thiếu cookie ký tự đại diện? chủ đề này có thể giúp bạn trong trường hợp như vậy: [link] (http://stackoverflow.com/questions/4826670/rails-devise-setting-a-devise-cookie-to-persist-across-different-subdomains) – HungryCoder

+0

@Kirk Không, nhưng tôi nghĩ rằng liên kết của HungryCoder trông giống như nó có thể là sửa chữa. Không có thời gian để kiểm tra nó tại thời điểm –

Trả lời

0

Nếu bạn đang đi qua tên miền phụ, có thể tốt hơn là chỉ cần thay đổi cookie phiên của bạn thành tên miền chéo.

Chỉnh sửa tệp phiên cửa hàng.rb trong trình khởi tạo thực hiện việc này.

Babyreveal::Application.config.session_store :cookie_store, 
key: '_babyreveal_session', 
:domain => ".mybabyreveal.com" 

Lưu ý. tiền tố trên miền attribtue. Điều này cho phép cookie này có thể truy cập được trên các tên miền phụ và ứng dụng nên duy trì phiên của nó trên các tên miền phụ. Có thể không phải là 100% những gì bạn đang tìm kiếm nhưng nó sẽ giúp bạn đi đúng hướng.

Các vấn đề liên quan