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 135 #138

Merged
merged 3 commits 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 @@ -63,6 +63,7 @@ gem 'omniauth-facebook'
gem 'dotenv-rails'
gem 'omniauth-twitter'
gem 'omniauth-google-oauth2'
gem 'omniauth-instagram'
gem 'geocoder'
gem 'carrierwave'
gem 'rmagick'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Expand Up @@ -131,6 +131,9 @@ GEM
multi_json (~> 1.3)
omniauth (>= 1.1.1)
omniauth-oauth2 (>= 1.3.1)
omniauth-instagram (1.2.0)
omniauth (~> 1)
omniauth-oauth2 (~> 1)
omniauth-oauth (1.1.0)
oauth
omniauth (~> 1.0)
Expand Down Expand Up @@ -248,6 +251,7 @@ DEPENDENCIES
omniauth
omniauth-facebook
omniauth-google-oauth2
omniauth-instagram
omniauth-twitter
puma (~> 3.0)
rails (~> 5.0.1)
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/users/omniauth_callbacks_controller.rb
Expand Up @@ -11,6 +11,10 @@ def google_oauth2
callback_from :google
end

def instagram
callback_from :google
end

private

def callback_from(provider)
Expand Down
4 changes: 3 additions & 1 deletion app/models/user.rb
Expand Up @@ -2,7 +2,8 @@ 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, :google_oauth2]
:recoverable, :rememberable, :trackable, :validatable, :omniauthable,
:omniauth_providers => [:facebook, :twitter, :google_oauth2, :instagram]
has_many :posts
has_many :comments
before_save { self.email = email.downcase }
Expand All @@ -17,6 +18,7 @@ def self.find_for_oauth(auth)
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'
nickname = auth.info.name if auth.provider == 'instagram'

user = User.create(
uid: auth.uid,
Expand Down
10 changes: 8 additions & 2 deletions app/views/home/signin.html.erb
Expand Up @@ -9,6 +9,8 @@
<i class="twitter icon"></i>
<% elsif current_user.provider == "google_oauth2" %>
<i class="google plus icon"></i>
<% elsif current_user.provider == "instagram" %>
<i class="instagram icon"></i>
<% end %>
<%= link_to current_user.nickname, current_user %>
<% else %>
Expand All @@ -19,11 +21,15 @@
</div>

<div id="tw-login-button">
<%= link_to '<i class="twitter icon"></i> Twitter'.html_safe, user_twitter_omniauth_authorize_path, :class => "ui twitter button" %>
<%= link_to '<i class="twitter icon"></i> Twitter'.html_safe, user_twitter_omniauth_authorize_path, :class => "ui left floated 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" %>
<%= link_to '<i class="google plus icon"></i> Google'.html_safe, user_google_oauth2_omniauth_authorize_path, :class => "ui left floated google plus button" %>
</div>

<div id="instagram-login-button">
<%= link_to '<i class="instagram icon"></i> Instagram'.html_safe, user_instagram_omniauth_authorize_path, :class => "ui instagram button" %>
</div>
<% end %>
</div>
Expand Down
2 changes: 2 additions & 0 deletions app/views/layouts/_bottom_menu.html.erb
Expand Up @@ -10,6 +10,8 @@
<i class="twitter icon"></i>
<% elsif current_user.provider == "google_oauth2" %>
<i class="google plus icon"></i>
<% elsif current_user.provider == "instagram" %>
<i class="instagram icon"></i>
<% end %>
<%= link_to current_user.nickname, current_user %>
[<%= link_to 'Sign out', destroy_user_session_path, method: :delete %>]
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/show.html.erb
Expand Up @@ -9,7 +9,7 @@
<% else %>
<%= image_tag @user.image.thumb.url, :class => "ui circular image" %>
<% end %>
<%= @user.uid %>
<%= @user.nickname %>
</h1>
<% if user_signed_in? && @user.id == current_user.id %>
<%= link_to t('users.show.edit_user'), edit_user_path(@user) %>
Expand Down
7 changes: 4 additions & 3 deletions config/initializers/devise.rb
Expand Up @@ -271,7 +271,8 @@
# 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 :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET']
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']
config.omniauth :instagram, ENV['INSTAGRAM_CLIENT_ID'], ENV['INSTAGRAM_CLIENT_SECRET']
end