diff --git a/authority/server/db.js b/authority/server/db.js index 4d362888e67f938fedc6eb608b8d12e761c89e55..2c4275d09c0cf570a0e6b25ef82550a7e95df4e2 100644 --- a/authority/server/db.js +++ b/authority/server/db.js @@ -292,4 +292,17 @@ exports.removeEmail = function(authenticated_email, email, cb) { else cb(); }); }); +}; + +exports.cancelAccount = function(authenticated_email, cb) { + emailToUserID(authenticated_email, function(user_id) { + executeTransaction([ + [ "delete from emails where user = ?", [ user_id ] ] , + [ "delete from keys where email in (select address from emails where user = ?)", [ user_id ] ], + [ "delete from users where id = ?", [ user_id ] ], + ], function (error) { + if (error) cb(error); + else cb(); + }); + }); }; \ No newline at end of file diff --git a/authority/server/wsapi.js b/authority/server/wsapi.js index 0bfb38b9eea745ff670d4e8766aa67a361beef3a..1a900b85ffa1f82d4b8da0bd32f124a3d8089713 100644 --- a/authority/server/wsapi.js +++ b/authority/server/wsapi.js @@ -168,6 +168,21 @@ exports.remove_email = function(req, resp) { }}); }; +exports.account_cancel = function(req, resp) { + // this should really be POST + if (!checkAuthed(req, resp)) return; + + logRequest("account_cancel"); + + db.cancelAccount(req.session.authenticatedUser, function(error) { + if (error) { + console.log("error cancelling account : " + error.toString()); + httputils.badRequest(resp, error.toString()); + } else { + httputils.jsonResponse(resp, true); + }}); +}; + exports.set_key = function (req, resp) { var urlobj = url.parse(req.url, true); var getArgs = urlobj.query; diff --git a/authority/static/css/style.css b/authority/static/css/style.css index 589531c73758f91974100cf41f9fc9ce78660828..9f52ecb716d29ecfe68243ecbc85c25a81e8d332 100644 --- a/authority/static/css/style.css +++ b/authority/static/css/style.css @@ -195,6 +195,14 @@ pre code { font-weight:bold; margin-top:32px; } + +#cancelaccount { + font-size: 1.0em; + width: 500px; + margin: auto; + margin-top:35px; +} + .email { display:inline-block; } diff --git a/authority/static/manage.html b/authority/static/manage.html index 0a3be84039b0d4d379a393790b711d9b96159f21..2eb38b793f266fa801e658ed8b4c6b9fee8f25ba 100644 --- a/authority/static/manage.html +++ b/authority/static/manage.html @@ -21,6 +21,9 @@ </div> <div id="emailList"> </div> + <div id="cancelaccount"> + You may, at any time, <a href="#" id="cancellink">cancel your account</a>. + </div> </div> <div class="footer"> <div> @@ -46,6 +49,15 @@ function display_saved_ids() emails = JSON.parse(window.localStorage.emails); } + $('#cancellink').click(function() { + if (confirm('Are you sure you want to cancel your account?')) { + $.post("/wsapi/account_cancel", {}, function(result) { + window.localStorage.emails = null; + document.location="/"; + }); + } + }); + $("#emailList").empty(); _(emails).each(function(data, e) { var block = $("<div>").addClass("emailblock");