'use strict';

angular.module('users').controller('AuthenticationController', ['$scope', '$http', '$location', 'Authentication',
	function($scope, $http, $location, Authentication) {
		$scope.authentication = Authentication;

		// If user is signed in then redirect back home
		if ($scope.authentication.user) $location.path('/');

		$scope.signup = function() {
			$http.post('/auth/signup', $scope.credentials).success(function(response) {
				// If successful we assign the response to the global user model
				$scope.authentication.user = response;

				// And redirect to the index page
				$location.path('/');
			}).error(function(response) {
				if (response.message.errors) {
					var reduce = function(collection, reducer, memo) {
						for (var key in collection) {
							memo = reducer(memo, collection[key], key);
						}
						return memo;
					};

					$scope.error = reduce(response.message.errors, function(memo, value, key) {
						return memo + value.message + '.\n';
					}, '');
				} else {
					$scope.error = response.message;
				}
			});
		};

		$scope.signin = function() {
			$http.post('/auth/signin', $scope.credentials).success(function(response) {
				// If successful we assign the response to the global user model
				$scope.authentication.user = response;

				// And redirect to the index page
				$location.path('/');
			}).error(function(response) {
				$scope.error = response.message;
			});
		};
	}
]);
@@ -122,17 +122,18 @@
 ation',%0A
-%09
+  
 function
@@ -177,18 +177,20 @@
 tion) %7B%0A
-%09%09
+    
 $scope.a
@@ -222,18 +222,20 @@
 ation;%0A%0A
-%09%09
+    
 // If us
@@ -274,18 +274,20 @@
 ck home%0A
-%09%09
+    
 if ($sco
@@ -332,18 +332,20 @@
 ('/');%0A%0A
-%09%09
+    
 $scope.s
@@ -357,35 +357,38 @@
  = function() %7B%0A
-%09%09%09
+      
 $http.post('/aut
@@ -439,36 +439,40 @@
 ion(response) %7B%0A
-%09%09%09%09
+        
 // If successful
@@ -512,36 +512,40 @@
 obal user model%0A
-%09%09%09%09
+        
 $scope.authentic
@@ -560,36 +560,40 @@
 er = response;%0A%0A
-%09%09%09%09
+        
 // And redirect 
@@ -602,36 +602,40 @@
  the index page%0A
-%09%09%09%09
+        
 $location.path('
@@ -631,35 +631,38 @@
 tion.path('/');%0A
-%09%09%09
+      
 %7D).error(functio
@@ -675,20 +675,24 @@
 onse) %7B%0A
-%09%09%09%09
+        
 if (resp
@@ -714,21 +714,26 @@
 rors) %7B%0A
-%09%09%09%09%09
+          
 var redu
@@ -775,22 +775,28 @@
 memo) %7B%0A
-%09%09%09%09%09%09
+            
 for (var
@@ -821,15 +821,22 @@
 ) %7B%0A
-%09%09%09%09%09%09%09
+              
 memo
@@ -879,49 +879,71 @@
 y);%0A
-%09%09%09%09%09%09%7D%0A%09%09%09%09%09%09return memo;%0A%09%09%09%09%09%7D;%0A%0A%09%09%09%09%09
+            %7D%0A            return memo;%0A          %7D;%0A%0A          
 $sco
@@ -1018,14 +1018,20 @@
 ) %7B%0A
-%09%09%09%09%09%09
+            
 retu
@@ -1067,39 +1067,53 @@
 n';%0A
-%09%09%09%09%09%7D, '');%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09
+          %7D, '');%0A        %7D else %7B%0A          
 $sco
@@ -1145,29 +1145,40 @@
 ge;%0A
-%09%09%09%09%7D%0A%09%09%09%7D);%0A%09%09%7D;%0A%0A%09%09
+        %7D%0A      %7D);%0A    %7D;%0A%0A    
 $sco
@@ -1202,19 +1202,22 @@
 ion() %7B%0A
-%09%09%09
+      
 $http.po
@@ -1284,20 +1284,24 @@
 onse) %7B%0A
-%09%09%09%09
+        
 // If su
@@ -1357,20 +1357,24 @@
 r model%0A
-%09%09%09%09
+        
 $scope.a
@@ -1405,20 +1405,24 @@
 ponse;%0A%0A
-%09%09%09%09
+        
 // And r
@@ -1447,20 +1447,24 @@
 ex page%0A
-%09%09%09%09
+        
 $locatio
@@ -1476,19 +1476,22 @@
 h('/');%0A
-%09%09%09
+      
 %7D).error
@@ -1516,12 +1516,16 @@
 ) %7B%0A
-%09%09%09%09
+        
 $sco
@@ -1557,21 +1557,27 @@
 ge;%0A
-%09%09%09%7D);%0A%09%09%7D;%0A%09
+      %7D);%0A    %7D;%0A  
 %7D%0A%5D)

Convert tabs to spaces