client/app/auth/auth_controller.js
changeset 169 76fb2dd72ce4
parent 113 b8400d8efac8
child 172 ffdfe491869c
--- a/client/app/auth/auth_controller.js	Thu Jun 11 15:36:07 2015 +0200
+++ b/client/app/auth/auth_controller.js	Thu Jun 11 15:36:42 2015 +0200
@@ -1,7 +1,7 @@
 (function(){
     'use strict';
 
-    angular.module('ammicoAuth',['ngRoute'])
+    angular.module('ammicoAuth',['ngRoute', 'ngMessages'])
     .controller('authCtrl', function($location, $rootScope, $routeParams, $modal){
         $modal.open({
             templateUrl: 'auth/' + $routeParams.action + '_modal.html',
@@ -37,16 +37,49 @@
         };
     })
     .controller('authregisterCtrl', function($scope, $modalInstance, authApi){
-        $scope.register = function () {
-            authApi.user.save({
-                email: $scope.email,
-                password: $scope.password,
-            }, function(){
-                $modalInstance.close('/auth/login');
-            });
+        $scope.message = "";
+
+        $scope.user = {
+            email: "",
+            password: "",
+            confirmPassword: ""
+        };
+
+        $scope.submit = function(isValid) {
+            console.log(isValid);
+            console.log($scope);
+            console.log($scope.email);
+            if (isValid) {
+                authApi.user.save({
+                    email: $scope.user.email,
+                    password: $scope.user.password,
+                }, function(){
+                    $modalInstance.close('/auth/login');
+                });
+            } else {
+                $scope.message = "Il reste toujours des champs invalides";
+            }
         };
         $scope.back = function () {
             $modalInstance.close('/auth/login');
         };
+    })
+    .directive("compareTo", function(){
+        return {
+            require: "ngModel",
+            scope: {
+              otherModelValue: "=compareTo"
+            },
+            link: function($scope, element, attributes, ngModel) {
+
+              ngModel.$validators.compareTo = function(modelValue) {
+                return modelValue == $scope.otherModelValue;
+              };
+
+              $scope.$watch("otherModelValue", function() {
+                  ngModel.$validate();
+              });
+            }
+        }
     });
 })();