Skip to content

Commit

Permalink
Merge pull request #31 from alexandrz/master
Browse files Browse the repository at this point in the history
Use verified emails only
  • Loading branch information
sigmike committed Mar 5, 2014
2 parents dbcea4b + c4b9f93 commit 5fdcbe8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ end

gem 'devise'
gem 'omniauth'
gem 'omniauth-github', git: 'https://github.com/sigmike/omniauth-github.git', branch: 'provide_emails'
gem 'omniauth-github', github: 'alexandrz/omniauth-github', branch: 'provide_emails'

gem 'octokit'

Expand Down
18 changes: 9 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
GIT
remote: git://github.com/alexandrz/omniauth-github.git
revision: 37a030aa37659831ef80af21b5c7270fe1384b3c
branch: provide_emails
specs:
omniauth-github (1.1.0)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.1)

GIT
remote: git://github.com/capistrano/rvm.git
revision: 19e8d15ae3d705499c610370f159d523bbedbd94
Expand All @@ -17,15 +26,6 @@ GIT
rails (>= 3.1)
railties (>= 3.1)

GIT
remote: https://github.com/sigmike/omniauth-github.git
revision: a6a3a48b5bad1f7b677e07340edee95c070da94d
branch: provide_emails
specs:
omniauth-github (1.1.0)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.1)

GEM
remote: https://rubygems.org/
specs:
Expand Down
23 changes: 14 additions & 9 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,28 @@ def github
# render text: "#{request.env["omniauth.auth"].to_json}"
info = request.env["omniauth.auth"]["info"]
@user = User.find_by :nickname => info["nickname"]
if @user.nil? and info["emails"].any?
@user = User.find_by :email => info["emails"]
if @user.nil? and info["verified_emails"].any?
@user = User.find_by :email => info["verified_emails"]
end
unless @user
generated_password = Devise.friendly_token.first(8)
@user = User.create!(
:email => info['email'],
:password => generated_password,
:nickname => info['nickname']
)
if info['primary_email']
generated_password = Devise.friendly_token.first(8)
@user = User.create!(
:email => info['primary_email'],
:password => generated_password,
:nickname => info['nickname']
)
else
set_flash_message(:error, :failure, kind: 'GitHub', reason: 'your promary email address should be verified.')
redirect_to new_user_session_path and return
end
end

@user.name = info['name']
@user.image = info['image']
@user.save

sign_in_and_redirect @user, :event => :authentication
set_flash_message(:notice, :success, :kind => "Github") if is_navigational_format?
set_flash_message(:notice, :success, :kind => "GitHub") if is_navigational_format?
end
end

0 comments on commit 5fdcbe8

Please sign in to comment.