Adding cancel account with token functionality

stable
Alejandro Alonso 2014-10-08 11:27:02 +02:00
parent e0a6dfee12
commit 5fd9a950a1
4 changed files with 46 additions and 0 deletions

View File

@ -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",

View File

@ -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])

View File

@ -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"

View File

@ -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"