mirror of https://github.com/sipwise/ngcp-csc.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.7 KiB
61 lines
1.7 KiB
// Attach JWT token to every request, and cleanup framework default params
|
|
Ext.Ajax.on("beforerequest", function(con, options) {
|
|
con.setUseDefaultXhrHeader(false);
|
|
con.setWithCredentials(true);
|
|
if (options.params && localStorage.getItem('jwt_token')) {
|
|
delete options.params.page;
|
|
delete options.params.start;
|
|
delete options.params.limit;
|
|
options.params['jwt_token'] = localStorage.getItem('jwt_token');
|
|
}
|
|
});
|
|
|
|
// in case of 401, user is redirected to login screen
|
|
Ext.Ajax.on("requestexception", function(con, response) {
|
|
var httpStatus = response.status;
|
|
switch (httpStatus) {
|
|
case 401:
|
|
NgcpCsc.getApplication().showLogin();
|
|
break;
|
|
}
|
|
});
|
|
|
|
Ext.application({
|
|
name: 'NgcpCsc',
|
|
|
|
extend: 'NgcpCsc.Application',
|
|
|
|
// Simply require all classes in the application. This is sufficient to ensure
|
|
// that all NgcpCsc classes will be included in the application build. If classes
|
|
// have specific requirements on each other, you may need to still require them
|
|
// explicitly.
|
|
//
|
|
requires: [
|
|
'NgcpCsc.*',
|
|
'Ext.window.Toast'
|
|
],
|
|
|
|
showLogin: function() {
|
|
var mainCmp = Ext.ComponentQuery.query('ngcp-main')[0];
|
|
if (mainCmp) {
|
|
mainCmp.destroy();
|
|
}
|
|
Ext.create({
|
|
xtype: 'ngcp-login'
|
|
});
|
|
localStorage.removeItem('jwt_token');
|
|
localStorage.removeItem('subscriber_id');
|
|
localStorage.removeItem('type');
|
|
localStorage.removeItem('username');
|
|
window.location.hash = '';
|
|
},
|
|
|
|
showMain: function() {
|
|
Ext.create({
|
|
xtype: 'ngcp-main'
|
|
});
|
|
window.location.hash = '#inbox';
|
|
}
|
|
|
|
});
|