9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'app/controllers/authentications_controller.rb', line 9
def create
omniauth = request.env["omniauth.auth"]
if omniauth
uid = (omniauth['uid']||omniauth['extra']['access_token'].params['member_id'])
authentication = Authentication.find_by_provider_and_authenticationable_type_and_uid(omniauth['provider'], uid)
if authentication
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, authentication.user)
elsif current_user
current_user.authentications.create!(:provider => omniauth['provider'], :uid => uid, :token => omniauth['credentials']['token'], :secret => omniauth['credentials']['secret'])
flash[:notice] = "Authentication successful."
redirect_to authentications_url
else
user = User.new
user.apply_omniauth(omniauth)
if user.save
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, user)
else
session[:omniauth] = omniauth.except('extra')
redirect_to new_user_registration_url
end
end
else
redirect_to root_url
end
end
|