Skip to content

Commit

Permalink
Merge branch 'master' into leaderboarddataapi
Browse files Browse the repository at this point in the history
  • Loading branch information
gchhablani authored Aug 9, 2023
2 parents 44bac68 + d44d33b commit 0f10404
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
26 changes: 26 additions & 0 deletions frontend/src/js/controllers/profileCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
}

})();
10 changes: 10 additions & 0 deletions frontend/src/js/route-config/route-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<section class="ev-md-container-ui">
<div class="ev-md-container ev-card-panel">
<div class="row ht-wt-100p">
<div class="col s12 m12">
<div class="ev-card-body">
<form name="deactivateAccountForm" ng-submit="profile.confirmDeactivateAccount(deactivateAccountForm.$valid)">
<div class="pass-title">Deactivate Account</div>
<div class="input-field align-left">
<input placeholder="Please type in the username to confirm" type="text" ng-model="nameInput">
</div>
<ul class="inline-list hide-on-med-and-down">
<li>
<a ng-click="profile.confirmDeactivateAccount(false)" class="dark-link pointer"><strong>Cancel</strong></a>
</li>
<li>
<button class="btn red waves-effect waves-dark grad-btn darken-2 fs-14" ng-disabled="!(nameInput==profile.user.username)" type="submit" value="submit">I understand the consequences of this action. Deactivate this account.</button>
<li>{{profile.userKey}}</li>
</li>
</ul>
</form>
</div>
</div>
</div>
</div>
</section>
2 changes: 2 additions & 0 deletions frontend/src/views/web/profile/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
class="text-light-black w-300"><i class="fa fa-lock"></i> Auth Token</a></li>
<li class="margin-btm-0"><a ui-sref=".change-password" ui-sref-active="active-challenge"
class="text-light-black w-300"><i class="fa fa-key"></i> Password</a></li>
<li class="margin-btm-0"><a ui-sref=".deactivate-account" ui-sref-active="active-challenge"
class="text-light-black w-300"><i class="fa fa-power-off"></i> Deactivate Account</a></li>
</ul>
</div>
</div>
Expand Down
41 changes: 41 additions & 0 deletions frontend/tests/controllers-test/profileCtrl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 0f10404

Please sign in to comment.