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..939d290e 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,42 @@ 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) -> + $auth.logout() + $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" 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")