facebook authenticate
This commit is contained in:
parent
9231e01014
commit
dd8f5c454a
5 changed files with 32 additions and 9 deletions
|
|
@ -0,0 +1,18 @@
|
|||
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||
def facebook
|
||||
# You need to implement the method below in your model (e.g. app/models/user.rb)
|
||||
@user = User.from_omniauth(request.env["omniauth.auth"])
|
||||
|
||||
if @user.persisted?
|
||||
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
|
||||
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
|
||||
else
|
||||
session["devise.facebook_data"] = request.env["omniauth.auth"]
|
||||
redirect_to new_user_registration_url
|
||||
end
|
||||
end
|
||||
|
||||
def failure
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
|
|
@ -19,7 +19,8 @@
|
|||
<% end -%>
|
||||
|
||||
<%- if devise_mapping.omniauthable? %>
|
||||
<%- resource_class.omniauth_providers.each do |provider| %>
|
||||
<%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %><br />
|
||||
<% end -%>
|
||||
<%- resource_class.omniauth_providers.each do |provider| %>
|
||||
<%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %><br />
|
||||
<% end -%>
|
||||
|
||||
<% end -%>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
|
||||
<p class="navbar-text pull-right">
|
||||
<% if user_signed_in? %>
|
||||
Logged in as <strong><%= current_user.email %></strong>.
|
||||
|
|
@ -18,7 +20,9 @@
|
|||
<% else %>
|
||||
<%= link_to "Sign up", new_user_registration_path, :class => 'navbar-link' %> |
|
||||
<%= link_to "Login", new_user_session_path, :class => 'navbar-link' %>
|
||||
<%= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path %>
|
||||
<!-- <%= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path %> -->
|
||||
|
||||
|
||||
<% end %>
|
||||
</p>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,21 +5,21 @@
|
|||
# gem 'sqlite3'
|
||||
#
|
||||
default: &default
|
||||
adapter: postgresql
|
||||
adapter: sqlite3
|
||||
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
||||
timeout: 5000
|
||||
|
||||
development:
|
||||
<<: *default
|
||||
database: db/development.postgresql
|
||||
database: db/development.sqlite3
|
||||
|
||||
# Warning: The database defined as "test" will be erased and
|
||||
# re-generated from your development database when you run "rake".
|
||||
# Do not set this db to the same as development or production.
|
||||
test:
|
||||
<<: *default
|
||||
database: db/test.postgresql
|
||||
database: db/test.sqlite3
|
||||
|
||||
production:
|
||||
<<: *default
|
||||
database: db/production.postgresql
|
||||
database: db/production.sqlite3
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@ Devise.setup do |config|
|
|||
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
||||
# up on your models and hooks.
|
||||
# config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
|
||||
config.omniauth :facebook, "APP_ID", "APP_SECRET"
|
||||
config.omniauth :facebook, "137009576938168", "5fb495fe5da4aad7d7e8f3863018c527"
|
||||
# ==> Warden configuration
|
||||
# If you want to use other strategies, that are not supported by Devise, or
|
||||
# change the failure app, you can configure them inside the config.warden block.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue