'use strict';

angular.module('CactusApp.createUser', ['ngRoute'])

.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/register', {
    templateUrl: 'components/CreateUser/createUser.html',
    controller: 'createUser'
  });
}])

.controller('createUser', function($scope, $location, $rootScope, $firebaseAuth, $firebaseObject, userRef) {

  $scope.createUser = function createUser() {
    var user = $scope.data;
    var username = user.username;
    if (user.password === user.reTypePassword) {
      userRef.createUser({
        email: user.email,
        password: user.password
      }, function(error, userData) {
        if (error) {
          console.log("Error creating user:", error);
        } else {
          console.log("Successfully created user account with uid:", userData.uid);
        }
      });
      userRef.push({
        email: user.email,
        username: username,
        tasks: [''],
        group: ['']
      });
      $location.path('/creategroup')
    }
		else{
			//trow error on password match
			console.log('passwords dont match');
		}

  }


});

@@ -57,24 +57,28 @@
 ngRoute'%5D)%0A%0A
+    
 .config(%5B'$r
@@ -100,16 +100,17 @@
 function
+ 
 ($routeP
@@ -120,16 +120,22 @@
 ider) %7B%0A
+      
   $route
@@ -163,16 +163,24 @@
 ter', %7B%0A
+        
     temp
@@ -229,16 +229,24 @@
 .html',%0A
+        
     cont
@@ -270,19 +270,33 @@
 er'%0A
+      
   %7D);%0A
+    
 %7D%5D)%0A%0A
+    
 .con
@@ -325,16 +325,17 @@
 function
+ 
 ($scope,
@@ -401,13 +401,24 @@
 rRef
-) %7B%0A%0A
+, ref) %7B%0A%0A      
   $s
@@ -455,24 +455,32 @@
 ateUser() %7B%0A
+        
     var user
@@ -503,38 +503,12 @@
     
-var username = user.username;%0A
+    
     
@@ -548,24 +548,34 @@
 Password) %7B%0A
+          
       userRe
@@ -589,16 +589,28 @@
 eUser(%7B%0A
+            
         
@@ -620,32 +620,44 @@
 il: user.email,%0A
+            
         password
@@ -672,16 +672,26 @@
 assword%0A
+          
       %7D,
@@ -699,16 +699,17 @@
 function
+ 
 (error, 
@@ -724,24 +724,36 @@
 ) %7B%0A        
+      
+      
 if (error) %7B
@@ -749,24 +749,38 @@
 f (error) %7B%0A
+              
           co
@@ -833,17 +833,43 @@
     
-%7D else %7B%0A
+            %7D else %7B%0A              
     
@@ -960,20 +960,794 @@
     
-%7D%0A      %7D);%0A
+                authenticate();%0A                    %7D%0A                %7D);%0A                function authenticate() %7B%0A                    ref.authWithPassword(%7B%0A                        email: user.email,%0A                        password: user.password%0A                    %7D, function (error, authData) %7B%0A                        if (error) %7B%0A                            console.log(%22Login Failed!%22, error);%0A                        %7D else %7B%0A                            console.log(%22Authenticated successfully with payload:%22, authData);%0A                            addUserToRecord();%0A                        %7D%0A                    %7D);%0A                    console.log('auth')%0A                %7D%0A%0A                function addUserToRecord() %7B%0A                    console.log('add')%0A              
     
@@ -1763,16 +1763,32 @@
 .push(%7B%0A
+                
         
@@ -1798,32 +1798,48 @@
 il: user.email,%0A
+                
         username
@@ -1840,16 +1840,21 @@
 ername: 
+user.
 username
@@ -1855,16 +1855,32 @@
 ername,%0A
+                
         
@@ -1904,84 +1904,381 @@
     
-group: %5B''%5D%0A      %7D);%0A      $location.path('/creategroup')%0A    %7D%0A%09%09
+                group: %5B''%5D%0A                    %7D);%0A                    console.log('push')%0A                    console.log('move')%0A                %7D%0A                function move() %7B%0A%0A                    $location.path('/creategroup');%0A                    console.log($location)%0A                %7D%0A%0A                move();%0A            %7D%0A%0A            
 else
+ 
 %7B%0A
-%09%09%09
+                
 //tr
@@ -2308,11 +2308,24 @@
 tch%0A
-%09%09%09
+                
 cons
@@ -2361,19 +2361,39 @@
 ');%0A
-%09%09%7D%0A%0A  %7D%0A%0A%0A
+            %7D%0A%0A        %7D%0A%0A%0A    
 %7D);%0A

create user