Blame view

scripts/LoginController.js 2.1 KB
4da3dd303   Andrew Buss   Tried unbreaking ...
1
  angular.module('flashy.LoginController', ['ui.router']).
ce4a4542e   Rachel Lee   Changes to random...
2

80d1e57aa   Andrew Buss   materialized thin...
3
      controller('LoginController', ['$scope', '$state', '$http', 'UserService',
6fd36f978   Andrew Buss   autocomplete is w...
4
          function($scope, $state, $http, UserService) {
80d1e57aa   Andrew Buss   materialized thin...
5
6
7
8
              'use strict';
  
              $scope.uniqueError = false;
              $scope.loginError = false;
6fd36f978   Andrew Buss   autocomplete is w...
9
              $scope.login = function(email, password) {
80d1e57aa   Andrew Buss   materialized thin...
10
11
12
13
                  $http.post('/api/login', JSON.stringify({
                      'email': email,
                      'password': password
                  })).
6fd36f978   Andrew Buss   autocomplete is w...
14
                      success(function(data) {
80d1e57aa   Andrew Buss   materialized thin...
15
16
17
18
                          UserService.getUserData();
                          $state.go('feed');
                          console.log(data);
                      }).
6fd36f978   Andrew Buss   autocomplete is w...
19
                      error(function(data, status, header, config) {
80d1e57aa   Andrew Buss   materialized thin...
20
21
22
23
24
25
                          if (data.detail) { // assume 'invalid email or pass'
                              $scope.loginError = true;
                          }
                          console.log(data);
                      });
              };
6fd36f978   Andrew Buss   autocomplete is w...
26
              $scope.signUp = function(email, password) {
80d1e57aa   Andrew Buss   materialized thin...
27
28
29
30
                  $http.post('/api/register', JSON.stringify({
                      'email': email,
                      'password': password
                  })).
6fd36f978   Andrew Buss   autocomplete is w...
31
                      success(function(data) {
80d1e57aa   Andrew Buss   materialized thin...
32
33
34
                          $state.go('feed');
                          console.log(data);
                      }).
6fd36f978   Andrew Buss   autocomplete is w...
35
                      error(function(data, status, headers, config) {
80d1e57aa   Andrew Buss   materialized thin...
36
37
38
39
40
41
42
43
44
45
46
47
48
                          console.log(data.email);
                          if (data.email == 'This field is required.') {
                              $scope.invalid = true;
                              $scope.uniqueError = false;
                          } else if (data.email) {
                              // assume 'email not unique' error
                              $scope.uniqueError = true;
                              $scope.invalid = false;
                          }
                          console.log(data);
                      });
  
              };
6fd36f978   Andrew Buss   autocomplete is w...
49
              $scope.triggerPasswordReset = function() {
80d1e57aa   Andrew Buss   materialized thin...
50
51
52
53
                  $state.go('requestpasswordreset');
              };
          }
      ]);