Compare View

switch
from
...
to
 
Commits (2)

Diff

Showing 1 changed file Inline Diff

scripts/LoginController.js View file @ 4b54a81
angular.module('flashy.LoginController', ['ui.router']). 1 1 angular.module('flashy.LoginController', ['ui.router']).
2 2
controller('LoginController', ['$rootScope', '$scope', '$state', '$http', 'UserService', 3 3 controller('LoginController', ['$rootScope', '$scope', '$state', '$http', 'UserService',
function($rootScope, $scope, $state, $http, UserService) { 4 4 function($rootScope, $scope, $state, $http, UserService) {
'use strict'; 5 5 'use strict';
// If we're logged in, there's nothing to do here 6 6 // If we're logged in, there's nothing to do here
7 7
if (UserService.isLoggedIn()) { 8 8 if (UserService.isLoggedIn()) {
console.log('logged in already'); 9 9 console.log('logged in already');
UserService.redirectToDefaultState($state); 10 10 UserService.redirectToDefaultState($state);
} 11 11 }
$scope.uniqueError = false; 12 12 $scope.uniqueError = false;
$scope.loginError = false; 13 13 $scope.loginError = false;
$scope.login = function(email, password) { 14 14 $scope.login = function(email, password) {
$http.post('/api/login/', JSON.stringify({ 15 15 $http.post('/api/login/', JSON.stringify({
'email': email, 16 16 'email': email,
'password': password 17 17 'password': password
})). 18 18 })).
success(function(data) { 19 19 success(function(data) {
UserService.login(data); 20 20 UserService.login(data);
if (angular.isDefined($scope.returnToState)) 21 21 if (angular.isDefined($scope.returnToState))
$state.go($scope.returnToState.name, $scope.returnToStateParams); 22 22 $state.go($scope.returnToState.name, $scope.returnToStateParams);
else 23 23 else
UserService.redirectToDefaultState($state); 24 24 UserService.redirectToDefaultState($state);
}). 25 25 }).
error(function(data, status, header, config) { 26 26 error(function(data, status, header, config) {
if (data.detail) { // assume 'invalid email or pass' 27 27 if (data.detail) { // assume 'invalid email or pass'
$scope.loginError = true; 28 28 $scope.loginError = true;
29 $scope.loginPassword = '';
$scope.loginPassword = ''; 29 30 }
} 30 31 console.log(data);
console.log(data); 31 32 });
}); 32 33 };
}; 33 34 $scope.signUp = function(email, password) {
$scope.signUp = function(email, password) { 34 35 $http.post('/api/register/', JSON.stringify({
$http.post('/api/register/', JSON.stringify({ 35 36 'email': email,
'email': email, 36 37 'password': password
'password': password 37 38 })).
})). 38 39 success(function(data) {
success(function(data) { 39 40 UserService.login(data);
UserService.login(data); 40 41 if (angular.isDefined($scope.returnToState))
if (angular.isDefined($scope.returnToState)) 41 42 $state.go($scope.returnToState.name, $scope.returnToStateParams);
$state.go($scope.returnToState.name, $scope.returnToStateParams); 42 43 else $state.go('addclass');
else $state.go('addclass'); 43 44
44 45 }).
}). 45 46 error(function(data, status, headers, config) {
error(function(data, status, headers, config) { 46 47 console.log(data.email);
console.log(data.email); 47 48 if (data.email == 'This field is required.') {
if (data.email == 'This field is required.') { 48 49 $scope.invalid = true;
$scope.invalid = true; 49 50 $scope.uniqueError = false;
$scope.uniqueError = false; 50 51 } else if (data.email == 'This field must be unique.') {
} else if (data.email == 'This field must be unique.') { 51 52 // assume 'email not unique' error
// assume 'email not unique' error 52 53 $scope.uniqueError = true;
$scope.uniqueError = true; 53 54 $scope.invalid = false;
$scope.invalid = false; 54 55 }
56
57 $scope.registerPassword = '';
} 55 58 console.log(data);
56 59 });
$scope.registerPassword = ''; 57 60
console.log(data); 58 61 };
}); 59 62 $scope.triggerPasswordReset = function() {
60 63 $state.go('requestpasswordreset');
}; 61 64 };
$scope.triggerPasswordReset = function() { 62 65 $(document).ready(function() {
$state.go('requestpasswordreset'); 63 66 $('ul.tabs').tabs();
}; 64 67 });