diff --git a/app/templates/Gruntfile.js b/app/templates/Gruntfile.js index 1c3ad2bfc..aa62e5c13 100644 --- a/app/templates/Gruntfile.js +++ b/app/templates/Gruntfile.js @@ -589,7 +589,10 @@ module.exports = function (grunt) { // Compiles ES6 to JavaScript using Babel babel: { options: { - sourceMap: true + sourceMap: true, + optional: [ + 'es7.classProperties' + ] },<% if(filters.babel) { %> client: { files: [{ diff --git a/app/templates/client/.jshintrc b/app/templates/client/.jshintrc index 07b9d3793..9d0d57476 100644 --- a/app/templates/client/.jshintrc +++ b/app/templates/client/.jshintrc @@ -16,6 +16,9 @@ "strict": true, "trailing": true, "smarttabs": true, + "ignoreDelimiters": [ + { "start": "start-non-standard", "end": "end-non-standard" } + ], "globals": { "jQuery": true, "angular": true, diff --git a/app/templates/client/app/account(auth)/account.js b/app/templates/client/app/account(auth)/account.js index d60fd72fe..4266116fa 100644 --- a/app/templates/client/app/account(auth)/account.js +++ b/app/templates/client/app/account(auth)/account.js @@ -5,7 +5,8 @@ angular.module('<%= scriptAppName %>') $routeProvider .when('/login', { templateUrl: 'app/account/login/login.html', - controller: 'LoginCtrl' + controller: 'LoginController', + controllerAs: 'vm' }) .when('/logout', { name: 'logout', @@ -21,11 +22,13 @@ angular.module('<%= scriptAppName %>') }) .when('/signup', { templateUrl: 'app/account/signup/signup.html', - controller: 'SignupCtrl' + controller: 'SignupController', + controllerAs: 'vm' }) .when('/settings', { templateUrl: 'app/account/settings/settings.html', - controller: 'SettingsCtrl', + controller: 'SettingsController', + controllerAs: 'vm', authenticate: true }); }) @@ -40,7 +43,8 @@ angular.module('<%= scriptAppName %>') .state('login', { url: '/login', templateUrl: 'app/account/login/login.html', - controller: 'LoginCtrl' + controller: 'LoginController', + controllerAs: 'vm' }) .state('logout', { url: '/logout?referrer', @@ -57,12 +61,14 @@ angular.module('<%= scriptAppName %>') .state('signup', { url: '/signup', templateUrl: 'app/account/signup/signup.html', - controller: 'SignupCtrl' + controller: 'SignupController', + controllerAs: 'vm' }) .state('settings', { url: '/settings', templateUrl: 'app/account/settings/settings.html', - controller: 'SettingsCtrl', + controller: 'SettingsController', + controllerAs: 'vm', authenticate: true }); }) diff --git a/app/templates/client/app/account(auth)/login/login(html).html b/app/templates/client/app/account(auth)/login/login(html).html index ab1346ba6..a01d29342 100644 --- a/app/templates/client/app/account(auth)/login/login(html).html +++ b/app/templates/client/app/account(auth)/login/login(html).html @@ -8,29 +8,29 @@

Login

Admin account is admin@example.com / admin

-
+
- +
- +
-

+

Please enter your email and password.

-

+

Please enter a valid email.

-

{{ errors.other }}

+

{{ vm.errors.other }}

diff --git a/app/templates/client/app/account(auth)/login/login(jade).jade b/app/templates/client/app/account(auth)/login/login(jade).jade index 2352e8fad..04936ec48 100644 --- a/app/templates/client/app/account(auth)/login/login(jade).jade +++ b/app/templates/client/app/account(auth)/login/login(jade).jade @@ -17,18 +17,18 @@ navbar code admin .col-sm-12 - form.form(name='form', ng-submit='login(form)', novalidate='') + form.form(name='form', ng-submit='vm.login(form)', novalidate='') .form-group label Email - input.form-control(type='email', name='email', ng-model='user.email') + input.form-control(type='email', name='email', ng-model='vm.user.email') .form-group label Password - input.form-control(type='password', name='password', ng-model='user.password') + input.form-control(type='password', name='password', ng-model='vm.user.password') .form-group.has-error - p.help-block(ng-show='form.email.$error.required && form.password.$error.required && submitted') + p.help-block(ng-show='form.email.$error.required && form.password.$error.required && vm.submitted') | Please enter your email and password. - p.help-block {{ errors.other }} + p.help-block {{ vm.errors.other }} div button.btn.btn-inverse.btn-lg.btn-login(type='submit') diff --git a/app/templates/client/app/account(auth)/login/login.controller.js b/app/templates/client/app/account(auth)/login/login.controller.js index 6e9d5fd7b..2363aab8f 100644 --- a/app/templates/client/app/account(auth)/login/login.controller.js +++ b/app/templates/client/app/account(auth)/login/login.controller.js @@ -1,26 +1,36 @@ 'use strict'; -angular.module('<%= scriptAppName %>') - .controller('LoginCtrl', function($scope, Auth<% if (filters.ngroute) { %>, $location<% } %><% if (filters.uirouter) { %>, $state<% } %>) { - $scope.user = {}; - $scope.errors = {}; +class LoginController { + //start-non-standard + user = {}; + errors = {}; + submitted = false; + //end-non-standard + + constructor(Auth<% if (filters.ngroute) { %>, $location<% } %><% if (filters.uirouter) { %>, $state<% } %>) { + this.Auth = Auth;<% if (filters.ngroute) { %> + this.$location = $location;<% } if (filters.uirouter) { %> + this.$state = $state;<% } %> + } - $scope.login = function(form) { - $scope.submitted = true; + login(form) { + this.submitted = true; - if (form.$valid) { - Auth.login({ - email: $scope.user.email, - password: $scope.user.password - }) - .then(function() { - // Logged in, redirect to home - <% if (filters.ngroute) { %>$location.path('/');<% } %><% if (filters.uirouter) { %>$state.go('main');<% } %> - }) - .catch(function(err) { - $scope.errors.other = err.message; - }); - } - }; + if (form.$valid) { + this.Auth.login({ + email: this.user.email, + password: this.user.password + }) + .then(() => { + // Logged in, redirect to home + <% if (filters.ngroute) { %>this.$location.path('/');<% } %><% if (filters.uirouter) { %>this.$state.go('main');<% } %> + }) + .catch(err => { + this.errors.other = err.message; + }); + } + } +} - }); +angular.module('<%= scriptAppName %>') + .controller('LoginController', LoginController); diff --git a/app/templates/client/app/account(auth)/settings/settings(html).html b/app/templates/client/app/account(auth)/settings/settings(html).html index 92ee40aa4..d1d979a3c 100644 --- a/app/templates/client/app/account(auth)/settings/settings(html).html +++ b/app/templates/client/app/account(auth)/settings/settings(html).html @@ -6,26 +6,26 @@

Change Password

- +
-

- {{ errors.other }} + {{ vm.errors.other }}

-

+ ng-show="(form.newPassword.$error.minlength || form.newPassword.$error.required) && (form.newPassword.$dirty || vm.submitted)"> Password must be at least 3 characters.

@@ -33,18 +33,18 @@

Change Password

-

+ ng-show="form.confirmPassword.$error.match && vm.submitted"> Passwords must match.

-

{{ message }}

+

{{ vm.message }}

diff --git a/app/templates/client/app/account(auth)/settings/settings(jade).jade b/app/templates/client/app/account(auth)/settings/settings(jade).jade index 701215380..8fe47801e 100644 --- a/app/templates/client/app/account(auth)/settings/settings(jade).jade +++ b/app/templates/client/app/account(auth)/settings/settings(jade).jade @@ -4,33 +4,33 @@ navbar .col-sm-12 h1 Change Password .col-sm-12 - form.form(name='form', ng-submit='changePassword(form)', novalidate='') + form.form(name='form', ng-submit='vm.changePassword(form)', novalidate='') .form-group label Current Password input.form-control(type='password' name='password' - ng-model='user.oldPassword' + ng-model='vm.user.oldPassword' mongoose-error='') p.help-block(ng-show='form.password.$error.mongoose') - | {{ errors.other }} + | {{ vm.errors.other }} .form-group label New Password input.form-control(type='password' name='newPassword' - ng-model='user.newPassword' + ng-model='vm.user.newPassword' ng-minlength='3', required='') - p.help-block(ng-show='(form.newPassword.$error.minlength || form.newPassword.$error.required) && (form.newPassword.$dirty || submitted)') + p.help-block(ng-show='(form.newPassword.$error.minlength || form.newPassword.$error.required) && (form.newPassword.$dirty || vm.submitted)') | Password must be at least 3 characters. .form-group label Confirm New Password input.form-control(type='password' name='confirmPassword' - ng-model='user.confirmPassword' - match="user.newPassword" + ng-model='vm.user.confirmPassword' + match="vm.user.newPassword" ng-minlength='3', required='') - p.help-block(ng-show='form.confirmPassword.$error.match && submitted') + p.help-block(ng-show='fvm.orm.confirmPassword.$error.match && vm.submitted') | Passwords must match. - p.help-block {{ message }} + p.help-block {{ vm.message }} button.btn.btn-lg.btn-primary(type='submit') Save changes diff --git a/app/templates/client/app/account(auth)/settings/settings.controller.js b/app/templates/client/app/account(auth)/settings/settings.controller.js index eeb1219cf..379ccc506 100644 --- a/app/templates/client/app/account(auth)/settings/settings.controller.js +++ b/app/templates/client/app/account(auth)/settings/settings.controller.js @@ -1,21 +1,31 @@ 'use strict'; -angular.module('<%= scriptAppName %>') - .controller('SettingsCtrl', function($scope, User, Auth) { - $scope.errors = {}; +class SettingsController { + //start-non-standard + errors = {}; + submitted = false; + //end-non-standard + + constructor(Auth) { + this.Auth = Auth; + } + + changePassword(form) { + this.submitted = true; - $scope.changePassword = function(form) { - $scope.submitted = true; - if (form.$valid) { - Auth.changePassword($scope.user.oldPassword, $scope.user.newPassword) - .then(function() { - $scope.message = 'Password successfully changed.'; - }) - .catch(function() { - form.password.$setValidity('mongoose', false); - $scope.errors.other = 'Incorrect password'; - $scope.message = ''; - }); - } - }; - }); + if (form.$valid) { + this.Auth.changePassword(this.user.oldPassword, this.user.newPassword) + .then(() => { + this.message = 'Password successfully changed.'; + }) + .catch(() => { + form.password.$setValidity('mongoose', false); + this.errors.other = 'Incorrect password'; + this.message = ''; + }); + } + } +} + +angular.module('<%= scriptAppName %>') + .controller('SettingsController', SettingsController); diff --git a/app/templates/client/app/account(auth)/signup/signup(html).html b/app/templates/client/app/account(auth)/signup/signup(html).html index 84f4451e0..a23fe43a6 100644 --- a/app/templates/client/app/account(auth)/signup/signup(html).html +++ b/app/templates/client/app/account(auth)/signup/signup(html).html @@ -6,62 +6,62 @@

Sign up

-
+ -
+
- -

+

A name is required

-
+
- -

+

Doesn't look like a valid email.

-

+

What's your email address?

- {{ errors.email }} + {{ vm.errors.email }}

-
+
-

+ ng-show="(form.password.$error.minlength || form.password.$error.required) && vm.submitted"> Password must be at least 3 characters.

- {{ errors.password }} + {{ vm.errors.password }}

-
+
-

+ ng-show="form.confirmPassword.$error.match && vm.submitted"> Passwords must match.

diff --git a/app/templates/client/app/account(auth)/signup/signup(jade).jade b/app/templates/client/app/account(auth)/signup/signup(jade).jade index 139dd2941..1d9d547ff 100644 --- a/app/templates/client/app/account(auth)/signup/signup(jade).jade +++ b/app/templates/client/app/account(auth)/signup/signup(jade).jade @@ -4,47 +4,48 @@ navbar .col-sm-12 h1 Sign up .col-sm-12 - form.form(name='form', ng-submit='register(form)', novalidate='') - .form-group(ng-class='{ "has-success": form.name.$valid && submitted,\ - "has-error": form.name.$invalid && submitted }') + form.form(name='form', ng-submit='vm.register(form)', novalidate='') + .form-group(ng-class='{ "has-success": form.name.$valid && vm.submitted,\ + "has-error": form.name.$invalid && vm.submitted }') label Name - input.form-control(type='text', name='name', ng-model='user.name', required='') - p.help-block(ng-show='form.name.$error.required && submitted') + input.form-control(type='text', name='name', ng-model='vm.user.name', required='') + p.help-block(ng-show='form.name.$error.required && vm.submitted') | A name is required - .form-group(ng-class='{ "has-success": form.email.$valid && submitted,\ - "has-error": form.email.$invalid && submitted }') + .form-group(ng-class='{ "has-success": form.email.$valid && vm.submitted,\ + "has-error": form.email.$invalid && vm.submitted }') label Email - input.form-control(type='email', name='email', ng-model='user.email', required='', mongoose-error='') - p.help-block(ng-show='form.email.$error.email && submitted') + input.form-control(type='email', name='email', ng-model='vm.user.email', required='', mongoose-error='') + p.help-block(ng-show='form.email.$error.email && vm.submitted') | Doesn't look like a valid email. - p.help-block(ng-show='form.email.$error.required && submitted') + p.help-block(ng-show='form.email.$error.required && vm.submitted') | What's your email address? p.help-block(ng-show='form.email.$error.mongoose') - | {{ errors.email }} + | {{ vm.errors.email }} - .form-group(ng-class='{ "has-success": form.password.$valid && submitted,\ - "has-error": form.password.$invalid && submitted }') + .form-group(ng-class='{ "has-success": form.password.$valid && vm.submitted,\ + "has-error": form.password.$invalid && vm.submitted }') label Password input.form-control(type='password' name='password' - ng-model='user.password' + ng-model='vm.user.password' mongoose-error='' ng-minlength='3', required='') - p.help-block(ng-show='(form.password.$error.minlength || form.password.$error.required) && submitted') + + p.help-block(ng-show='(form.password.$error.minlength || form.password.$error.required) && vm.submitted') | Password must be at least 3 characters. p.help-block(ng-show='form.password.$error.mongoose') - | {{ errors.password }} + | {{ vm.errors.password }} - .form-group(ng-class='{ "has-success": form.confirmPassword.$valid && submitted,\ - "has-error": form.confirmPassword.$invalid && submitted }') + .form-group(ng-class='{ "has-success": form.confirmPassword.$valid && vm.submitted,\ + "has-error": form.confirmPassword.$invalid && vm.submitted }') label Confirm Password input.form-control(type='password' name='confirmPassword' - ng-model='user.confirmPassword' - match="user.password" + ng-model='vm.user.confirmPassword' + match="vm.user.password" ng-minlength='3', required='') - p.help-block(ng-show='form.confirmPassword.$error.match && submitted') + p.help-block(ng-show='form.confirmPassword.$error.match && vm.submitted') | Passwords must match. div diff --git a/app/templates/client/app/account(auth)/signup/signup.controller.js b/app/templates/client/app/account(auth)/signup/signup.controller.js index 405461a1f..a6f83fb58 100644 --- a/app/templates/client/app/account(auth)/signup/signup.controller.js +++ b/app/templates/client/app/account(auth)/signup/signup.controller.js @@ -1,42 +1,52 @@ 'use strict'; -angular.module('<%= scriptAppName %>') - .controller('SignupCtrl', function($scope, Auth<% if (filters.ngroute) { %>, $location<% } %><% if (filters.uirouter) { %>, $state<% } %>) { - $scope.user = {}; - $scope.errors = {}; +class SignupController { + //start-non-standard + user = {}; + errors = {}; + submitted = false; + //end-non-standard + + constructor(Auth<% if (filters.ngroute) { %>, $location<% } %><% if (filters.uirouter) { %>, $state<% } %>) { + this.Auth = Auth;<% if (filters.ngroute) { %> + this.$location = $location;<% } if (filters.uirouter) { %> + this.$state = $state;<% } %> + } - $scope.register = function(form) { - $scope.submitted = true; + register(form) { + this.submitted = true; - if (form.$valid) { - Auth.createUser({ - name: $scope.user.name, - email: $scope.user.email, - password: $scope.user.password - }) - .then(function() { - // Account created, redirect to home - <% if (filters.ngroute) { %>$location.path('/');<% } %><% if (filters.uirouter) { %>$state.go('main');<% } %> - }) - .catch(function(err) { - err = err.data; - $scope.errors = {}; + if (form.$valid) { + this.Auth.createUser({ + name: this.user.name, + email: this.user.email, + password: this.user.password + }) + .then(() => { + // Account created, redirect to home + <% if (filters.ngroute) { %>this.$location.path('/');<% } %><% if (filters.uirouter) { %>this.$state.go('main');<% } %> + }) + .catch(err => { + err = err.data; + this.errors = {}; <% if (filters.mongooseModels) { %> - // Update validity of form fields that match the mongoose errors - angular.forEach(err.errors, function(error, field) { + // Update validity of form fields that match the mongoose errors + angular.forEach(err.errors, (error, field) => { + form[field].$setValidity('mongoose', false); + this.errors[field] = error.message; + });<% } +if (filters.sequelizeModels) { %> + // Update validity of form fields that match the sequelize errors + if (err.name) { + angular.forEach(err.fields, field => { form[field].$setValidity('mongoose', false); - $scope.errors[field] = error.message; - });<% } - if (filters.sequelizeModels) { %> - // Update validity of form fields that match the sequelize errors - if (err.name) { - angular.forEach(err.fields, function(field) { - form[field].$setValidity('mongoose', false); - $scope.errors[field] = err.message; - }); - }<% } %> - }); - } - }; + this.errors[field] = err.message; + }); + }<% } %> + }); + } + } +} - }); +angular.module('<%= scriptAppName %>') + .controller('SignupController', SignupController); diff --git a/app/templates/client/components/navbar/navbar(html).html b/app/templates/client/components/navbar/navbar(html).html index eda46b07a..06bcff0c6 100644 --- a/app/templates/client/components/navbar/navbar(html).html +++ b/app/templates/client/components/navbar/navbar(html).html @@ -1,7 +1,7 @@ -