Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 29 additions & 28 deletions app/templates/client/app/main/main.controller(js).js
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
'use strict';

(function() {

function MainController($scope, $http<% if (filters.socketio) { %>, socket<% } %>) {
var self = this;
this.awesomeThings = [];

$http.get('/api/things').then(function(response) {
self.awesomeThings = response.data;<% if (filters.socketio) { %>
socket.syncUpdates('thing', self.awesomeThings);<% } %>
});
<% if (filters.models) { %>
this.addThing = function() {
if (self.newThing === '') {
return;
}
$http.post('/api/things', { name: self.newThing });
self.newThing = '';
};

this.deleteThing = function(thing) {
$http.delete('/api/things/' + thing._id);
};<% } %><% if (filters.socketio) { %>

$scope.$on('$destroy', function() {
socket.unsyncUpdates('thing');
});<% } %>
}

angular.module('<%= scriptAppName %>')
.controller('MainController', MainController);
function MainController($scope, $http<% if (filters.socketio) { %>, socket<% } %>) {
var self = this;
this.awesomeThings = [];

$http.get('/api/things').then(function(response) {
self.awesomeThings = response.data;<% if (filters.socketio) { %>
socket.syncUpdates('thing', self.awesomeThings);<% } %>
});<% if (filters.models) { %>

this.addThing = function() {
if (self.newThing === '') {
return;
}
$http.post('/api/things', { name: self.newThing });
self.newThing = '';
};

this.deleteThing = function(thing) {
$http.delete('/api/things/' + thing._id);
};<% } if (filters.socketio) { %>

$scope.$on('$destroy', function() {
socket.unsyncUpdates('thing');
});<% } %>
}

angular.module('<%= scriptAppName %>')
.controller('MainController', MainController);

})();
28 changes: 18 additions & 10 deletions app/templates/client/components/auth(auth)/auth.service(js).js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

angular.module('<%= scriptAppName %>')
.factory('Auth', function Auth($http, User, $cookies, $q) {
(function() {

function AuthService($http, User, $cookies, $q) {
/**
* Return a callback or noop function
*
Expand All @@ -18,7 +19,7 @@ angular.module('<%= scriptAppName %>')
currentUser = User.get();
}

return {
var Auth = {

/**
* Authenticate user and save token
Expand All @@ -42,10 +43,10 @@ angular.module('<%= scriptAppName %>')
return user;
})
.catch(function(err) {
this.logout();
Auth.logout();
safeCb(callback)(err.data);
return $q.reject(err.data);
}.bind(this));
});
},

/**
Expand All @@ -71,9 +72,9 @@ angular.module('<%= scriptAppName %>')
return safeCb(callback)(null, user);
},
function(err) {
this.logout();
Auth.logout();
return safeCb(callback)(err);
}.bind(this)).$promise;
}).$promise;
},

/**
Expand Down Expand Up @@ -130,7 +131,7 @@ angular.module('<%= scriptAppName %>')
return currentUser.hasOwnProperty('role');
}

return this.getCurrentUser(null)
return Auth.getCurrentUser(null)
.then(function(user) {
var is = user.hasOwnProperty('role');
safeCb(callback)(is);
Expand All @@ -150,7 +151,7 @@ angular.module('<%= scriptAppName %>')
return currentUser.role === 'admin';
}

return this.getCurrentUser(null)
return Auth.getCurrentUser(null)
.then(function(user) {
var is = user.role === 'admin';
safeCb(callback)(is);
Expand All @@ -167,4 +168,11 @@ angular.module('<%= scriptAppName %>')
return $cookies.get('token');
}
};
});

return Auth;
}

angular.module('<%= scriptAppName %>')
.factory('Auth', AuthService);

})();