TwoToc code
[YouAndWeb_TwoToc] / client / app / account / login / login.controller.js
diff --git a/client/app/account/login/login.controller.js b/client/app/account/login/login.controller.js
new file mode 100755 (executable)
index 0000000..a756b30
--- /dev/null
@@ -0,0 +1,29 @@
+'use strict';
+
+angular.module('dashboardApp')
+  .controller('LoginCtrl', function($scope, Auth, $state, $window) {
+    $scope.user = {};
+    $scope.errors = {};
+
+    $scope.login = function(form) {
+      $scope.submitted = true;
+
+      if (form.$valid) {
+        Auth.login({
+          email: $scope.user.email,
+          password: $scope.user.password
+        })
+        .then(function() {
+          // Logged in, redirect to home
+          $state.go('main');
+        })
+        .catch(function(err) {
+          $scope.errors.other = err.message;
+        });
+      }
+    };
+
+    $scope.loginOauth = function(provider) {
+      $window.location.href = '/auth/' + provider;
+    };
+  });