我首先在一个域app.example.com
中创建了Rails应用,在另一个域www.example.com
中创建了静态站点。然后在rails应用程序中添加devise
gem,并在静态站点中创建一个登录表单。这是登录表单的代码:
<form action="app.example.com/users/sign_in" method="post">
<input name="utf8" type="hidden" value="✓">
Email:<input type="text" name="email" value="admin@gmail.com">
Password:<input type="password" name="password" value="password">
<input name="authenticity_token", value="", type="hidden">
<button>Submit</button>
</form>
从静态站点登录后,是否有可能重定向到Rails应用程序,因为它需要authenticity_token且很难在静态站点中生成authenticity_token,而且可能存在csrf
的问题。
答案 0 :(得分:0)
您可以通过子类化Devise::SessionsController
来禁用CSRF protection来执行此操作。
# app/controllers/my_sessions_controller.rb
class MySessionsController < Devise::SessionsController
skip_before_action :verify_authenticity_token, only: :create
end
请确保您更改了devise_for :users
中的config/routes.rb
呼叫:
devise_for :users, controllers: { sessions: 'my_sessions' }