ResetPasswordController.js
2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
angular.module('flashy.ResetPasswordController', ['ui.router']).
controller('ResetPasswordController', ['$scope', '$state', '$http', '$timeout',
function($scope, $state, $http, $timeout) {
'use strict';
var url = document.location.href.split('/');
var token = url[url.length - 1];
var uid = url[url.length - 2];
$scope.error = false;
$scope.success = false;
$scope.mismatch = false;
$scope.unacceptable = false;
/*if(token == 'resetpassword') {
$state.go('login');
}*/
console.log('RESETTING');
$scope.confirmResetPass = function() {
if ($scope.newPassword.length < 8) {
$scope.unacceptable = true;
return;
}
if ($scope.newPassword != $scope.confirmPassword) {
$scope.mismatch = true;
$scope.confirmPassword.$setPristine();
console.log('mismatch');
return;
}
/*password passes local tests*/
$http.post('/api/reset_password/', JSON.stringify({
'uid': uid,
'token': token,
'new_password': $scope.newPassword
}))
.success(function(data) {
$scope.error = false;
$scope.success = true;
//$state.go('resetpasssuccess');
$timeout(function($state) {
$state.go('login');
}, 1000);
console.log(data);
})
.error(function(data, status, header, config) {
$scope.error = true;
$scope.success = false;
$scope.mismatch = false;
$scope.unacceptable = false;
console.log(data);
});
};
$scope.cancelReset = function() {
$state.go('login');
};
}]);