diff --git a/scripts/RequestResetController.js b/scripts/RequestResetController.js index 892cefc..97fbf13 100644 --- a/scripts/RequestResetController.js +++ b/scripts/RequestResetController.js @@ -7,9 +7,8 @@ angular.module('flashy.RequestResetController', ['ui.router']). $http.post('/api/request_password_reset/', {email: email}). success(function(data) { $scope.success = true; - //$state.go('requestresetsuccess'); - console.log('SUCCESS'); - console.log(data); + Materialize.toast('A password reset link was sent to your email', 4000); + $state.go('login'); }). error(function(data, status, header, config) { if (data.email) { diff --git a/scripts/ResetPasswordController.js b/scripts/ResetPasswordController.js index 552d7f1..d29a429 100644 --- a/scripts/ResetPasswordController.js +++ b/scripts/ResetPasswordController.js @@ -1,54 +1,45 @@ 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'); - }; -}]); + controller('ResetPasswordController', function($scope, $state, $stateParams, $http, UserService) { + $scope.error = false; + $scope.success = false; + $scope.mismatch = false; + $scope.unacceptable = false; + + $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': $stateParams.uid, + 'token': $stateParams.token, + 'new_password': $scope.newPassword + })) + .success(function(data) { + $scope.error = false; + $scope.success = true; + UserService.startAuth().then(function() { + $state.go('login'); + }); + Materialize.toast('Your password was successfully changed', 4000); + }) + .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'); + }; + }); diff --git a/scripts/RootController.js b/scripts/RootController.js index e60cac6..2c57375 100644 --- a/scripts/RootController.js +++ b/scripts/RootController.js @@ -34,7 +34,7 @@ angular.module('flashy.RootController', ['ui.router', 'ngResource', 'ngSanitize' $('#classDropdown').toggle(); }) */ - + var postlogin = function(data) { $scope.user = data; //UserService.redirectToDefaultState($state); diff --git a/scripts/SettingsController.js b/scripts/SettingsController.js index 8394772..05f8c3b 100644 --- a/scripts/SettingsController.js +++ b/scripts/SettingsController.js @@ -27,7 +27,7 @@ angular.module('flashy.SettingsController', ['ui.router']). callback(true); } - console.log("gonna try to launch service worker now"); + console.log('gonna try to launch service worker now'); if ('serviceWorker' in navigator) { console.log('gonna try to launch service worker now'); @@ -55,4 +55,4 @@ angular.module('flashy.SettingsController', ['ui.router']). } - }); \ No newline at end of file + }); diff --git a/scripts/UserService.js b/scripts/UserService.js index f8364aa..1cb744e 100644 --- a/scripts/UserService.js +++ b/scripts/UserService.js @@ -19,15 +19,17 @@ angular.module('flashy.UserService', ['ui.router']). deferred.resolve(data); }; this.login = login; - $http.get('/api/me/').success(function(data) { - console.log('user is logged in!'); - login(data); - }).error(function(data) { - console.log(data); - console.log('not logged in yet: ' + data.detail); - _user = {email: false}; - deferred.resolve(_user); - }); + this.startAuth = function() { + return $http.get('/api/me/').success(function(data) { + console.log('user is logged in!'); + login(data); + }).error(function(data) { + console.log(data); + console.log('not logged in yet: ' + data.detail); + _user = {email: false}; + deferred.resolve(_user); + }); + }; this.isResolved = function() { return !!_user; @@ -102,4 +104,5 @@ angular.module('flashy.UserService', ['ui.router']). Materialize.toast('Resent confirmation email! Check your spam folder too.', 4000); }); }; + this.startAuth(); }); diff --git a/templates/requestpasswordreset.html b/templates/requestpasswordreset.html index ba15111..bb81577 100644 --- a/templates/requestpasswordreset.html +++ b/templates/requestpasswordreset.html @@ -1,39 +1,37 @@ -
-

Request sent!

-

Check your email in a few minutes.

-
+
+
+
+
-
-
-
- -
-

Reset Password

-
- -
-
-
-
- - Enter a valid email! +
+

Reset Password

+
+ +
+
+
+
+ + Enter a valid email! +
+
+ +
+ + +
-
- -
- - -
-
-
- - +
+ + +
+
- -
-
+
diff --git a/templates/resetpassword.html b/templates/resetpassword.html index 385580b..ba0cfcd 100644 --- a/templates/resetpassword.html +++ b/templates/resetpassword.html @@ -1,49 +1,47 @@ -
-

Reset password successful!

-
+
+
+
+
+
+

Reset Password

+
+
+
+ +
+ + Your password reset link is invalid. Perhaps it has already been used? +
+
+ + Passwords do not match! +
+
+ + Please make a password with at least 8 characters! +
+ +
+ + +
+
+ + +
+
-
-
-
-
- -
-

Reset Password

-
-
-
- -
- - Please check your reset password link! -
-
- - Passwords do not match! -
-
- - Please make a password with at least 8 characters! -
- -
- - -
-
- - -
-
- -
- - +
+ + + +
+
- -
-
-
+
\ No newline at end of file