Implements iChain authentication

This commit is contained in:
chrisbr 2014-11-04 17:42:47 +01:00
parent 15c6ed127f
commit 49d565def2
21 changed files with 269 additions and 126 deletions

View file

@ -11,11 +11,13 @@ module Users
def handle(provider)
auth_hash = request.env['omniauth.auth']
uid = auth_hash[:uid]
openid = Openid.find_for_oauth(auth_hash) # Get or create openid
# If openid exists and is associated with a user, sign in with associated user,
# even if the email of the associated user and the email of the provided openid are different
unless (user = openid.user)
user = User.find_for_auth(auth_hash, current_user) # Get or create users
user.username = "#{uid}@#{provider}" if user.username.blank?
end
begin
@ -28,7 +30,8 @@ module Users
sign_in user
redirect_to root_path, notice: user.email + " signed in successfully with #{provider}"
rescue => e
redirect_back_or_to new_user_registration_path, alert: 'Failed' + e.message
flash[:error] = e.message
redirect_back_or_to new_user_registration_path
end
end
end