Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue 124 #137

Merged
merged 1 commit into from Nov 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -62,6 +62,7 @@ gem 'omniauth'
gem 'omniauth-facebook'
gem 'dotenv-rails'
gem 'omniauth-twitter'
gem 'omniauth-google-oauth2'
gem 'geocoder'
gem 'carrierwave'
gem 'rmagick'
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Expand Up @@ -126,6 +126,11 @@ GEM
rack (>= 1.0, < 3)
omniauth-facebook (4.0.0)
omniauth-oauth2 (~> 1.2)
omniauth-google-oauth2 (0.5.2)
jwt (~> 1.5)
multi_json (~> 1.3)
omniauth (>= 1.1.1)
omniauth-oauth2 (>= 1.3.1)
omniauth-oauth (1.1.0)
oauth
omniauth (~> 1.0)
Expand Down Expand Up @@ -242,6 +247,7 @@ DEPENDENCIES
masonry-rails
omniauth
omniauth-facebook
omniauth-google-oauth2
omniauth-twitter
puma (~> 3.0)
rails (~> 5.0.1)
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/users/omniauth_callbacks_controller.rb
Expand Up @@ -7,6 +7,10 @@ def twitter
callback_from :twitter
end

def google_oauth2
callback_from :google
end

private

def callback_from(provider)
Expand All @@ -18,7 +22,7 @@ def callback_from(provider)
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => provider.capitalize) if is_navigational_format?
else
session["devise.#{provider}_data"] = request.env["omniauth.auth"]
session["devise.#{provider}_data"] = request.env["omniauth.auth"].except("extra")
redirect_to new_user_registration_url
end
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/user.rb
Expand Up @@ -2,7 +2,7 @@ class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:facebook, :twitter]
:recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:facebook, :twitter, :google_oauth2]
has_many :posts
has_many :comments
before_save { self.email = email.downcase }
Expand All @@ -16,6 +16,7 @@ def self.find_for_oauth(auth)
unless user
nickname = auth.extra.raw_info.name if auth.provider == 'facebook'
nickname = auth.info.nickname if auth.provider == 'twitter'
nickname = auth.info.name if auth.provider == 'google_oauth2'

user = User.create(
uid: auth.uid,
Expand Down
2 changes: 1 addition & 1 deletion app/views/home/_show_post.html.erb
@@ -1,4 +1,4 @@
<%= div_for(show_post, class: "box") do %>
<%= show_post.name %>
<%= link_to image_tag(show_post.pics[0].avatar_url), url_for(controller: :posts, action: :show, id: show_post.id) %>
<%#= link_to image_tag(show_post.pics[0].avatar_url), url_for(controller: :posts, action: :show, id: show_post.id) %>
<% end %>
8 changes: 7 additions & 1 deletion app/views/home/signin.html.erb
Expand Up @@ -5,8 +5,10 @@
<% if user_signed_in? %>
<% if current_user.provider == "facebook" %>
<i class="facebook icon"></i>
<% else current_user.provider == "twitter" %>
<% elsif current_user.provider == "twitter" %>
<i class="twitter icon"></i>
<% elsif current_user.provider == "google_oauth2" %>
<i class="google plus icon"></i>
<% end %>
<%= link_to current_user.nickname, current_user %>
<% else %>
Expand All @@ -19,6 +21,10 @@
<div id="tw-login-button">
<%= link_to '<i class="twitter icon"></i> Twitter'.html_safe, user_twitter_omniauth_authorize_path, :class => "ui twitter button" %>
</div>

<div id="google-login-button">
<%= link_to '<i class="google plus icon"></i> Google'.html_safe, user_google_oauth2_omniauth_authorize_path, :class => "ui google plus button" %>
</div>
<% end %>
</div>

Expand Down
4 changes: 3 additions & 1 deletion app/views/layouts/_bottom_menu.html.erb
Expand Up @@ -6,8 +6,10 @@
<div class="item">
<% if current_user.provider == "facebook" %>
<i class="facebook icon"></i>
<% else current_user.provider == "twitter" %>
<% elsif current_user.provider == "twitter" %>
<i class="twitter icon"></i>
<% elsif current_user.provider == "google_oauth2" %>
<i class="google plus icon"></i>
<% end %>
<%= link_to current_user.nickname, current_user %>
[<%= link_to 'Sign out', destroy_user_session_path, method: :delete %>]
Expand Down
5 changes: 3 additions & 2 deletions config/initializers/devise.rb
Expand Up @@ -271,6 +271,7 @@
# When using OmniAuth, Devise cannot automatically set OmniAuth path,
# so you need to do it manually. For the users scope, it would be:
# config.omniauth_path_prefix = '/my_engine/users/auth'
config.omniauth :facebook, ENV['FACEBOOK_API'], ENV['FACEBOOK_KEY']
config.omniauth :twitter, ENV['TWITTER_API'], ENV['TWITTER_KEY']
config.omniauth :facebook, ENV['FACEBOOK_API'], ENV['FACEBOOK_KEY']
config.omniauth :twitter, ENV['TWITTER_API'], ENV['TWITTER_KEY']
config.omniauth :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET']
end