Commit 33e449318865d6fe55e0f95288912b919ab6d125
1 parent
343523153b
Exists in
master
clear password input box if there's error
Showing 1 changed file with 3 additions and 0 deletions Inline Diff
scripts/LoginController.js
View file @
33e4493
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 = ''; | |||
} | 29 | 30 | } | |
console.log(data); | 30 | 31 | console.log(data); | |
}); | 31 | 32 | }); | |
}; | 32 | 33 | }; | |
$scope.signUp = function(email, password) { | 33 | 34 | $scope.signUp = function(email, password) { | |
$http.post('/api/register/', JSON.stringify({ | 34 | 35 | $http.post('/api/register/', JSON.stringify({ | |
'email': email, | 35 | 36 | 'email': email, | |
'password': password | 36 | 37 | 'password': password | |
})). | 37 | 38 | })). | |
success(function(data) { | 38 | 39 | success(function(data) { | |
UserService.login(data); | 39 | 40 | UserService.login(data); | |
if (angular.isDefined($scope.returnToState)) | 40 | 41 | if (angular.isDefined($scope.returnToState)) | |
$state.go($scope.returnToState.name, $scope.returnToStateParams); | 41 | 42 | $state.go($scope.returnToState.name, $scope.returnToStateParams); | |
else $state.go('addclass'); | 42 | 43 | else $state.go('addclass'); | |
43 | 44 | |||
}). | 44 | 45 | }). | |
error(function(data, status, headers, config) { | 45 | 46 | error(function(data, status, headers, config) { | |
console.log(data.email); | 46 | 47 | console.log(data.email); | |
if (data.email == 'This field is required.') { | 47 | 48 | if (data.email == 'This field is required.') { | |
$scope.invalid = true; | 48 | 49 | $scope.invalid = true; | |
$scope.uniqueError = false; | 49 | 50 | $scope.uniqueError = false; | |
} else if (data.email == 'This field must be unique.') { | 50 | 51 | } else if (data.email == 'This field must be unique.') { | |
// assume 'email not unique' error | 51 | 52 | // assume 'email not unique' error | |
$scope.uniqueError = true; | 52 | 53 | $scope.uniqueError = true; | |
$scope.invalid = false; | 53 | 54 | $scope.invalid = false; | |
} | 54 | 55 | } | |
56 | ||||
57 | $scope.registerPassword = ''; | |||
console.log(data); | 55 | 58 | console.log(data); | |
}); | 56 | 59 | }); | |
57 | 60 | |||
}; | 58 | 61 | }; | |
$scope.triggerPasswordReset = function() { | 59 | 62 | $scope.triggerPasswordReset = function() { | |
$state.go('requestpasswordreset'); | 60 | 63 | $state.go('requestpasswordreset'); | |
}; | 61 | 64 | }; | |
$(document).ready(function() { | 62 | 65 | $(document).ready(function() { |