Improved session login check.

This commit is contained in:
Martin Edenhofer 2012-04-10 21:57:33 +02:00
parent 99e9751612
commit 53ff165ba1
2 changed files with 30 additions and 31 deletions

View file

@ -32,7 +32,6 @@ class Index extends App.Controller
) )
cancel: -> cancel: ->
@log 'cancel....'
@navigate 'login' @navigate 'login'
submit: (e) -> submit: (e) ->
@ -51,10 +50,7 @@ class Index extends App.Controller
if !@params.login && @params.email if !@params.login && @params.email
@params.login = @params.email @params.login = @params.email
# role = App.Role.findByAttribute("name", "Customer") @params.role_ids = [0]
# @params.role_ids = role.id
# @params.role_ids = 3
@params.role_ids = []
@log 'updateAttributes', @params @log 'updateAttributes', @params
user = new User user = new User
user.load(@params) user.load(@params)
@ -82,7 +78,6 @@ class Index extends App.Controller
) )
success: (data, status, xhr) => success: (data, status, xhr) =>
@log 'login:success', data
# login check # login check
auth = new App.Auth auth = new App.Auth
@ -98,7 +93,6 @@ class Index extends App.Controller
@navigate '#' @navigate '#'
error: (xhr, statusText, error) => error: (xhr, statusText, error) =>
console.log 'login:error'
# add notify # add notify
Spine.trigger 'notify:removeall' Spine.trigger 'notify:removeall'

View file

@ -40,7 +40,21 @@ class SessionsController < ApplicationController
# user = User.authenticate('hansi', 'test') # user = User.authenticate('hansi', 'test')
respond_to do |format| respond_to do |format|
if session[:user_id]
# 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,
}
return
end
# Save the user ID in the session so it can be used in # Save the user ID in the session so it can be used in
# subsequent requests # subsequent requests
@ -49,23 +63,14 @@ class SessionsController < ApplicationController
# auto population of default collections # auto population of default collections
default_collection = default_collections() default_collection = default_collections()
# config
config = {}
Setting.where( :frontend => true ).each { |setting|
config[setting.name] = setting.state[:value]
}
#, :status => :created #, :status => :created
format.json { format.json {
render :json => { render :json => {
:session => user, :session => user,
:default_collections => default_collection, :default_collections => default_collection,
:config => config :config => config,
} }
} }
else
format.json { render :json => { :error => 'no valid session' }, :status => :unprocessable_entity }
end
end end
end end