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: ->
@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'

View file

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