From 53ff165ba19b3c8cafbbf0039ac125390016622b Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 10 Apr 2012 21:57:33 +0200 Subject: [PATCH] Improved session login check. --- .../app/controllers/signup.js.coffee | 8 +-- app/controllers/sessions_controller.rb | 53 ++++++++++--------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/app/assets/javascripts/app/controllers/signup.js.coffee b/app/assets/javascripts/app/controllers/signup.js.coffee index 73e99dea8..805ba14cd 100644 --- a/app/assets/javascripts/app/controllers/signup.js.coffee +++ b/app/assets/javascripts/app/controllers/signup.js.coffee @@ -32,7 +32,6 @@ class Index extends App.Controller ) cancel: -> - @log 'cancel....' @navigate 'login' submit: (e) -> @@ -51,10 +50,7 @@ class Index extends App.Controller if !@params.login && @params.email @params.login = @params.email -# role = App.Role.findByAttribute("name", "Customer") -# @params.role_ids = role.id -# @params.role_ids = 3 - @params.role_ids = [] + @params.role_ids = [0] @log 'updateAttributes', @params user = new User user.load(@params) @@ -82,7 +78,6 @@ class Index extends App.Controller ) success: (data, status, xhr) => - @log 'login:success', data # login check auth = new App.Auth @@ -98,7 +93,6 @@ class Index extends App.Controller @navigate '#' error: (xhr, statusText, error) => - console.log 'login:error' # add notify Spine.trigger 'notify:removeall' diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index f49a5793b..825a43a91 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -40,32 +40,37 @@ class SessionsController < ApplicationController # user = User.authenticate('hansi', 'test') respond_to do |format| - if session[:user_id] - - # Save the user ID in the session so it can be used in - # subsequent requests - user = user_data_full( session[:user_id] ) - - # auto population of default collections - default_collection = default_collections() - - # config - config = {} - Setting.where( :frontend => true ).each { |setting| - config[setting.name] = setting.state[:value] + + # config + config = {} + Setting.where( :frontend => true ).each { |setting| + config[setting.name] = setting.state[:value] + } + + # no valid sessions + if !session[:user_id] + render :json => { + :error => 'no valid session', + :config => config, } - - #, :status => :created - format.json { - render :json => { - :session => user, - :default_collections => default_collection, - :config => config - } - } - else - format.json { render :json => { :error => 'no valid session' }, :status => :unprocessable_entity } + return end + + # Save the user ID in the session so it can be used in + # subsequent requests + user = user_data_full( session[:user_id] ) + + # auto population of default collections + default_collection = default_collections() + + #, :status => :created + format.json { + render :json => { + :session => user, + :default_collections => default_collection, + :config => config, + } + } end end