'Deactivate the currently logged in account.
A valid username/password and confirmation must be supplied. An
optional `deactivate_message` may be supplied to explain the reason the
account is to be deleted.
Called by /prefs/deactivate on the site.'

@validatedForm(VUser(), VModhash(), deactivate_message=VLength('deactivate_message', max_length=500), username=VRequired('user', errors.NOT_USER), user=VThrottledLogin(['user', 'passwd']), confirm=VBoolean('confirm'))
def POST_deactivate_user(self, form, jquery, deactivate_message, username, user, confirm):

    if (username and (username.lower() != c.user.name.lower())):
        c.errors.add(errors.NOT_USER, field='user')
    if (not confirm):
        c.errors.add(errors.CONFIRM, field='confirm')
    if (not (form.has_errors('ratelimit', errors.RATELIMIT) or form.has_errors('user', errors.NOT_USER) or form.has_errors('passwd', errors.WRONG_PASSWORD) or form.has_errors('deactivate_message', errors.TOO_LONG) or form.has_errors('confirm', errors.CONFIRM))):
        redirect_url = '/?deactivated=true'
        c.user.delete(deactivate_message)
        form.redirect(redirect_url)
