나는 Ryan Boland's excellent Rails multitenancy tutorial을 따르고 있지만, devise_invitable과 관련되어 있습니다. 나는 레일 4의 devise_invitable 초대 토큰이 유효하지 않습니다.
Rails 4.1.5
devise 3.3.0
devise_invitable 1.3.6
Postgresql
내가 선택한 하위 도메인에 나는 사용자 초대가 잘 보낼 수있는 (mysubdomain.lvh.me:3000를) 새 계정 및 사용자/계정 소유자를 만들 ... 사용하고 있습니다. 시크릿 크롬 세션에서 초대 링크를 열어 로그인하지 않았거나 현재 세션이 있는지 확인합니다. 초대 링크를 클릭하면 로그인 페이지 (mysubdomain.lvh.me:3000/users/sign_in)로 리디렉션되고 플래시 알림이 표시됩니다 : "제공된 초대 토큰이 유효하지 않습니다!"
나는, 당신이 볼 수 있듯이
<%= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @token) %>
, 나는 @token의 사용을 보장 ... 아주 간단한 메일러보기 (응용 프로그램/뷰/궁리/우편물/invitation_instructions.html.erb)를 사용하고 있습니다 here.
초대장을 생성하면, 나는 초대 토큰 (- d1801fd8df78bd8cd125d5d8091fdc6a72c8f8faf4136cb282d497ec612195e9 [email protected]이 경우) 데이터베이스에 저장됩니다 확인했다. 수락 요청시 초대장 조회시 토큰과 일치하는지 확인했습니다 (아래 추적 참조). 그래도 가입을 마치지 않고 사용자 로그인 페이지로 리디렉션되며 추적 로그에 "필터 체인 중지됨 : resource_from_invitation_token 렌더링 또는 리디렉션"이 표시됩니다. 이 거래 후 사용자는 최종적으로 확정되지 않습니다.나를 위해 잘못 될 수있는 것에 대한 아이디어가 있습니까? 나는 여기에
초대 생성을위한 추적 로그는 ... 로그, 내 응용 프로그램 컨트롤러, 그리고 아래에있는 내 유증의 설정을 포함하고있다 : 여기Started POST "https://stackoverflow.com/users/invitation" for 127.0.0.1 at 2014-09-07 01:28:33 +0800
Processing by Devise::InvitationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"BiIQ95wwdQz3CJ0+OoLOE9xHHvxhloHsRHrxsqf1D2Q=", "user"=>{"email"=>"[email protected]"}, "commit"=>"Invite User"}
User Load (4.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
Account Load (0.4ms) SELECT "public"."accounts".* FROM "public"."accounts" WHERE "public"."accounts"."subdomain" = 'mysubdomain' LIMIT 1
User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."email" = '[email protected]' ORDER BY "users"."id" ASC LIMIT 1
User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."invitation_token" = 'd1801fd8df78bd8cd125d5d8091fdc6a72c8f8faf4136cb282d497ec612195e9' ORDER BY "users"."id" ASC LIMIT 1
(0.1ms) BEGIN
SQL (0.5ms) INSERT INTO "users" ("created_at", "email", "invitation_created_at", "invitation_sent_at", "invitation_token", "invited_by_id", "invited_by_type", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id" [["created_at", "2014-09-06 17:28:34.296123"], ["email", "[email protected]"], ["invitation_created_at", "2014-09-06 17:28:34.294987"], ["invitation_sent_at", "2014-09-06 17:28:34.294987"], ["invitation_token", "d1801fd8df78bd8cd125d5d8091fdc6a72c8f8faf4136cb282d497ec612195e9"], ["invited_by_id", 1], ["invited_by_type", "User"], ["updated_at", "2014-09-06 17:28:34.296123"]]
(2.2ms) COMMIT
Rendered devise/mailer/invitation_instructions.html.erb (1.3ms)
Devise::Mailer#invitation_instructions: processed outbound mail in 23.5ms
Sent mail to [email protected] (26.0ms)
Date: Sun, 07 Sep 2014 01:28:34 +0800
From: [email protected]
Reply-To: [email protected]
To: [email protected]
Message-ID: <...>
Subject: Invitation instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<a href="http://mysubdomain.lvh.me:3000/users/invitation/accept?invitation_token=3GXDmi7NntDRdhvo57q5">Accept invitation</a>
Redirected to http://mysubdomain.lvh.me:3000/users
Completed 302 Found in 888ms (ActiveRecord: 10.0ms)
가 초대 링크를 따라 추적입니다 ... 여기
Started GET "https://stackoverflow.com/users/invitation/accept?invitation_token=3GXDmi7NntDRdhvo57q5" for 127.0.0.1 at 2014-09-07 01:28:38 +0800
Processing by Devise::InvitationsController#edit as HTML
Parameters: {"invitation_token"=>"3GXDmi7NntDRdhvo57q5"}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."invitation_token" = 'd1801fd8df78bd8cd125d5d8091fdc6a72c8f8faf4136cb282d497ec612195e9' ORDER BY "users"."id" ASC LIMIT 1
Redirected to http://mysubdomain.lvh.me:3000/users/sign_in
Filter chain halted as :resource_from_invitation_token rendered or redirected
Completed 302 Found in 5ms (ActiveRecord: 0.6ms)
Started GET "https://stackoverflow.com/users/sign_in" for 127.0.0.1 at 2014-09-07 01:28:38 +0800
Processing by Devise::SessionsController#new as HTML
Account Load (0.4ms) SELECT "public"."accounts".* FROM "public"."accounts" WHERE "public"."accounts"."subdomain" = 'mysubdomain' LIMIT 1
Rendered devise/shared/_links.erb (0.7ms)
Rendered devise/sessions/new.html.erb within layouts/application (4.4ms)
Completed 200 OK in 21ms (Views: 16.6ms | ActiveRecord: 1.3ms)
좋은 측정을위한 내 application_controller입니다 ...
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :load_schema, :authenticate_user!, :set_mailer_host
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:first_name, :last_name, :company, :email, :password, :password_confirmation, :remember_me, :image, :image_cache)}
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:first_name, :last_name, :company, :email, :password_confirmation, :current_password, :image, :image_cache)}
end
private
def load_schema
Apartment::Database.switch('public')
return unless request.subdomain.present?
if current_account
Apartment::Database.switch(current_account.subdomain)
else
redirect_to root_url(subdomain: false)
end
end
def current_account
@current_account ||= Account.find_by(subdomain: request.subdomain)
end
helper_method :current_account
def set_mailer_host
subdomain = current_account ? "#{current_account.subdomain}." : ""
ActionMailer::Base.default_url_options[:host] = "#{subdomain}lvh.me:3000"
end
def after_sign_out_path_for(resource_or_scope)
new_user_session_path
end
def after_invite_path_for(resource)
users_path
end
end
여기 내 고안 초기화 (설정/초기화/devise.rb), 난이 도움이되지만 아무 소용에 있는지 확인하기 위해 "config.allow_insecure_token_lookup = true"로 라인을 추가 한 ... 나는 '
Devise.setup do |config|
config.mailer_sender = '[email protected]'
require 'devise/orm/active_record'
config.case_insensitive_keys = [ :email ]
config.strip_whitespace_keys = [ :email ]
config.skip_session_storage = [:http_auth]
config.stretches = Rails.env.test? ? 1 : 10
config.reconfirmable = true
config.expire_all_remember_me_on_sign_out = true
config.password_length = 8..128
config.sign_out_via = :delete
config.allow_insecure_token_lookup = true
end