-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
minhyeok
committed
Aug 28, 2014
1 parent
ab02179
commit 9166136
Showing
10 changed files
with
149 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,55 @@ | ||
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController | ||
def self.provides_callback_for(provider) | ||
class_eval %Q{ | ||
def #{provider} | ||
@provider = "#{provider}" | ||
@uid = request.env["omniauth.auth"].uid | ||
result = User.find_for_oauth(@provider, request.env["omniauth.auth"]) | ||
case @provider | ||
when "twitter" | ||
@nickname = request.env["omniauth.auth"]["extra"]["raw_info"].screen_name | ||
case result[:status] | ||
when :success | ||
@user = result[:data] | ||
sign_in_and_redirect @user, :event => :authentication | ||
when :first_login | ||
@user = User.new | ||
render sign_up_from_twitter_users_path | ||
end | ||
else | ||
@email = request.env["omniauth.auth"]["info"].email | ||
case result[:status] | ||
when :success | ||
@user = result[:data] | ||
sign_in_and_redirect @user, :event => :authentication | ||
when :first_login | ||
@user = User.new | ||
render nickname_new_users_path | ||
when :duplicated | ||
@user = User.find_by_email(@email) | ||
render merge_users_path | ||
end | ||
end | ||
def authenticate(provider) | ||
@user = User.new( | ||
provider: provider, | ||
uid: request.env["omniauth.auth"].uid) | ||
|
||
result = User.find_for_oauth(provider, request.env["omniauth.auth"]) | ||
|
||
case provider | ||
when :twitter | ||
@user.nickname = request.env["omniauth.auth"]["extra"]["raw_info"].screen_name | ||
|
||
case result[:status] | ||
when :success | ||
@user = result[:data] | ||
sign_in_and_redirect @user, :event => :authentication | ||
|
||
when :first_login | ||
render sign_up_from_twitter_users_path | ||
end | ||
|
||
else | ||
@user.email = request.env["omniauth.auth"]["info"].email | ||
|
||
case result[:status] | ||
when :success | ||
@user = result[:data] | ||
sign_in_and_redirect @user, :event => :authentication | ||
|
||
when :first_login | ||
render nickname_new_users_path | ||
|
||
when :duplicated | ||
@user = User.find_by_email(@user.email) | ||
render merge_users_path | ||
|
||
when :duplicated_by_oauth | ||
flash[:notice] = result[:data] + " 서비스로 이미 회원가입 되어있습니다. 해당 서비스로 로그인해주세요" | ||
redirect_to new_user_session_path | ||
end | ||
} | ||
end | ||
end | ||
|
||
def twitter | ||
authenticate(:twitter) | ||
end | ||
|
||
def facebook | ||
authenticate(:facebook) | ||
end | ||
|
||
[:twitter, :facebook, :google_oauth2].each do |provider| | ||
provides_callback_for provider | ||
def google_oauth2 | ||
authenticate(:google_oauth2) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
|
||
<%= form_tag(nickname_new_callback_users_path, method: "post") do %> | ||
<div class="form-container"> | ||
<%= form_for @user, url: nickname_new_callback_users_path, method: "post" do |f| %> | ||
|
||
<p>처음이십니다. 새로운 닉네임을 입력하세요</p> | ||
|
||
<%= text_field_tag(:nickname) %> | ||
<%= f.error_messages %> | ||
|
||
<% if flash[:notice] %> | ||
<p class="notice"><%= flash[:notice] %></p> | ||
<% end %> | ||
|
||
<%= hidden_field_tag(:provider, @provider) %> | ||
<%= hidden_field_tag(:uid, @uid) %> | ||
<%= hidden_field_tag(:email, @email) %> | ||
<div class="form-group"> | ||
<%= f.label :nickname %> | ||
<%= f.text_field :nickname, autofocus: true, class: "form-control" %> | ||
</div> | ||
|
||
<%= f.hidden_field :provider, value: @user.provider %> | ||
<%= f.hidden_field :uid, value: @user.uid %> | ||
<%= f.hidden_field :email, value: @user.email %> | ||
|
||
<%= f.submit "Submit", class: "btn btn-primary" %> | ||
|
||
<%= submit_tag("Submit", class: "btn btn-primary") %> | ||
<% end %> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters