diff --git a/templates/app/client/app/account(auth)/login/login(html).html b/templates/app/client/app/account(auth)/login/login(html).html index 76382615f..2f72c7268 100644 --- a/templates/app/client/app/account(auth)/login/login(html).html +++ b/templates/app/client/app/account(auth)/login/login(html).html @@ -28,7 +28,7 @@

Login

Please enter a valid email.

-

{{ vm.errors.other }}

+

{{ vm.errors.login }}

diff --git a/templates/app/client/app/account(auth)/login/login(jade).jade b/templates/app/client/app/account(auth)/login/login(jade).jade index c46f0e5eb..a463419d4 100644 --- a/templates/app/client/app/account(auth)/login/login(jade).jade +++ b/templates/app/client/app/account(auth)/login/login(jade).jade @@ -27,7 +27,7 @@ .form-group.has-error p.help-block(ng-show='form.email.$error.required && form.password.$error.required && vm.submitted') | Please enter your email and password. - p.help-block {{ vm.errors.other }} + p.help-block {{ vm.errors.login }} div button.btn.btn-inverse.btn-lg.btn-login(type='submit') diff --git a/templates/app/client/app/account(auth)/login/login.controller.js b/templates/app/client/app/account(auth)/login/login.controller.js index 1aa48e1e3..a6dd073a4 100644 --- a/templates/app/client/app/account(auth)/login/login.controller.js +++ b/templates/app/client/app/account(auth)/login/login.controller.js @@ -1,14 +1,40 @@ 'use strict'; +// @flow +<%_ if(filters.flow) { -%> +type User = { + name: string; + email: string; + password: string; +}; +<%_ } -%> +<%_ if(filters.ts) { -%> +interface User { + name: string; + email: string; + password: string; +} +<%_ } -%> export default class LoginController { + user: User = { + name: '', + email: '', + password: '' + }; + errors = {login: undefined}; + submitted = false; + Auth; + <%_ if(filters.ngroute) { -%> + $location; + <%_ } if(filters.uirouter) { -%> + $state;<% } %> + /*@ngInject*/ constructor(Auth<% if (filters.ngroute) { %>, $location<% } %><% if (filters.uirouter) { %>, $state<% } %>) { - this.user = {}; - this.errors = {}; - this.submitted = false; - - this.Auth = Auth;<% if (filters.ngroute) { %> - this.$location = $location;<% } if (filters.uirouter) { %> + this.Auth = Auth; + <%_ if(filters.ngroute) { -%> + this.$location = $location; + <%_ } if(filters.uirouter) { -%> this.$state = $state;<% } %> } @@ -25,7 +51,7 @@ export default class LoginController { <% if (filters.ngroute) { %>this.$location.path('/');<% } %><% if (filters.uirouter) { %>this.$state.go('main');<% } %> }) .catch(err => { - this.errors.other = err.message; + this.errors.login = err.message; }); } } diff --git a/templates/app/client/app/account(auth)/settings/settings.controller.js b/templates/app/client/app/account(auth)/settings/settings.controller.js index 976bd5154..d6316b7a5 100644 --- a/templates/app/client/app/account(auth)/settings/settings.controller.js +++ b/templates/app/client/app/account(auth)/settings/settings.controller.js @@ -1,8 +1,30 @@ 'use strict'; +// @flow +<%_ if(filters.flow) { -%> +type User = { + oldPassword: string; + newPassword: string; + confirmPassword: string; +}; +<%_ } -%> +<%_ if(filters.ts) { -%> +interface User { + oldPassword: string; + newPassword: string; + confirmPassword: string; +} +<%_ } -%> export default class SettingsController { - errors = {}; + user: User = { + oldPassword: '', + newPassword: '', + confirmPassword: '' + }; + errors = {other: undefined}; + message = ''; submitted = false; + Auth; /*@ngInject*/ constructor(Auth) { @@ -12,7 +34,7 @@ export default class SettingsController { changePassword(form) { this.submitted = true; - if (form.$valid) { + if(form.$valid) { this.Auth.changePassword(this.user.oldPassword, this.user.newPassword) .then(() => { this.message = 'Password successfully changed.'; diff --git a/templates/app/client/app/account(auth)/signup/signup.controller.js b/templates/app/client/app/account(auth)/signup/signup.controller.js index 6ae9064e4..196684c24 100644 --- a/templates/app/client/app/account(auth)/signup/signup.controller.js +++ b/templates/app/client/app/account(auth)/signup/signup.controller.js @@ -1,44 +1,69 @@ 'use strict'; +// @flow +<%_ if(filters.flow) { -%> +type User = { + name: string; + email: string; + password: string; +}; +<%_ } -%> +<%_ if(filters.ts) { -%> +interface User { + name: string; + email: string; + password: string; +} +<%_ } -%> export default class SignupController { - //start-non-standard - user = {}; + user: User = { + name: '', + email: '', + password: '' + }; errors = {}; submitted = false; - //end-non-standard + Auth; + <%_ if(filters.ngroute) { -%> + $location; + <%_ } if(filters.uirouter) { -%> + $state;<% } %> /*@ngInject*/ constructor(Auth<% if (filters.ngroute) { %>, $location<% } %><% if (filters.uirouter) { %>, $state<% } %>) { - this.Auth = Auth;<% if (filters.ngroute) { %> - this.$location = $location;<% } if (filters.uirouter) { %> + this.Auth = Auth; + <%_ if(filters.ngroute) { -%> + this.$location = $location; + <%_ } if(filters.uirouter) { -%> this.$state = $state;<% } %> } register(form) { this.submitted = true; - if (form.$valid) { - this.Auth.createUser({ + if(form.$valid) { + return 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');<% } %> + <% if(filters.ngroute) { %>this.$location.path('/');<% } -%> + <% if(filters.uirouter) { %>this.$state.go('main');<% } -%> }) .catch(err => { err = err.data; this.errors = {}; -<% if (filters.mongooseModels) { %> + <%_ if(filters.mongooseModels) { -%> // 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) { %> + });<% } %> + <%_ if(filters.sequelizeModels) { -%> // Update validity of form fields that match the sequelize errors - if (err.name) { + if(err.name) { angular.forEach(err.fields, field => { form[field].$setValidity('mongoose', false); this.errors[field] = err.message; diff --git a/templates/app/client/app/main/main.component.js b/templates/app/client/app/main/main.component.js index fab99e6a3..a1dc2479a 100644 --- a/templates/app/client/app/main/main.component.js +++ b/templates/app/client/app/main/main.component.js @@ -7,12 +7,18 @@ import uiRouter from 'angular-ui-router';<% } _%> import routing from './main.routes'; export class MainController { + $http; + <%_ if(filters.socketio) { -%> + socket;<% } %> + awesomeThings = []; + <%_ if(filters.models) { -%> + newThing = '';<% } %> + /*@ngInject*/ constructor($http<% if(filters.socketio) { %>, $scope, socket<% } %>) { - this.$http = $http;<% if (filters.socketio) { %> - this.socket = socket;<% } %> - this.awesomeThings = []; - <%_ if (filters.socketio) { _%> + this.$http = $http; + <%_ if(filters.socketio) { -%> + this.socket = socket; $scope.$on('$destroy', function() { socket.unsyncUpdates('thing'); diff --git a/templates/app/client/components/auth(auth)/auth.service.js b/templates/app/client/components/auth(auth)/auth.service.js index 2e3bb33a9..87a0adb2f 100644 --- a/templates/app/client/components/auth(auth)/auth.service.js +++ b/templates/app/client/components/auth(auth)/auth.service.js @@ -1,10 +1,17 @@ 'use strict'; // @flow +class User { + _id: string = ''; + name: string = ''; + email: string = ''; + role: string = ''; + $promise = undefined; +} export function AuthService($location, $http, $cookies, $q, appConfig, Util, User) { 'ngInject'; var safeCb = Util.safeCb; - var currentUser = {}; + var currentUser: User = new User(); var userRoles = appConfig.userRoles || []; /** * Check if userRole is >= role @@ -25,10 +32,10 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use * Authenticate user and save token * * @param {Object} user - login info - * @param {Function} callback - optional, function(error, user) + * @param {Function} callback - function(error, user) * @return {Promise} */ - login({email, password}, callback: Function) { + login({email, password}, callback?: Function) { return $http.post('/auth/local', { email, password }) .then(res => { $cookies.put('token', res.data.token); @@ -51,17 +58,17 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use */ logout() { $cookies.remove('token'); - currentUser = {}; + currentUser = new User(); }, /** * Create a new user * * @param {Object} user - user info - * @param {Function} callback - optional, function(error, user) + * @param {Function} callback - function(error, user) * @return {Promise} */ - createUser(user, callback) { + createUser(user, callback?: Function) { return User.save(user, function(data) { $cookies.put('token', data.token); @@ -79,10 +86,10 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use * * @param {String} oldPassword * @param {String} newPassword - * @param {Function} callback - optional, function(error, user) + * @param {Function} callback - function(error, user) * @return {Promise} */ - changePassword(oldPassword, newPassword, callback) { + changePassword(oldPassword, newPassword, callback?: Function) { return User.changePassword({ id: currentUser._id }, { oldPassword, newPassword }, function() { return safeCb(callback)(null); }, function(err) { @@ -93,10 +100,10 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use /** * Gets all available info on a user * - * @param {Function} [callback] - funciton(user) + * @param {Function} [callback] - function(user) * @return {Promise} */ - getCurrentUser(callback) { + getCurrentUser(callback?: Function) { var value = currentUser.hasOwnProperty('$promise') ? currentUser.$promise : currentUser; @@ -124,10 +131,10 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use * Check if a user is logged in * * @param {Function} [callback] - function(is) - * @return {Bool|Promise} + * @return {Promise} */ - isLoggedIn(callback) { - return Auth.getCurrentUser() + isLoggedIn(callback?: Function) { + return Auth.getCurrentUser(undefined) .then(user => { var is = user.hasOwnProperty('role'); safeCb(callback)(is); @@ -149,10 +156,10 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use * * @param {String} role - the role to check against * @param {Function} [callback] - function(has) - * @return {Bool|Promise} + * @return {Promise} */ - hasRole(role, callback) { - return Auth.getCurrentUser() + hasRole(role, callback?: Function) { + return Auth.getCurrentUser(undefined) .then(user => { var has = user.hasOwnProperty('role') ? hasRole(user.role, role) diff --git a/templates/app/client/components/navbar/navbar.component.js b/templates/app/client/components/navbar/navbar.component.js index 1e9c3ad9d..6a6d37282 100644 --- a/templates/app/client/components/navbar/navbar.component.js +++ b/templates/app/client/components/navbar/navbar.component.js @@ -1,14 +1,19 @@ 'use strict'; export class NavbarComponent { - //start-non-standard menu = [{ 'title': 'Home', <% if (filters.uirouter) { %>'state': 'main'<% } else { %>'link': '/'<% } %> }]; - + <%_ if(!filters.uirouter) { -%> + $location; + <%_ } -%> + <%_ if (filters.auth) { -%> + isLoggedIn: Function; + isAdmin: Function; + getCurrentUser: Function; + <%_ } -%> isCollapsed = true; - //end-non-standard <%_ if(filters.ngroute || filters.auth) { _%> constructor(<% if(!filters.uirouter) { %>$location<% } if(!filters.uirouter && filters.auth) { %>, <% } if (filters.auth) { %>Auth<% } %>) {