Refactor to a method to DRY, even if its not 100% the best spot for it to live long term

This commit is contained in:
Daniel O'Connor
2016-08-22 18:52:12 +09:30
parent 0f034523e1
commit 87352b04f1
2 changed files with 16 additions and 19 deletions

View File

@@ -7,16 +7,7 @@ class AuthenticationsController < ApplicationController
auth = request.env['omniauth.auth']
@authentication = nil
if auth
name = ''
case auth['provider']
when 'twitter'
name = auth['info']['nickname']
when 'flickr', 'facebook'
name = auth['info']['name']
else
name = auth['info']['name']
end
name = Growstuff::OauthSignupAction.new.determine_name(auth)
@authentication = current_member.authentications
.create_with(

View File

@@ -38,15 +38,7 @@ class Growstuff::OauthSignupAction
# - We need to create it
#
def establish_authentication(auth, member)
name = ''
case auth['provider']
when 'twitter'
name = auth['info']['nickname']
when 'flickr', 'facebook'
name = auth['info']['name']
else
name = auth['info']['name']
end
name = determine_name(auth)
authentication = member.authentications
.create_with(
@@ -67,4 +59,18 @@ class Growstuff::OauthSignupAction
def member_created?
@member_created
end
def determine_name(auth)
name = ''
case auth['provider']
when 'twitter'
name = auth['info']['nickname']
when 'flickr', 'facebook'
name = auth['info']['name']
else
name = auth['info']['name']
end
name
end
end