resetPasswordCtrl.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. define([
  2. 'angular',
  3. '../core_module',
  4. ],
  5. function (angular, coreModule) {
  6. 'use strict';
  7. coreModule.controller('ResetPasswordCtrl', function($scope, contextSrv, backendSrv, $location) {
  8. contextSrv.sidemenu = false;
  9. $scope.formModel = {};
  10. $scope.mode = 'send';
  11. var params = $location.search();
  12. if (params.code) {
  13. $scope.mode = 'reset';
  14. $scope.formModel.code = params.code;
  15. }
  16. $scope.sendResetEmail = function() {
  17. if (!$scope.sendResetForm.$valid) {
  18. return;
  19. }
  20. backendSrv.post('/api/user/password/send-reset-email', $scope.formModel).then(function() {
  21. $scope.mode = 'email-sent';
  22. });
  23. };
  24. $scope.submitReset = function() {
  25. if (!$scope.resetForm.$valid) { return; }
  26. if ($scope.formModel.newPassword !== $scope.formModel.confirmPassword) {
  27. $scope.appEvent('alert-warning', ['New passwords do not match', '']);
  28. return;
  29. }
  30. backendSrv.post('/api/user/password/reset', $scope.formModel).then(function() {
  31. $location.path('login');
  32. });
  33. };
  34. });
  35. });