Skip to content

Commit 13fe177

Browse files
author
minhyeok92
committed
OAuth 로그인 시엔 패스워드를 DB에 저장하지 않는다
1 parent faf679a commit 13fe177

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

app/controllers/users/omniauth_callbacks_controller.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
22
def facebook
33
@user = User.find_for_oauth2(request.env["omniauth.auth"])
44

5+
session["omniauth"] = request.env["omniauth.auth"]
6+
57
if @user.nil?
6-
session["omniauth"] = request.env["omniauth.auth"]
7-
redirect_to users_merge_path
8+
render users_nickname_new_path
9+
elsif @user == "duplicated"
10+
redirect_to users_merge_path
811
else
912
sign_in_and_redirect @user, :event => :authentication
1013
end
@@ -14,10 +17,10 @@ def google_oauth2
1417
@user = User.find_for_oauth2(request.env["omniauth.auth"])
1518

1619
session["omniauth"] = request.env["omniauth.auth"]
17-
20+
1821
if @user.nil?
1922
render users_nickname_new_path
20-
elsif @user == "dup"
23+
elsif @user == "duplicated"
2124
redirect_to users_merge_path
2225
else
2326
sign_in_and_redirect @user, :event => :authentication

app/controllers/users_controller.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def nickname_new_callback
2929
@user = User.create!(provider:auth["provider"],
3030
uid: auth["uid"],
3131
email: auth["info"]["email"],
32-
password: Devise.friendly_token[0,20],
3332
nickname: params[:nickname])
3433
sign_in_and_redirect @user, :event => :authentication
3534
end
@@ -46,8 +45,7 @@ def sign_up_from_twitter_callback
4645

4746
@user = User.new(provider:auth["provider"],
4847
uid:auth["uid"],
49-
nickname: auth["extra"]["raw_info"]["screen_name"],
50-
password: Devise.friendly_token[0,20])
48+
nickname: auth["extra"]["raw_info"]["screen_name"])
5149

5250
@user.email = params[:user]["email"]
5351

app/models/user.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def self.find_for_oauth2(access_token)
5151

5252
unless user
5353
if User.where(email: data["email"]).first
54-
"dup"
54+
user = "duplicated"
5555
else
56-
nil
56+
user = nil
5757
end
5858
end
5959
user
@@ -77,6 +77,10 @@ def update_from_twitter(id, email)
7777
user.save!
7878
end
7979

80-
80+
def password_required?
81+
if provider.nil?
82+
super
83+
end
84+
end
8185

8286
end

0 commit comments

Comments
 (0)