<![CDATA[ Tutorial: Login Extra - Terminate Account / Delete User - My Forums]]> https://forums.modx.com/thread/?thread=101919 <![CDATA[Re: Tutorial: Login Extra - Terminate Account / Delete User]]> https://forums.modx.com/thread/101919/tutorial-login-extra---terminate-account-delete-user#dis-post-559092 yvesman13 Jun 15, 2018, 07:36 AM https://forums.modx.com/thread/101919/tutorial-login-extra---terminate-account-delete-user#dis-post-559092 <![CDATA[Re: Tutorial: Login Extra - Terminate Account / Delete User]]> https://forums.modx.com/thread/101919/tutorial-login-extra---terminate-account-delete-user#dis-post-549539 ]]> lkfranklin Mar 21, 2017, 05:51 AM https://forums.modx.com/thread/101919/tutorial-login-extra---terminate-account-delete-user#dis-post-549539 <![CDATA[Re: Tutorial: Login Extra - Terminate Account / Delete User]]> https://forums.modx.com/thread/101919/tutorial-login-extra---terminate-account-delete-user#dis-post-549538

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.]]>
BobRay Mar 21, 2017, 03:38 AM https://forums.modx.com/thread/101919/tutorial-login-extra---terminate-account-delete-user#dis-post-549538
<![CDATA[Tutorial: Login Extra - Terminate Account / Delete User]]> https://forums.modx.com/thread/101919/tutorial-login-extra---terminate-account-delete-user#dis-post-549523 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!
]]>
lkfranklin Mar 20, 2017, 01:47 PM https://forums.modx.com/thread/101919/tutorial-login-extra---terminate-account-delete-user#dis-post-549523