From aba551df662009c6c1c7f9cc4db0646c410c0384 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 18 Apr 2012 10:33:42 +0200 Subject: [PATCH] Refactoring. --- app/controllers/sessions_controller.rb | 36 +++++++++++--------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index ec3fe5bfa..9fac603c8 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -66,37 +66,31 @@ class SessionsController < ApplicationController render :json => { } end - + def create_omniauth -# auth = request.env['rack.auth'] auth = request.env['omniauth.auth'] - logger.info(auth.inspect) if !auth logger.info("AUTH IS NULL, SERVICE NOT LINKED TO ACCOUNT") -# logger.info() -# logger.info("PROVIDER: #{provider}, UID: #{uid}, EMAIL: #{email}") + + # redirect to app + redirect_to '/app#' end - logger.info(1111111) -# raise auth.to_yaml - unless @auth = Authorization.find_from_hash(auth) - # Create a new user or add an auth to existing user, depending on - # whether there is already a user signed in. - @auth = Authorization.create_from_hash(auth, current_user) + + # Create a new user or add an auth to existing user, depending on + # whether there is already a user signed in. + authorization = nil + if current_user + authorization = Authorization.create_from_hash(auth, current_user) + else + authorization = Authorization.find_from_hash(auth) end -# logger.info(2222222) -# logger.info(@auth) -# logger.info(@auth.inspect) -# logger.info(@auth.user) + # Log the authorizing user in. -# self.current_user = @auth.user -# user = @auth.user -# logger.info(333333333) -# exit - session[:user_id] = @auth.user.id + session[:user_id] = authorization.user.id # redirect to app - redirect_to '/app#' + redirect_to '/app#' end private