Ruby on rails 为什么我的用户从Paypal付款返回时没有登录?
用户注册帐户后,他们将自动登录 然后他们可以选择“激活他们的帐户”来解锁应用程序的功能。帐户激活将引导他们进入Paypal网关。成功完成付款后,它们将重定向回发票页面。但是,发票页面上没有当前用户会话。你知道我做错了什么吗?代码如下 我正在使用Desive管理身份验证 这是用户模型Ruby on rails 为什么我的用户从Paypal付款返回时没有登录?,ruby-on-rails,paypal,devise,Ruby On Rails,Paypal,Devise,用户注册帐户后,他们将自动登录 然后他们可以选择“激活他们的帐户”来解锁应用程序的功能。帐户激活将引导他们进入Paypal网关。成功完成付款后,它们将重定向回发票页面。但是,发票页面上没有当前用户会话。你知道我做错了什么吗?代码如下 我正在使用Desive管理身份验证 这是用户模型 class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confir
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
validates :first_name, :last_name, :email, :password, presence: true
serialize :notification_params, Hash
def paypal_url(return_path)
values = {
business: "seller@seller.com",
cmd: "_xclick",
upload: 1,
return: "#{Rails.application.secrets.app_host}#{return_path}",
invoice: id,
amount: 20,
item_name: "Online Store",
item_number: 1,
quantity: '1',
notify_url: "#{Rails.application.secrets.app_host}/hook"
}
"#{Rails.application.secrets.paypal_host}/cgi-bin/webscr?" + values.to_query
end
end
这是管理支付/网络钩子的控制器
class MembershipsController < ApplicationController
def show
@user = current_user
end
protect_from_forgery except: [:hook]
def hook
params.permit! # Permit all Paypal input params
status = params[:payment_status]
if status == "Completed"
@user = User.find params[:invoice]
@user.update_attributes notification_params: params, status: status, transaction_id: params[:txn_id], purchased_at: Time.now
end
render nothing: true
end
end
如果你还有什么需要看的,请告诉我。谢谢你经过研究,我在谷歌论坛上找到了Stefan Wrobel的答案 “好的,我终于明白了。对于rails 3.0.4及以上版本,自动 如果有任何操作,表单上的CSRF保护将使会话无效 除GET之外的其他操作已完成,并且未提供真实性令牌。 由于无法让Paypal发送真伪令牌, 有两种解决方法:
class MembershipsController < ApplicationController
def show
@user = current_user
end
protect_from_forgery except: [:hook]
def hook
params.permit! # Permit all Paypal input params
status = params[:payment_status]
if status == "Completed"
@user = User.find params[:invoice]
@user.update_attributes notification_params: params, status: status, transaction_id: params[:txn_id], purchased_at: Time.now
end
render nothing: true
end
end
%section#course-content
%section#ruby
%section.detailed-syllabus
.wrapper-inside
%h3.title Course invoice
.columns.clearfix
.left{style: "padding-left:100px;"}
%p#notice= notice
%p
- if user_signed_in?
%strong Email:
= current_user.first_name
- else
%strong Invalid User Session