Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DaftMonk/generator-angular-fullstack
Browse files Browse the repository at this point in the history
  • Loading branch information
DaftMonk committed Jul 17, 2014
2 parents 05f7f43 + 71f80ce commit 8170796
Show file tree
Hide file tree
Showing 16 changed files with 186 additions and 170 deletions.
66 changes: 33 additions & 33 deletions app/templates/client/app/account(auth)/account(coffee).coffee
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
'use strict'

angular.module('<%= scriptAppName %>')
<% if(filters.ngroute) { %>.config ($routeProvider) ->
$routeProvider
.when('/login',
templateUrl: 'app/account/login/login.html'
controller: 'LoginCtrl'
)
.when('/signup',
templateUrl: 'app/account/signup/signup.html'
controller: 'SignupCtrl'
)
.when('/settings',
templateUrl: 'app/account/settings/settings.html'
controller: 'SettingsCtrl',
authenticate: true
)<% } %><% if(filters.uirouter) { %>.config ($stateProvider) ->
$stateProvider
.state('login',
url: '/login',
templateUrl: 'app/account/login/login.html'
controller: 'LoginCtrl'
)
.state('signup',
url: '/signup',
templateUrl: 'app/account/signup/signup.html'
controller: 'SignupCtrl'
)
.state('settings',
url: '/settings',
templateUrl: 'app/account/settings/settings.html'
controller: 'SettingsCtrl',
authenticate: true
)<% } %>
angular.module '<%= scriptAppName %>'
<% if(filters.ngroute) { %>.config ($routeProvider) ->
$routeProvider
.when '/login',
templateUrl: 'app/account/login/login.html'
controller: 'LoginCtrl'

.when '/signup',
templateUrl: 'app/account/signup/signup.html'
controller: 'SignupCtrl'

.when '/settings',
templateUrl: 'app/account/settings/settings.html'
controller: 'SettingsCtrl'
authenticate: true
<% } %><% if(filters.uirouter) { %>.config ($stateProvider) ->
$stateProvider
.state 'login',
url: '/login'
templateUrl: 'app/account/login/login.html'
controller: 'LoginCtrl'

.state 'signup',
url: '/signup'
templateUrl: 'app/account/signup/signup.html'
controller: 'SignupCtrl'

.state 'settings',
url: '/settings'
templateUrl: 'app/account/settings/settings.html'
controller: 'SettingsCtrl'
authenticate: true
<% } %>
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
'use strict'

angular.module('<%= scriptAppName %>').controller 'LoginCtrl', ($scope, Auth, $location, $window) ->
angular.module '<%= scriptAppName %>'
.controller 'LoginCtrl', ($scope, Auth, $location, $window) ->
$scope.user = {}
$scope.errors = {}
$scope.login = (form) ->
$scope.submitted = true

if form.$valid
# Logged in, redirect to home
Auth.login(
Auth.login
email: $scope.user.email
password: $scope.user.password
).then(->

.then ->
$location.path '/'
).catch (err) ->

.catch (err) ->
$scope.errors.other = err.message

$scope.loginOauth = (provider) ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
'use strict'

angular.module('<%= scriptAppName %>').controller 'SettingsCtrl', ($scope, User, Auth) ->
angular.module '<%= scriptAppName %>'
.controller 'SettingsCtrl', ($scope, User, Auth) ->
$scope.errors = {}
$scope.changePassword = (form) ->
$scope.submitted = true

if form.$valid
Auth.changePassword($scope.user.oldPassword, $scope.user.newPassword).then(->
Auth.changePassword $scope.user.oldPassword, $scope.user.newPassword
.then ->
$scope.message = 'Password successfully changed.'
).catch ->

.catch ->
form.password.$setValidity 'mongoose', false
$scope.errors.other = 'Incorrect password'
$scope.message = ''
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
'use strict'

angular.module('<%= scriptAppName %>').controller 'SignupCtrl', ($scope, Auth, $location, $window) ->
angular.module '<%= scriptAppName %>'
.controller 'SignupCtrl', ($scope, Auth, $location, $window) ->
$scope.user = {}
$scope.errors = {}
$scope.register = (form) ->
$scope.submitted = true

if form.$valid
# Account created, redirect to home
Auth.createUser(
Auth.createUser
name: $scope.user.name
email: $scope.user.email
password: $scope.user.password
).then(->

.then ->
$location.path '/'

).catch (err) ->
.catch (err) ->
err = err.data
$scope.errors = {}

Expand Down
26 changes: 13 additions & 13 deletions app/templates/client/app/admin(auth)/admin(coffee).coffee
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict'

angular.module('<%= scriptAppName %>')
<% if(filters.ngroute) { %>.config ($routeProvider) ->
$routeProvider
.when('/admin',
templateUrl: 'app/admin/admin.html'
controller: 'AdminCtrl'
)<% } %><% if(filters.uirouter) { %>.config ($stateProvider) ->
$stateProvider
.state('admin',
url: '/admin',
templateUrl: 'app/admin/admin.html'
controller: 'AdminCtrl'
)<% } %>
angular.module '<%= scriptAppName %>'
<% if(filters.ngroute) { %>.config ($routeProvider) ->
$routeProvider
.when '/admin',
templateUrl: 'app/admin/admin.html'
controller: 'AdminCtrl'
<% } %><% if(filters.uirouter) { %>.config ($stateProvider) ->
$stateProvider
.state 'admin',
url: '/admin'
templateUrl: 'app/admin/admin.html'
controller: 'AdminCtrl'
<% } %>
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use strict'

angular.module('<%= scriptAppName %>').controller 'AdminCtrl', ($scope, $http, Auth, User) ->
$http.get('/api/users').success (users) ->
angular.module '<%= scriptAppName %>'
.controller 'AdminCtrl', ($scope, $http, Auth, User) ->

$http.get '/api/users'
.success (users) ->
$scope.users = users

$scope.delete = (user) ->
User.remove id: user._id
angular.forEach $scope.users, (u, i) ->
$scope.users.splice i, 1 if u is user
$scope.users.splice i, 1 if u is user
69 changes: 34 additions & 35 deletions app/templates/client/app/app(coffee).coffee
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
'use strict'

angular.module('<%= scriptAppName %>', [<%= angularModules %>])
<% if(filters.ngroute) { %>.config (($routeProvider, $locationProvider<% if(filters.auth) { %>, $httpProvider<% } %>) ->
$routeProvider
.otherwise
redirectTo: '/'
angular.module '<%= scriptAppName %>', [<%= angularModules %>]
<% if(filters.ngroute) { %>.config ($routeProvider, $locationProvider<% if(filters.auth) { %>, $httpProvider<% } %>) ->
$routeProvider
.otherwise
redirectTo: '/'

$locationProvider.html5Mode true<% if(filters.auth) { %>
$httpProvider.interceptors.push 'authInterceptor'<% } %>
)<% } %><% if(filters.uirouter) { %>.config (($stateProvider, $urlRouterProvider, $locationProvider<% if(filters.auth) { %>, $httpProvider<% } %>) ->
$urlRouterProvider
.otherwise('/')
$locationProvider.html5Mode true<% if(filters.auth) { %>
$httpProvider.interceptors.push 'authInterceptor'<% } %>
<% } %><% if(filters.uirouter) { %>.config ($stateProvider, $urlRouterProvider, $locationProvider<% if(filters.auth) { %>, $httpProvider<% } %>) ->
$urlRouterProvider
.otherwise '/'

$locationProvider.html5Mode true<% if(filters.auth) { %>
$httpProvider.interceptors.push 'authInterceptor'<% } %>
)<% } %><% if(filters.auth) { %>
.factory('authInterceptor', ($rootScope, $q, $cookieStore, $location) ->
# Add authorization token to headers
request: (config) ->
config.headers = config.headers or {}
config.headers.Authorization = 'Bearer ' + $cookieStore.get('token') if $cookieStore.get('token')
config
$locationProvider.html5Mode true<% if(filters.auth) { %>
$httpProvider.interceptors.push 'authInterceptor'<% } %>
<% } %><% if(filters.auth) { %>
.factory 'authInterceptor', ($rootScope, $q, $cookieStore, $location) ->
# Add authorization token to headers
request: (config) ->
config.headers = config.headers or {}
config.headers.Authorization = 'Bearer ' + $cookieStore.get 'token' if $cookieStore.get 'token'
config

# Intercept 401s and redirect you to login
responseError: (response) ->
if response.status is 401
$location.path '/login'
# remove any stale tokens
$cookieStore.remove 'token'
$q.reject response
else
$q.reject response
)
.run (($rootScope, $location, Auth) ->
# Redirect to login if route requires auth and you're not logged in
$rootScope.$on <% if(filters.ngroute) { %>'$routeChangeStart'<% } %><% if(filters.uirouter) { %>'$stateChangeStart'<% } %>, (event, next) ->
Auth.isLoggedInAsync (loggedIn) ->
$location.path "/login" if next.authenticate and not loggedIn
)<% } %>
# Intercept 401s and redirect you to login
responseError: (response) ->
if response.status is 401
$location.path '/login'
# remove any stale tokens
$cookieStore.remove 'token'

$q.reject response

.run ($rootScope, $location, Auth) ->
# Redirect to login if route requires auth and you're not logged in
$rootScope.$on <% if(filters.ngroute) { %>'$routeChangeStart'<% } %><% if(filters.uirouter) { %>'$stateChangeStart'<% } %>, (event, next) ->
Auth.isLoggedInAsync (loggedIn) ->
$location.path "/login" if next.authenticate and not loggedIn
<% } %>
26 changes: 13 additions & 13 deletions app/templates/client/app/main/main(coffee).coffee
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict'

angular.module('<%= scriptAppName %>')
<% if(filters.ngroute) { %>.config ($routeProvider) ->
$routeProvider
.when('/',
templateUrl: 'app/main/main.html'
controller: 'MainCtrl'
)<% } %><% if(filters.uirouter) { %>.config ($stateProvider) ->
$stateProvider
.state('main',
url: '/',
templateUrl: 'app/main/main.html'
controller: 'MainCtrl'
)<% } %>
angular.module '<%= scriptAppName %>'
<% if(filters.ngroute) { %>.config ($routeProvider) ->
$routeProvider
.when '/',
templateUrl: 'app/main/main.html'
controller: 'MainCtrl'
<% } %><% if(filters.uirouter) { %>.config ($stateProvider) ->
$stateProvider
.state 'main',
url: '/'
templateUrl: 'app/main/main.html'
controller: 'MainCtrl'
<% } %>
3 changes: 2 additions & 1 deletion app/templates/client/app/main/main.controller(coffee).coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

angular.module('<%= scriptAppName %>').controller 'MainCtrl', ($scope, $http<% if(filters.socketio) { %>, socket<% } %>) ->
angular.module '<%= scriptAppName %>'
.controller 'MainCtrl', ($scope, $http<% if(filters.socketio) { %>, socket<% } %>) ->
$scope.awesomeThings = []

$http.get('/api/things').success (awesomeThings) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
describe 'Controller: MainCtrl', ->

# load the controller's module
beforeEach module('<%= scriptAppName %>')<% if(filters.socketio) {%>
beforeEach module('socketMock')<% } %>
beforeEach module '<%= scriptAppName %>' <% if(filters.socketio) {%>
beforeEach module 'socketMock' <% } %>

MainCtrl = undefined
scope = undefined
$httpBackend = undefined

# Initialize the controller and a mock scope
beforeEach inject((_$httpBackend_, $controller, $rootScope) ->
beforeEach inject (_$httpBackend_, $controller, $rootScope) ->
$httpBackend = _$httpBackend_
$httpBackend.expectGET('/api/things').respond [
'HTML5 Boilerplate'
Expand All @@ -20,10 +20,8 @@ describe 'Controller: MainCtrl', ->
'Express'
]
scope = $rootScope.$new()
MainCtrl = $controller('MainCtrl',
MainCtrl = $controller 'MainCtrl',
$scope: scope
)
)

it 'should attach a list of things to the scope', ->
$httpBackend.flush()
Expand Down
Loading

0 comments on commit 8170796

Please sign in to comment.