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,32 +40,37 @@ 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]
# Save the user ID in the session so it can be used in # config
# subsequent requests config = {}
user = user_data_full( session[:user_id] ) Setting.where( :frontend => true ).each { |setting|
config[setting.name] = setting.state[:value]
}
# auto population of default collections # no valid sessions
default_collection = default_collections() if !session[:user_id]
render :json => {
# config :error => 'no valid session',
config = {} :config => config,
Setting.where( :frontend => true ).each { |setting|
config[setting.name] = setting.state[:value]
} }
return
#, :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 }
end 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
end end