Skip to content

Commit

Permalink
Refactor Auth and Routes
Browse files Browse the repository at this point in the history
  • Loading branch information
bradschafer committed Oct 30, 2015
1 parent bf12076 commit e95f1f3
Show file tree
Hide file tree
Showing 16 changed files with 548 additions and 393 deletions.
76 changes: 76 additions & 0 deletions WebRTC/bootstrap.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion WebRTC/classic.json

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions WebRTC/classic/src/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@ Ext.define('WebRTC.Application', {

requires: ['WebRTC.*'],

//If no token then go home
defaultToken : 'home',

//Global Controllers
controllers:[
'opentok.controller.OpenTok',
'soundlibrary.controller.SoundLibrary',
'Auth',
'Navigation'
],


stores:['WebRTC.store.chat.Rooms','Settings','SecurityRoles','Users'],
//Global Stores
stores:[
'WebRTC.store.chat.Rooms',
'Settings',
'SecurityRoles',
'Users'
],

init: function(){
WebRTC.util.Logger.init();
Expand Down
27 changes: 22 additions & 5 deletions WebRTC/classic/src/controller/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ Ext.define('WebRTC.controller.Auth', {
//used to store the currect number of seconds idle
idleTime: 0,

listen: {
controller: {
'*':{
isAuthReady: 'isAuthReady'
}
}
},

init: function () {
var me = this;
Expand All @@ -54,15 +61,25 @@ Ext.define('WebRTC.controller.Auth', {
me.FBUrl = record.data.fbUrl;
me.firebaseRef = new Firebase(me.FBUrl);
me.ensureFirebaseReady();


}
}
});

},

//Since there's no callback when firebase is ready wait and retry a few times, then call initDone when ready
isAuthReady: function(callback){
var me = this;
if (!me.firebaseRef) {
Ext.Function.defer(function () {
callback(true);
},
500);
}else{
callback(true);
}
},

// Since there's no callback when firebase is ready wait and retry a few times, then call initDone when ready
ensureFirebaseReady: function(){
var me = this;
if (!me.firebaseRef) {
Expand Down Expand Up @@ -381,13 +398,13 @@ Ext.define('WebRTC.controller.Auth', {
WebRTC.util.Logger.log("User account deleted successfully!");
Ext.util.Cookies.clear('user');
firebase.unauth();
this.redirectTo('login');
this.redirectTo('logout');
}
});
}else{
Ext.util.Cookies.clear('user');
firebase.unauth();
this.redirectTo('login')
this.redirectTo('logout')
}

},
Expand Down
182 changes: 130 additions & 52 deletions WebRTC/classic/src/controller/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ Ext.define('WebRTC.controller.Navigation', {
'home' : {
action : 'onRouteHome'
},
'room' : {
before : 'onRouteBeforeRoom',
action : 'onRouteRoom'
},
'room/:id' : {
// before : 'onRouteBeforeRoom',
before : 'onRouteBeforeRoomId',
action : 'onRouteRoom'
},
'token/:id' : {
Expand All @@ -21,6 +25,9 @@ Ext.define('WebRTC.controller.Navigation', {
'user' : {
action : 'onRouteUser'
},
'logout' : {
action : 'onRouteLogout'
},
'settings' : {
before : 'onRouteBeforeSettings',
action : 'onRouteSettings'
Expand All @@ -29,78 +36,126 @@ Ext.define('WebRTC.controller.Navigation', {

listen: {
controller: {
'auth':{
// configure: 'onAdminSetup',
// initDone: 'onAuthInit',
islogin: 'onAuthIsLogin',
islogout: 'onAuthIsLogout',
login: 'onAuthLogin'
},
'#' : {
unmatchedroute : 'onRouteUnmatched'
}
}
},

onRouteHome: function(){
//empty object that will contain route to continue with if authorized
_authorizingRoute: null,

//Hide everything on the viewport except our route.
clearViewport: function (doRemove){
var viewport = Ext.ComponentQuery.query('app-main')[0];
Ext.each(viewport.items.items, function(childPanel) {
if(!!doRemove){
viewport.remove(childPanel, true);
}else{
childPanel.hide();
}
});
},

onRouteUnmatched:function(route){
if(!!route){
WebRTC.util.Logger.log('unmatched route' + route);
window.location.hash = '#home';
//add or show a new component based on the route
onRouteViewportComponent: function (xtype, params) {
this.clearViewport();
if(Ext.ComponentQuery.query(xtype)[0]){
Ext.ComponentQuery.query(xtype)[0].show();
}else{
Ext.ComponentQuery.query('app-main')[0].add(params)
}
},

/*
onRouteBeforeRoom : function(id, action) {
var me = this,
roomId = id;
if(Ext.StoreManager.lookup('rooms').getTotalCount() > 0 ){
var room = Ext.StoreManager.lookup('rooms').getById(roomId);
if(!room){
action.stop();
me.redirectTo('');
}else{
me.onRouteRoomSetup(room,action);
}
onRouteHome: function(){
this.onRouteViewportComponent('uxiframe',{
xtype:'uxiframe',
src: "/static/cms/",
region:'north',
layout:'fit',
flex:1,
reference: 'cms'
});
},

}else{
Ext.StoreManager.lookup('rooms').load(function(){
var room = Ext.StoreManager.lookup('rooms').getById(roomId); //lookup the value after callback
if(!room){
action.stop();
me.redirectTo('');
}else{
me.onRouteRoomSetup(room,action);
}
})
onRouteUnmatched: function(route) {
if(!!route){
WebRTC.util.Logger.log('unmatched route' + route);
window.location.hash = '#home';
}
},

onRouteRoomSetup: function(room, action){
var me= this,
userCookie = Ext.util.Cookies.get('user');
onRouteBeforeRoom : function(action) {
var me = this;
me.fireEvent('isAuthReady',function(isReady) {
me._authorizingRoute = {
action: action
};
me.fireEvent('authorize');
});
},

if( room.get('isPublic') ){
action.resume();
}else{
if( room.get('isPrivate') ){
this.redirectTo('denied');
}else{
action.resume();
}
}
onRouteBeforeRoomId : function(id, action) {
this.onRouteBeforeRoom(action);
},
*/

onRouteRoom: function(id){
var combo = Ext.first('combobox[reference=roomscombo]');
var vm = Ext.ComponentQuery.query('app-main')[0].getViewModel();

//Chat rooms into center
this.onRouteViewportComponent('chatroomscontainer',{
xtype:'chatroomscontainer',
region:'center',
flex:5,
layout:'fit',
startupRoom: id,
bind: {
title: 'Sencha Communicator | {user.fn}'
},
reference: 'roomtabs'
});

if(1==0){ //!vm.isAdmin(vm)
this.onRouteViewportComponent('chatpresense',{
title: 'All Users',
xtype: 'chatpresense',
region:'west',
collapsable: true,
collasped: true,
/*bind: {
hidden: '{!isAdmin}'
},*/
split:true,
flex: 1
});
}

Ext.Function.defer(function(){
var record = combo.store.getById(id);
if(record){
combo.select(record);
combo.fireEvent('select',combo,record);
}
},
1200);
},

// this will be used when we implment more room security
onRouteRoomSetup: function(room, action){
/*
var me= this,
userCookie = Ext.util.Cookies.get('user');
if( room.get('isPublic') ){
action.resume();
}else{
if( room.get('isPrivate') ){
this.redirectTo('denied');
}else{
action.resume();
}
}
*/
},

onRouteBeforeToken : function(id, action) {
Expand Down Expand Up @@ -154,6 +209,29 @@ Ext.define('WebRTC.controller.Navigation', {
onRouteToken: function(){
var id = this.tokenInfo.id;
this.onRouteRoom(id)
},

onRouteLogout: function (){
this.redirectTo('home');
},

//user was already logged in
onAuthIsLogin: function(){
if(this._authorizingRoute){
this._authorizingRoute.action.resume();
}
},

//login successful
onAuthLogin: function(authData){
if(this._authorizingRoute){
this._authorizingRoute.action.resume();
}
},

//user was not logged in - so log them in
onAuthIsLogout: function(){
this.redirectTo('login');
}


Expand Down
Loading

0 comments on commit e95f1f3

Please sign in to comment.