TwoToc code
[YouAndWeb_TwoToc] / client / app / account / login / login.controller.js
1 'use strict';
2
3 angular.module('dashboardApp')
4   .controller('LoginCtrl', function($scope, Auth, $state, $window) {
5     $scope.user = {};
6     $scope.errors = {};
7
8     $scope.login = function(form) {
9       $scope.submitted = true;
10
11       if (form.$valid) {
12         Auth.login({
13           email: $scope.user.email,
14           password: $scope.user.password
15         })
16         .then(function() {
17           // Logged in, redirect to home
18           $state.go('main');
19         })
20         .catch(function(err) {
21           $scope.errors.other = err.message;
22         });
23       }
24     };
25
26     $scope.loginOauth = function(provider) {
27       $window.location.href = '/auth/' + provider;
28     };
29   });