--- /dev/null
+'use strict';
+
+angular.module('dashboardApp')
+ .controller('SignupCtrl', function($scope, Auth, $state, $window, datepickerPopupConfig) {
+ $scope.user = {};
+ $scope.errors = {};
+
+ $scope.$watch('user', function() {
+ $scope.user.name = $scope.user.firstName + ' ' + $scope.user.lastName;
+ }, true);
+
+ $scope.datepickers = {
+ birthDate: false
+ };
+
+ $scope.open = function($event, which, whichnot) {
+ $event.preventDefault();
+ $event.stopPropagation();
+
+ $scope.datepickers[which]= true;
+ $scope.datepickers[whichnot]= false;
+ };
+
+ $scope.dateOptions = {
+ 'year-format': 'yy',
+ 'starting-day': 1,
+ 'show-weeks': false
+ };
+
+ datepickerPopupConfig.showButtonBar = false;
+ datepickerPopupConfig.appendToBody = false;
+
+ $scope.minDate = new Date();
+ $scope.minDateFine = new Date();
+
+ $scope.register = function(form) {
+ $scope.submitted = true;
+
+ if (form.$valid) {
+ Auth.createUser({
+ name: $scope.user.name,
+ firstNname: $scope.user.firstName,
+ lastName: $scope.user.lastName,
+ birthDate: $scope.user.birthDate,
+ email: $scope.user.email,
+ password: $scope.user.password
+ })
+ .then(function() {
+ // Account created, redirect to home
+ $state.go('main');
+ })
+ .catch(function(err) {
+ err = err.data;
+ $scope.errors = {};
+
+ // Update validity of form fields that match the mongoose errors
+ angular.forEach(err.errors, function(error, field) {
+ form[field].$setValidity('mongoose', false);
+ $scope.errors[field] = error.message;
+ });
+ });
+ }
+ };
+
+ $scope.loginOauth = function(provider) {
+ $window.location.href = '/auth/' + provider;
+ };
+ });