From 076dcd1a7fe72adc37e56b8af1d7af1015a6750a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yves=20M=C3=BCller?= Date: Thu, 20 Oct 2016 13:56:33 +0200 Subject: [PATCH 1/3] Fix error in adhcoracy service --- app/modules/adhocracyEmbedder/services/adhocracy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/modules/adhocracyEmbedder/services/adhocracy.js b/app/modules/adhocracyEmbedder/services/adhocracy.js index 0a36f88b..cf62fb6e 100644 --- a/app/modules/adhocracyEmbedder/services/adhocracy.js +++ b/app/modules/adhocracyEmbedder/services/adhocracy.js @@ -99,7 +99,7 @@ angular.module('pcApp.adhocracyEmbedder.services.adhocracy', []) for (errorIndex in serverErrors) { if (serverErrors.hasOwnProperty(errorIndex)) { var error = serverErrors[errorIndex]; - if (error.location = 'body') { + if (error.location === 'body') { simpleName = error.name.split('.').pop(); processedErrors[simpleName] = error.description; } From ff6c7cb196097ff0a30a89524c030f588564d982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yves=20M=C3=BCller?= Date: Thu, 20 Oct 2016 13:56:58 +0200 Subject: [PATCH 2/3] Fix floating html close tags in login/register --- app/modules/auth/partials/login.html | 1 - app/modules/auth/partials/register.html | 1 - 2 files changed, 2 deletions(-) diff --git a/app/modules/auth/partials/login.html b/app/modules/auth/partials/login.html index cffeefe6..a0db3ffd 100644 --- a/app/modules/auth/partials/login.html +++ b/app/modules/auth/partials/login.html @@ -12,7 +12,6 @@

Use your created account to login.

-
diff --git a/app/modules/auth/partials/register.html b/app/modules/auth/partials/register.html index 4a977fd0..3fcb5ec7 100644 --- a/app/modules/auth/partials/register.html +++ b/app/modules/auth/partials/register.html @@ -11,7 +11,6 @@

Create an account to login.

-
From 9af695a8b9eb2fbc752780f8f1bbbfe4f5a78c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yves=20M=C3=BCller?= Date: Thu, 20 Oct 2016 14:10:28 +0200 Subject: [PATCH 3/3] Add password reset functionality --- .../adhocracyEmbedder/services/adhocracy.js | 13 ++++++- app/modules/auth/auth.js | 3 ++ .../auth/controllers/authControllers.js | 37 +++++++++++++++++-- app/modules/auth/directives/loginRegister.js | 10 ++++- app/modules/auth/partials/login.html | 3 ++ app/modules/auth/services/auth.js | 7 ++++ 6 files changed, 66 insertions(+), 7 deletions(-) diff --git a/app/modules/adhocracyEmbedder/services/adhocracy.js b/app/modules/adhocracyEmbedder/services/adhocracy.js index cf62fb6e..7a539586 100644 --- a/app/modules/adhocracyEmbedder/services/adhocracy.js +++ b/app/modules/adhocracyEmbedder/services/adhocracy.js @@ -195,7 +195,18 @@ angular.module('pcApp.adhocracyEmbedder.services.adhocracy', []) }, transformResponse: withResponseErrorTransformer() }) - } + }; + + client.resetPassword = function(email) { + return $http({ + method: 'POST', + url: url('/create_password_reset/'), + data: { + email: email + }, + transformResponse: withResponseErrorTransformer() + }); + }; return client; } diff --git a/app/modules/auth/auth.js b/app/modules/auth/auth.js index 3bd33576..37507cef 100644 --- a/app/modules/auth/auth.js +++ b/app/modules/auth/auth.js @@ -11,5 +11,8 @@ auth.config(function ($routeProvider) { }) .when('/register', { template: '' + }) + .when('/password_reset',{ + template: '' }); }); diff --git a/app/modules/auth/controllers/authControllers.js b/app/modules/auth/controllers/authControllers.js index 65b365af..25b53fbb 100644 --- a/app/modules/auth/controllers/authControllers.js +++ b/app/modules/auth/controllers/authControllers.js @@ -42,8 +42,8 @@ angular.module('pcApp.auth.controllers.authControllers', [ ]) .controller('LoginController', [ '$scope', '$location', 'Auth', function ($scope, $location, Auth) { - $scope.goToRegister = function ( path ) { - $location.path('/register'); + $scope.goToPasswordReset = function ( path ) { + $location.path('/password_reset'); }; $scope.$submitted = false; @@ -68,7 +68,36 @@ angular.module('pcApp.auth.controllers.authControllers', [ $scope.serverErrors.$other = 'Unknown error.'; throw e; } - }) + }); }; } - ]); + ]) + .controller('ResetPasswordController', [ + '$scope', 'Auth', function ($scope, Auth) { + $scope.$submitted = false; + $scope.serverErrors = {} + $scope.completed = false; + + $scope.resetPassword = function () { + $scope.$submitted = true; + + if (!$scope.resetPasswordForm.$valid) { + return false + } + + Auth.resetPassword($scope.email) + .then(function () { + $scope.completed = true; + }).catch(function (response) { + try { + $scope.serverErrors = response.data.errorDict; + } catch (e) { + $scope.serverErrors.$other = 'Unknown error.'; + throw e; + } + }); + + return true; + }; + } + ]) diff --git a/app/modules/auth/directives/loginRegister.js b/app/modules/auth/directives/loginRegister.js index e9d9302e..b9f9aeaf 100644 --- a/app/modules/auth/directives/loginRegister.js +++ b/app/modules/auth/directives/loginRegister.js @@ -5,13 +5,19 @@ angular.module('pcApp.auth.directives.loginRegister', [ .directive('login', function () { return { restrict: 'E', - templateUrl: 'modules/auth/partials/login.html', + templateUrl: 'modules/auth/partials/login.html' }; }) .directive('register', function () { return { restrict: 'E', - templateUrl: 'modules/auth/partials/register.html', + templateUrl: 'modules/auth/partials/register.html' + }; + }) + .directive('passwordReset', function () { + return { + restrict: 'E', + templateUrl: 'modules/auth/partials/passwordReset.html' }; }) .directive("passwordVerify", function() { diff --git a/app/modules/auth/partials/login.html b/app/modules/auth/partials/login.html index a0db3ffd..044c1504 100644 --- a/app/modules/auth/partials/login.html +++ b/app/modules/auth/partials/login.html @@ -30,6 +30,9 @@

+

diff --git a/app/modules/auth/services/auth.js b/app/modules/auth/services/auth.js index a93e2937..fc56d495 100644 --- a/app/modules/auth/services/auth.js +++ b/app/modules/auth/services/auth.js @@ -148,6 +148,13 @@ angular.module('pcApp.auth.services.auth', [ return AdhocracyClient.register(name, email, password) }; + /** Wrapper to make A3 auth features pluggable. Calls directly A3 + * specific password reset code. + */ + Auth.resetPassword = function (email) { + return AdhocracyClient.resetPassword(email); + }; + Auth.logout = function () { teardownSession(); };