Skip to content

Commit

Permalink
refactoring, tiny methods...
Browse files Browse the repository at this point in the history
  • Loading branch information
mistersourcerer committed Mar 16, 2012
1 parent 5869479 commit 96bcf0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class SessionsController < ApplicationController

def create
auth.authenticate

if current_user
redirect_to projects_path
else
Expand Down
20 changes: 13 additions & 7 deletions app/models/authenticator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@ def initialize(
def authenticate
return false unless @info

user = @all_users.find_or_initialize_by_email(@info["info"] && @info["info"]["email"])
auth = @all_auths.find_or_initialize_by_uid(@info["uid"])
user.add_authentication auth
@all_users.add_or_update(user)
@session[:user] = user_for_info(@info)

@session[:user] = user

return true
true
end

def current(key)
@session[key]
end

private
def user_for_info(info)
user = @all_users.find_or_initialize_by_email(@info["info"] && @info["info"]["email"])
auth = @all_auths.find_or_initialize_by_uid(@info["uid"])
user.add_authentication auth

@all_users.add_or_update(user)

user
end

end

0 comments on commit 96bcf0a

Please sign in to comment.