Problems, need help? Have a tip or advice? Post it here.
9 posts Page 1 of 1
I'm putting together a site which is basically (at least initially) to run a small mailing list and allow people to sign up, manage their own profiles and preferences etc.

I'd like to be able to invite members of an existing mailing list to sign up the new one, and ideally I'd send them a personalised link which would take them to the new registration form with the name and email address pre-filled for them.

I can get the data from the URL (using the getstring); I've used

Code: Select all
<cms:set emailsent="<cms:gpc 'e' method='get'/>" />

to extract the email in a cms variable 'emailsent', and can echo that to the page to confirm it's getting there OK.

But if I try

Code: Select all
 <cms:input name='extended_user_email' value="<cms:show emailsent />" type='bound' />

the value does not appear in the form.

How can I achieve what I want in this case?
When a <cms:input> is declared as type 'bound', all its data is fetched from the <cms:editable> definition originally used to create it (i.e. it looks exactly the way it does while editing in the admin panel). This means that the value you are trying to show within it will be ignored.

The correct way would be to use normal (i.e. non-bound) <cms:input> instead.
Then when the form is successfully submitted, fetch the submitted data and save it into the editable region using <cms:db_persist> - please see viewtopic.php?p=15104#p15104 for a discussion.

Hope this helps.
Thanks as always, KK!

What I'm not clear on here, though, is how this will work with the user registration aspect of extended users.

At what point in the process do I actually persist the data - and will the extended user registration process still deal with things like mismatched password entries and so on?



Also, while I have your attention (:-)) - is there a way of allowing an 'authenticated' extended user to delete herself - that is, to delete their page? (I believe deletions of anyone above that level would need superadmin involvement, and that's fine). I tried this (modified from viewtopic.php?p=13980#p13980):
Code: Select all
<?php require_once( '../couch/cms.php' ); ?>
<cms:pages masterpage=k_user_template>
   <h3><cms:show k_page_title /></h3>
   <cms:form
          masterpage=k_user_template
          mode='edit'
          page_id=k_user_id
          method='post'
          anchor='0'
       >
      <cms:if k_success>
              <!-- Delete the specified page -->
              <cms:db_delete masterpage=k_user_template page_id=k_user_id />
              <!-- and then redirect -->
              <cms:redirect k_site_link />
       </cms:if>
      <p>
        <cms:show k_user_id />
     </p>
     <cms:input type="submit" name="submit" value="Delete page"/>
  </cms:form>

</cms:pages>
<?php COUCH::invoke(); ?>


..but the page gives an 'Access Denied' error when visited as an authenticated user.
Ok, I've got the bit about using an URL with an email in it to pre-fill the filed and pass it to the user record. With a URL in my site like
Code: Select all
/users/register.php?e=test@example.com

I get the email like this:
Code: Select all
<cms:set emailsent="<cms:gpc 'e' method='get'/>" /> 

I've then got a form input like this:
Code: Select all
<cms:input name='inputemail' type="text" value="<cms:show emailsent />"/>

and the db_persist of the registration page (taken from the usual extended users users.zip file) is amended like this:
Code: Select all
<cms:if k_success >        
   <cms:check_spam email=frm_extended_user_email />           
   <cms:db_persist_form
            _invalidate_cache='0'
             k_page_name = "<cms:random_name />"
             k_page_title = "<cms:show frm_name_c/> <cms:show frm_name_s />"
             extended_user_email = "<cms:show frm_inputemail />"
             k_publish_date = '0000-00-00 00:00:00'
     />   


But i'm still stuck on the deletion issue! Any help gratefully received....
Non-admins are not allowed to delete themselves.. However I developed a 'hackish' way to do it for you - please welcome the function (more on functions here viewtopic.php?f=8&t=11368&start=10#p30174) that kinda helps -
Code: Select all
<cms:func 'suicide_now' ><cms:ignore>

    // Erases logged in user from database + log out
    // <cms:call 'suicide_now' />

    </cms:ignore>
    <cms:php>
        global $CTX, $AUTH, $FUNCS;

        $me = $AUTH->user->id;
        $my_access_level = &$AUTH->user->access_level;

        if( !$me || $me == -1 || $my_access_level == 10 ) return;

        $nonce = $FUNCS->create_nonce( 'logout'.$me, $AUTH->user->name );
        $AUTH->logout($nonce);

        $my_access_level += 1;
        $user = new KUser($me, 1);
        $user->delete();
    </cms:php>

</cms:func>


Use with care :) Do not forget to reload the page (cms:redirect) to see the result.

EDIT: Superadmin can potentially delete himself too! The function has a check to avoid that :)
Say `Please!` [̲̅$̲̅(̲̅ ͡° ͜ʖ ͡°̲̅)̲̅$̲̅]..... Active topics [Forum posts from previous 7 days].... helpcouch@mail.ru [My email for friends]
@trendoman: thanks for this - but it doesn't seem to be working for me. Here's the whole page:
Code: Select all
<?php require_once( '../couch/cms.php' ); ?>

<cms:func 'suicide_now' ><cms:ignore>

    // Erases logged in user from database
    // <cms:call 'suicide_now' />

    </cms:ignore>
    <cms:php>
        global $CTX, $AUTH;

        $me = $CTX->get('k_extended_user_id');
        $me = intval($me);
        if( !$me || $me == -1 || $me == 10 ) return;

        $AUTH->user->access_level += 1;
        $user = new KUser($me, 1);
        $user->delete();
    </cms:php>
 
</cms:func>

  <!-- Make sure we have an authenticated user -->
  <cms:if k_logged_out >
      <cms:redirect "<cms:login_link />" />
  </cms:if>

  <!-- Since they have logged in, they can delete themselves-->
   <cms:embed 'header.inc' />
     <main>
       <h1>Deleting your profile</h1>
       <cms:call 'suicide_now' />
       <cms:redirect  url="<cms:show k_site_link />" />
    </main>
  <cms:embed 'footer.inc' />

<?php COUCH::invoke(); ?>


If I log in as an ordinary authenticated user, and visit this page, I get a standard Couch 'access denied' page - even though it must have got past the authentication check to reach the deletion code! The user record is not deleted.

Am I missing something obvious?
Getting rid of people is a tricky business :lol:

First, I have tested the function and as a thing it works quite well in the deleting part. I also updated the code to avoid superadmin killing itself and automatically logout user and delete cookie (borrowing that part from cms:process_logout tag) - please copy the new cms:func.

Second, the template's code you posted will have issues, because it tries to call the function upon loading the template. Quite often, before displaying the final page it can be redirected by itself multiple times - concurrent requests, influence of addons (such as url-changing behavior of multilingual addon). The point is, HTML will not be visible to the visitor, because the page gets redirected to self and triggers the 'k_logged_out' block of code with redirect to login link. I suggest the following solution - give your visitor a button to start the deletion process via a form -
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>

<!-- Make sure we have an authenticated user -->
<cms:if k_logged_out >
    <cms:redirect "<cms:login_link />" />
</cms:if>

<!-- Since they have logged in, they can delete themselves-->
<cms:form anchor='0' method='post'>
    <cms:if k_success>
        <cms:set_flash 'user_deleted' value='Success!' />
        <cms:call 'suicide_now' />
        <cms:redirect url=k_site_link />
    </cms:if>
    <cms:input type='submit' name='submit' value='Commit a suicide' />
</cms:form>

<?php COUCH::invoke(); ?>


With a form, you can display HTML, control the flow of the process and do whatever else, for example set flash message and output a success message on the main site link.

Please apply the changes and hopefully you'll see it working fine.
Say `Please!` [̲̅$̲̅(̲̅ ͡° ͜ʖ ͡°̲̅)̲̅$̲̅]..... Active topics [Forum posts from previous 7 days].... helpcouch@mail.ru [My email for friends]
Hi, @trendoman.

A long gap (sorry, various issues both on the site and IRL), but now I'm back, and wanted to confirm that this does work. Thankyou for your help.

One point in case anyone else uses this - it seemed that I had to visit the page as superadmin before it would work for an ordinary user; is that correct? I know that's usual for templates, but hadn't realised it would be needed for this purpose.
You are welcome.
Thanks for the confirmation it works for you. :)
Say `Please!` [̲̅$̲̅(̲̅ ͡° ͜ʖ ͡°̲̅)̲̅$̲̅]..... Active topics [Forum posts from previous 7 days].... helpcouch@mail.ru [My email for friends]
9 posts Page 1 of 1

Who is online

In total there are 5 users online :: 1 registered, 0 hidden and 4 guests
(based on users active over the past 5 minutes)

Users browsing this forum: Google [Bot] and 4 guests