Witam, mam aplikacje do której mogę się logować po przez konto facebooka. W jaki sposób mogę uzyskać efekty w którym będąc juz wcześniej zalogowanym do facebooka wchodze do aplikacji beż monitu logowania devise
#kontroler dla callback
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
# You need to implement the method below in your model
@user = User.find_for_facebook_oauth(env[“omniauth.auth”], current_user)
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Fac
ebook"
sign_in_and_redirect @user, :event => :authentication
else
session[“devise.facebook_data”] = env[“omniauth.auth”]
redirect_to new_user_registration_url
end
end
end
model user
class User < ActiveRecord::Base
devise :omniauthable,:database_authenticatable, :registerable
#:recoverable, :trackable, :validatable, :oauth2_authenticatable
Setup accessible (or protected) attributes for your model
attr_accessible :name,:firstname,:lastname,:email, :password, :password_confir
mation, :remember_me
def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
data = access_token[‘extra’][‘user_hash’]
@fb_data=data
if user = User.find_by_email(data[“email”])
user
else # Create an user with a stub password.
User.create!(:email => data[“email”], :password => Devise.friendly_token[0,2
0],:firstname=>data[“name”].split[0],:lastname=>data[“name”].split[1])
end
end
widok standardowy dla devise dla session + link do facebooka
app/views/devise/sessions/new.html.erb
app/views/devise/shared/_links.erb
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to image_tag(‘fb-login.gif’),omniauth_authorize_path(resource_name,
provider),:border=>0 %>
<%# link_to t(“Sign in with #{provider.to_s.titleize}”), omniauth_authorize_
path(resource_name, provider) %>
<% end -%>
<% end -%>