diff --git a/frontend/src/js/controllers/profileCtrl.js b/frontend/src/js/controllers/profileCtrl.js index 2395d90480..5545f14cda 100644 --- a/frontend/src/js/controllers/profileCtrl.js +++ b/frontend/src/js/controllers/profileCtrl.js @@ -354,6 +354,32 @@ $rootScope.notify("error", "Something went wrong! Please refresh the page and try again."); } }; + + // Deactivate User Account + vm.confirmDeactivateAccount = function(deactivateAccountForm) { + if (deactivateAccountForm) { + parameters.token = userKey; + parameters.method = 'POST'; + parameters.url = 'accounts/user/disable'; + parameters.callback = { + onSuccess: function(response) { + var status = response.status; + if (status == 200) { + utilities.resetStorage(); + $rootScope.isLoader = false; + $state.go("home"); + $rootScope.isAuth = false; + $rootScope.notify("success", "Your account has been deactivated successfully."); + } + }, + onError: function(response) { + var details = response.data; + $rootScope.notify("error", details.error); + } + }; + utilities.sendRequest(parameters); + } + }; } })(); diff --git a/frontend/src/js/route-config/route-config.js b/frontend/src/js/route-config/route-config.js index 38fa1340f8..5f7b07729f 100644 --- a/frontend/src/js/route-config/route-config.js +++ b/frontend/src/js/route-config/route-config.js @@ -397,6 +397,15 @@ authenticate: true }; + var deactivate_account = { + name: "web.profile.deactivate-account", + parent: "web.profile", + url: "/deactivate-account", + templateUrl: baseUrl + "/web/profile/edit-profile/deactivate-account.html", + title: 'Deactivate Account', + authenticate: true + }; + var host_challenge = { name: "web.host-challenge", parent: "web", @@ -617,6 +626,7 @@ $stateProvider.state(our_team); $stateProvider.state(get_involved); $stateProvider.state(edit_profile); + $stateProvider.state(deactivate_account); $stateProvider.state(contact_us); $stateProvider.state(challengeInvitation); $stateProvider.state(get_submission_related_files); diff --git a/frontend/src/views/web/profile/edit-profile/deactivate-account.html b/frontend/src/views/web/profile/edit-profile/deactivate-account.html new file mode 100644 index 0000000000..f6ae38c1aa --- /dev/null +++ b/frontend/src/views/web/profile/edit-profile/deactivate-account.html @@ -0,0 +1,25 @@ +
+
+
+
+
+
+
Deactivate Account
+
+ +
+
    +
  • + Cancel +
  • +
  • + +
  • {{profile.userKey}}
  • + +
+
+
+
+
+
+
diff --git a/frontend/src/views/web/profile/profile.html b/frontend/src/views/web/profile/profile.html index 01f35297d7..d2ccc3c5e8 100644 --- a/frontend/src/views/web/profile/profile.html +++ b/frontend/src/views/web/profile/profile.html @@ -8,6 +8,8 @@ class="text-light-black w-300"> Auth Token
  • Password
  • +
  • Deactivate Account
  • diff --git a/frontend/tests/controllers-test/profileCtrl.test.js b/frontend/tests/controllers-test/profileCtrl.test.js index 55a5bfdeca..d6f4ae3d9c 100644 --- a/frontend/tests/controllers-test/profileCtrl.test.js +++ b/frontend/tests/controllers-test/profileCtrl.test.js @@ -272,4 +272,45 @@ describe('Unit tests for profile controller', function () { $state.reload(); }); }); + + describe('Unit tests for `deactivate user` function', function () { + var success, deactivateAccountForm; + var errorResponse = { + error: 'error' + }; + + beforeEach(function () { + spyOn($rootScope, 'notify'); + spyOn($state, 'go'); + + utilities.sendRequest = function (parameters) { + if (success) { + parameters.callback.onSuccess({ + data: 'success', + status: 200 + }); + } else { + parameters.callback.onError({ + data: errorResponse, + status: 400 + }); + } + }; + }); + + it('successfully deactivated user', function () { + success = true; + deactivateAccountForm = true; + vm.confirmDeactivateAccount(deactivateAccountForm); + expect($rootScope.notify).toHaveBeenCalledWith("success", "Your account has been deactivated successfully."); + expect($state.go).toHaveBeenCalledWith("home"); + }); + + it('backend error', function () { + success = false; + deactivateAccountForm = true; + vm.confirmDeactivateAccount(deactivateAccountForm); + expect($rootScope.notify).toHaveBeenCalledWith("error", errorResponse.error); + }); + }); });