refactor security system

This commit is contained in:
2012-12-11 11:27:41 +01:00
parent f19044ae6a
commit 009b84f7cd
10 changed files with 151 additions and 103 deletions
+9 -10
View File
@@ -1,6 +1,6 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
// a
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
@@ -39,7 +39,7 @@ var path_mapping = {
list_products: '/list_products',
active_list: '/active_list',
history_list: '/history_list',
obtain_user_token: '/obtain_token',
obtain_token: '/obtain_token',
lists_history: '/list_history'
}
var $translations = {
@@ -119,7 +119,7 @@ function redirect_to(mapping, variables){
var vars = [];
for(var name in variables){
vars.push(name + '=' +variables[name]);
Qstorage[name] = variables[name];
Qstorage.setItem(name, variables[name]);
}
window.location = QMobile.root_url() + path_mapping[mapping] + '.html'
}
@@ -154,22 +154,21 @@ function t(path, vars){
$.ajaxSetup({
error: function(xhr, ajaxOptions, error, another){
if(xhr.status == 401){
direct_to_site('obtain_user_token');
redirect_to('obtain_token');
}else if(xhr.status == 0){
QMobile.connection_problem();
}
}
});
var Qstorage = sessionStorage;
$(function(){
$locale = QMobile.locale();
if(Qstorage.message){
$locale = Qstorage.getItem('locale') || 'en';
if(Qstorage.getItem('message')){
var container = $('.alert-success');
container.find('div').text($translations[$locale]['messages'][Qstorage.message]);
container.find('div').text($translations[$locale]['messages'][Qstorage.getItem('message')]);
container.show();
Qstorage.removeItem('message');
}
if(Qstorage.list_closed){
if(Qstorage.getItem('list_closed')){
var container = $('.alert-error');
container.find('div').text($translations[$locale]['messages']['the_list_has_been_closed']);
container.show();
@@ -178,7 +177,7 @@ $(function(){
setTranslations();
});
function setLocale(locale){
QMobile.setLocale(locale);
Qstorage.setItem('locale', locale);
$locale = locale;
setTranslations();
}