我无法找到从Facebook注销的方法。我们使用window.location = '/auth/facebook'
登录,将用户重定向到Facebook登录页面,并将回调路由/auth/facebook/callback
(在developers.facebook.com
中声明)调用到session_controller/create
中的方法。
session_controller/create
方法如下所示
def create
#get auth hash from omniauth
auth = auth_hash
@data = {}
@session_data = {}
@data['id'] = auth['uid']
@data['access_token'] = auth['credentials']['token']
#time must be in iso format, see parse rest api for details under linking
@expiry = Time.at(auth['credentials']['expires_at']).iso8601
@data['expiration_date'] = @expiry
#create new linking user object
user = Parse::User::Facebook.new(@data)
# add other user information to body of PARSE::USER::FACEBOOK instance
user.body['email'] = auth['info']['email']
user.body['auth'] = true
user.body['fullname'] = auth['info']['name']
user.body['ip'] = request.remote_ip
user.body['image'] = auth['info']['image'] if auth['info']['image']
user.body['admin'] = false
user.body['facebookId'] = auth['uid']
user.body['facebookToken'] = auth['credentials']['token']
user.body['has_seen_web_tutorial'] = false
@current_user = user.save
#save necessary session information
session['name'] = @current_user['fullname']
session['points'] = @current_user['points']
session['objectId'] = @current_user['objectId']
session['sessionToken'] = @current_user['sessionToken']
session['image'] = @current_user['image']
session['location'] = @current_user['location']
@session_data['name'] = session['name']
@session_data['fullname'] = @current_user['fullname']
@session_data['points'] = session['points']
@session_data['objectId'] = session['objectId']
@session_data['image'] = session['image']
if auth['info']['image']
File.open('temp_face.png', 'wb') do |file|
file << open(auth['info']['image'], :allow_redirections => :safe).read
end
photo = Parse::File.new({
:body => IO.read("temp_face.png"),
:local_filename => "temp_face.png",
:content_type => "image/png"
})
photo.save
#user.body['image'] = photo
end
image = Parse::Object.new("ImageUploads")
image['fileKey'] = photo
image['owner'] = Parse::Pointer.new({"className" => "_User", "objectId" => session['objectId']})
image['type'] = 'profile'
#image['location']
saved_image = image.save
redirect_to listing_index_path
end
我无法尝试退出。对铁路来说很新。有什么帮助吗? 谢谢