Skip to content
This repository has been archived by the owner on Feb 18, 2020. It is now read-only.

Commit

Permalink
+ Refactored session create to reduce complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
Averethel committed Feb 9, 2014
1 parent fa41120 commit 02939dc
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions app/controllers/sessions_controller.rb
Expand Up @@ -4,6 +4,27 @@ def create
session[:user_id] = user.id
flash[:notice] = 'Signed In!'

update_user_data(user)
redirect_to root_url
end

def destroy
session[:user_id] = nil
flash[:notice] = 'Signed Out'
redirect_to root_url
end

private

def update_user_data(user)
data = get_user_data
user.update_attributes email: data['email'],
name: data['given_name'],
surname: data['family_name'],
avatar: data['picture']
end

def get_user_data
auth = Signet::Rails::Factory.create_from_env :google, request.env
client = Google::APIClient.new
client.authorization = auth
Expand All @@ -13,19 +34,9 @@ def create
:parameters => {},
:headers => {'Content-Type' => 'application/json'}
)
data = JSON.parse(result.body)
user.update_attributes email: data['email'],
name: data['given_name'],
surname: data['family_name'],
avatar: data['picture']
JSON.parse(result.body)
end


redirect_to root_url
end

def destroy
session[:user_id] = nil
flash[:notice] = 'Signed Out'
redirect_to root_url
end
end

0 comments on commit 02939dc

Please sign in to comment.