|
1 | 1 | 'use strict'; |
| 2 | +// @flow |
| 3 | +<%_ if(filters.flow) { -%> |
| 4 | +type User = { |
| 5 | + name: string; |
| 6 | + email: string; |
| 7 | + password: string; |
| 8 | +}; |
| 9 | +<%_ } -%> |
| 10 | +<%_ if(filters.ts) { -%> |
| 11 | +interface User { |
| 12 | + name: string; |
| 13 | + email: string; |
| 14 | + password: string; |
| 15 | +} |
| 16 | +<%_ } -%> |
2 | 17 |
|
3 | 18 | export default class SignupController { |
4 | | - //start-non-standard |
5 | | - user = {}; |
| 19 | + user: User = { |
| 20 | + name: '', |
| 21 | + email: '', |
| 22 | + password: '' |
| 23 | + }; |
6 | 24 | errors = {}; |
7 | 25 | submitted = false; |
8 | | - //end-non-standard |
| 26 | + Auth; |
| 27 | + <%_ if(filters.ngroute) { -%> |
| 28 | + $location; |
| 29 | + <%_ } if(filters.uirouter) { -%> |
| 30 | + $state;<% } %> |
9 | 31 |
|
10 | 32 | /*@ngInject*/ |
11 | 33 | constructor(Auth<% if (filters.ngroute) { %>, $location<% } %><% if (filters.uirouter) { %>, $state<% } %>) { |
12 | | - this.Auth = Auth;<% if (filters.ngroute) { %> |
13 | | - this.$location = $location;<% } if (filters.uirouter) { %> |
| 34 | + this.Auth = Auth; |
| 35 | + <%_ if(filters.ngroute) { -%> |
| 36 | + this.$location = $location; |
| 37 | + <%_ } if(filters.uirouter) { -%> |
14 | 38 | this.$state = $state;<% } %> |
15 | 39 | } |
16 | 40 |
|
17 | 41 | register(form) { |
18 | 42 | this.submitted = true; |
19 | 43 |
|
20 | | - if (form.$valid) { |
21 | | - this.Auth.createUser({ |
| 44 | + if(form.$valid) { |
| 45 | + return this.Auth.createUser({ |
22 | 46 | name: this.user.name, |
23 | 47 | email: this.user.email, |
24 | 48 | password: this.user.password |
25 | 49 | }) |
26 | 50 | .then(() => { |
27 | 51 | // Account created, redirect to home |
28 | | - <% if (filters.ngroute) { %>this.$location.path('/');<% } %><% if (filters.uirouter) { %>this.$state.go('main');<% } %> |
| 52 | + <% if(filters.ngroute) { %>this.$location.path('/');<% } -%> |
| 53 | + <% if(filters.uirouter) { %>this.$state.go('main');<% } -%> |
29 | 54 | }) |
30 | 55 | .catch(err => { |
31 | 56 | err = err.data; |
32 | 57 | this.errors = {}; |
33 | | -<% if (filters.mongooseModels) { %> |
| 58 | + <%_ if(filters.mongooseModels) { -%> |
34 | 59 | // Update validity of form fields that match the mongoose errors |
35 | 60 | angular.forEach(err.errors, (error, field) => { |
36 | 61 | form[field].$setValidity('mongoose', false); |
37 | 62 | this.errors[field] = error.message; |
38 | | - });<% } |
39 | | -if (filters.sequelizeModels) { %> |
| 63 | + });<% } %> |
| 64 | + <%_ if(filters.sequelizeModels) { -%> |
40 | 65 | // Update validity of form fields that match the sequelize errors |
41 | | - if (err.name) { |
| 66 | + if(err.name) { |
42 | 67 | angular.forEach(err.fields, field => { |
43 | 68 | form[field].$setValidity('mongoose', false); |
44 | 69 | this.errors[field] = err.message; |
|
0 commit comments