mirror of
https://github.com/mmumshad/ansible-playable.git
synced 2025-02-13 18:51:54 +00:00
45 lines
967 B
JavaScript
45 lines
967 B
JavaScript
'use strict';
|
|
|
|
import angular from 'angular';
|
|
|
|
export default class SignupController {
|
|
user = {
|
|
name: '',
|
|
email: '',
|
|
password: ''
|
|
};
|
|
errors = {};
|
|
submitted = false;
|
|
|
|
|
|
/*@ngInject*/
|
|
constructor(Auth, $state) {
|
|
this.Auth = Auth;
|
|
this.$state = $state;
|
|
}
|
|
|
|
register(form) {
|
|
this.submitted = true;
|
|
|
|
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
|
|
this.$state.go('main');
|
|
})
|
|
.catch(err => {
|
|
err = err.data;
|
|
this.errors = {};
|
|
// 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;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|