From 5fd9a950a1b45c50af10c79561ff3b4b7007fad7 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Wed, 8 Oct 2014 11:27:02 +0200 Subject: [PATCH 1/3] Adding cancel account with token functionality --- app/coffee/app.coffee | 2 ++ app/coffee/modules/auth.coffee | 42 +++++++++++++++++++++++++++++ app/coffee/modules/base.coffee | 1 + app/coffee/modules/resources.coffee | 1 + 4 files changed, 46 insertions(+) diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index 220c50a9..e007c11d 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -114,6 +114,8 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven {templateUrl: "/partials/mail-notifications.html"}) $routeProvider.when("/change-email/:email_token", {templateUrl: "/partials/change-email.html"}) + $routeProvider.when("/cancel-account/:cancel_token", + {templateUrl: "/partials/cancel-account.html"}) # Auth $routeProvider.when("/login", diff --git a/app/coffee/modules/auth.coffee b/app/coffee/modules/auth.coffee index 2695afc6..ee116ccd 100644 --- a/app/coffee/modules/auth.coffee +++ b/app/coffee/modules/auth.coffee @@ -137,6 +137,10 @@ class AuthService extends taiga.Service data = _.clone(data, false) return @http.post(url, data) + cancelAccount: (data) -> + url = @urls.resolve("users-cancel-account") + data = _.clone(data, false) + return @http.post(url, data) module.service("$tgAuth", AuthService) @@ -458,3 +462,41 @@ ChangeEmailDirective = ($repo, $model, $auth, $confirm, $location, $params, $nav module.directive("tgChangeEmail", ["$tgRepo", "$tgModel", "$tgAuth", "$tgConfirm", "$tgLocation", "$routeParams", "$tgNavUrls", ChangeEmailDirective]) + +############################################################################# +## Cancel account +############################################################################# + +CancelAccountDirective = ($repo, $model, $auth, $confirm, $location, $params, $navUrls) -> + link = ($scope, $el, $attrs) -> + $scope.data = {} + $scope.data.cancel_token = $params.cancel_token + form = $el.find("form").checksley() + + onSuccessSubmit = (response) -> + $location.path($navUrls.resolve("home")) + $confirm.success("Our Oompa Loompas removed your account") #TODO: i18n + + onErrorSubmit = (response) -> + $confirm.notify("error", "One of our Oompa Loompas says + '#{response.data._error_message}'.") #TODO: i18n + + submit = -> + if not form.validate() + return + + promise = $auth.cancelAccount($scope.data) + promise.then(onSuccessSubmit, onErrorSubmit) + + $el.on "submit", (event) -> + event.preventDefault() + submit() + + $el.on "click", "a.button-cancel-account", (event) -> + event.preventDefault() + submit() + + return {link:link} + +module.directive("tgCancelAccount", ["$tgRepo", "$tgModel", "$tgAuth", "$tgConfirm", "$tgLocation", "$routeParams", + "$tgNavUrls", CancelAccountDirective]) diff --git a/app/coffee/modules/base.coffee b/app/coffee/modules/base.coffee index 1feb8e91..9a4a309f 100644 --- a/app/coffee/modules/base.coffee +++ b/app/coffee/modules/base.coffee @@ -51,6 +51,7 @@ urls = { "forgot-password": "/forgot-password" "change-password": "/change-password/:token" "change-email": "/change-email/:token" + "cancel-account": "/cancel-account/:token" "register": "/register" "invitation": "/invitation/:token" "create-project": "/create-project" diff --git a/app/coffee/modules/resources.coffee b/app/coffee/modules/resources.coffee index 6947e804..18675d29 100644 --- a/app/coffee/modules/resources.coffee +++ b/app/coffee/modules/resources.coffee @@ -73,6 +73,7 @@ urls = { "users-change-password-from-recovery": "/users/change_password_from_recovery" "users-change-password": "/users/change_password" "users-change-email": "/users/change_email" + "users-cancel-account": "/users/cancel" "user-storage": "/user-storage" "resolver": "/resolver" "userstory-statuses": "/userstory-statuses" From 9bd2c6b9ee6e50a246a047b27050fc59584445bb Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Wed, 15 Oct 2014 12:33:23 +0200 Subject: [PATCH 2/3] Adding lost templates --- app/partials/cancel-account.jade | 14 ++++++++++++++ .../views/modules/cancel-account-form.jade | 12 ++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 app/partials/cancel-account.jade create mode 100644 app/partials/views/modules/cancel-account-form.jade diff --git a/app/partials/cancel-account.jade b/app/partials/cancel-account.jade new file mode 100644 index 00000000..45dd5275 --- /dev/null +++ b/app/partials/cancel-account.jade @@ -0,0 +1,14 @@ +extends dummy-layout + +block head + title Taiga Your agile, free, and open source project management tool + +block content + div.wrapper + div.login-main + div.login-container + h1.logo + img.logo-svg(src="/svg/logo.svg", alt="TAIGA") + p.tagline Your agile, free, and open source project management tool + + include views/modules/cancel-account-form diff --git a/app/partials/views/modules/cancel-account-form.jade b/app/partials/views/modules/cancel-account-form.jade new file mode 100644 index 00000000..99108c2b --- /dev/null +++ b/app/partials/views/modules/cancel-account-form.jade @@ -0,0 +1,12 @@ +div.change-email-form-container(tg-cancel-account) + p.change-password-text + strong Cancel your account
+ span We're sorry you are leaving the taiga, we hope you enjoyed your stay :) + + form(ng-submit="ctrl.submit()") + fieldset + input(type="hidden", name="cancel_token", ng-model="data.cancel_token", data-required="true", + placeholder="cancel account token") + + a.button.button-cancel-account.button-gray(href="", title="Yes, I'm leaving") Yes, I'm leaving! + input(type="submit", style="display:none") From 6cd8e87ce6db23a4f354e94b09862c255ed4ded1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Wed, 15 Oct 2014 13:07:36 +0200 Subject: [PATCH 3/3] Minor fix: Logout user after cancel account --- app/coffee/modules/auth.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/app/coffee/modules/auth.coffee b/app/coffee/modules/auth.coffee index ee116ccd..939d290e 100644 --- a/app/coffee/modules/auth.coffee +++ b/app/coffee/modules/auth.coffee @@ -474,6 +474,7 @@ CancelAccountDirective = ($repo, $model, $auth, $confirm, $location, $params, $n form = $el.find("form").checksley() onSuccessSubmit = (response) -> + $auth.logout() $location.path($navUrls.resolve("home")) $confirm.success("Our Oompa Loompas removed your account") #TODO: i18n