We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17301
    • 932 Posts
    This article is not written by me but taken from:
    http://blog.chrispomfret.com/2014/07/24/delete-account-for-a-web-user-in-modx-when-using-the-login-plugin/

    I'm posting it here incase the site goes down at some point. With EGDPR rules cmoing into effect next year all corporations in the EU have to offer an opt out of any information submitted and this includes terminating an account. Therefore I'm posting this here for safe keeping..Thank you to the original author.

    ---------


    Login is a MODx plugin that allows front-end login capabilities for users.

    The existing guides are great, which cover most aspects of a basic account system. The first Basic Setup leaves you with the most basic account functionality, the Membership tutorial expands upon this, providing pages for users to create their own account. Lastly, the User Profiles and Extended User Profiles guides start looking at storing information with each user.
    These guides are great but there’s one key functionality I think is left out – That is the ability for a user to delete their account. That is what this is a guide for.

    This is a fairly straight forwards process. 1st step, create a page with a form for users to confirm they wish to delete their account. The 2nd (and last) step is to create a snippet which actually deletes the user account.

    This guide uses a form which requires the FormIt package. If you haven’t already got it, make sure you do that before starting!

    Create a document that will be your Delete Account page (you could call it ‘Delete Account’).
    Make sure this is set as a Members only page under its Resource Groups tab (See the Login tutorials mentioned above).
    Enter the following as the contents of the page. What this does is show a form to the user. To delete their account they must type ‘delete ‘ into a text box, check a tickbox and click submit. If this is done, the snippet ‘DeleteAccount’ will be called (as denoted by &hooks in the FormIt call).:

    [[!FormIt?
    &hooks=`DeleteAccount`
    &successMessage=`Account Deleted`
    &validate=`deleteString:required:stripTags,
    cancel:required`
    ]]
     
    <form method="post" action="[[~[[*id]]]]">
    [[!+fi.validation_error_message]]
    <ul >
      <li id="li_1" >
        <label class="description" for="deleteString">
          To delete your account please type the word 'delete' into the box below and check the tickbox.
          [[!+fi.error.deleteString]]
        </label>
        <input id="deleteString" name="deleteString" class="element text medium" type="text" maxlength="255" value="[[!+fi.deleteString]]"/>
      </li>
     
      <li id="li_2" >
        <label class="description" for="cancel">[[!+fi.error.cancel]]</label>
        <span>
          <input type="hidden" name="cancel[]" value="" />
          <input id="cancel" name="cancel[]" class="element checkbox" type="checkbox" value="Yes" [[!+fi.cancel:FormItIsChecked=`Yes`]] />
          <label class="choice" for="element_2_1">I confirm I wish to delete my account.</label>
        </span>
      </li>
      <p class="response-message">[[!+fi.successMessage]][[!+fi.error_message]]</p>
      <li class="buttons">
        <input type="hidden" name="form_id" value="850696" />
        <input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
      </li>
    </ul>
    </form>


    Create a snippet called DeleteAccount and enter the following into the body of the snippet:

    <?php
      $allFormFields = $hook->getValues();
      $output = true;
     
      $deleteString = mb_strtolower($allFormFields['deleteString']);
     
      $user = $modx->user;
      if (!$user){
        $errorMsg = 'No user found';
        $hook->addError(deleteString, $errorMsg);
        $output= false;
      }
     
      $profile = $user->getOne('Profile');
      if (!$profile){
        $errorMsg = 'No profile found';
        $hook->addError(deleteString, $errorMsg);
        $output= false;
      }
     
      if($deleteString == 'delete'){
        $user->remove();
      }else{
        $errorMsg = 'You did not enter delete in the text box - '.$deleteString;
        $hook->addError(deleteString, $errorMsg);
        $output = false;
      }
      return $output;
    ?>
    


    When the form is sent, the checkbox is ticked and the word ‘delete’ was entered into the text box, the currently logged in user account will be deleted.

    I hope this works for you and you found it helpful!
    [ed. note: lkfranklin last edited this post 7 years ago.]
      ■ email: [email protected] | ■ website: https://alienbuild.uk

      The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
      • 3749
      • 24,544 Posts
      Interesting stuff. Thanks for posting it. wink

      FYI, the Subscribe package has a page to set interests or delete the account. The Notify extra automatically sends a user-specific link to that page in any email.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 17301
        • 932 Posts
        Thanks Bob!
          ■ email: [email protected] | ■ website: https://alienbuild.uk

          The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
          • 54319
          • 6 Posts
          bonjour j'ai copié le code tel quel et j'ai une belle page blanche dans supprimer mon compte