Testing for existing user account

18 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: June 1, 2011   (RSS)

By gkornbluth - May 23, 2010 - edited: May 23, 2010

Hi all,

Using the membership plugin, I’d like to be able to test for the existence of a disabled member account based on an email address entered in a form, and display a message on the web page confirming the existence of the account.

Here’s what I’ve done so far (mostly guesswork, mostly wrong!). Which gives me this error when I try to display any page that uses the membership plugin:

Parse error: syntax error, unexpected $end in /hsphere/local/home/apbcweb/artistsofpalmbeachcounty.org/cmsAdmin/plugins/websiteMembership.php on line 270

To the “// perform website login actions” section in the membership plugin, I added the lineif (@$_REQUEST['action'] == 'pastInformation') { _websiteLogin_pastInformation(); }


Then above the existing: function _websiteLogin_sendPasswordReminder() {
global $SETTINGS, $TABLE_PREFIX;
I added;function _websiteLogin_pastInformation() {
global $SETTINGS, $TABLE_PREFIX;

// REQUEST FOR PAST INFORMATION
// display errors
if (array_key_exists('pastInformation', $_REQUEST) && @$_REQUEST['pastInformation'] == $user['email']) {
alert("<span class='heading-text-yellow'>Congratulations!!!<br />Your Account Exists</span><br/><span class='body-text-yellow'>You do not need to create a new account.</span>\n");
}



The plan was then to use this form (modified from the password reminder code) to request the test, but I never even got that far (so this is probably wrong too). <?php if (!@$CURRENT_USER): ?>
<form action="?" method="post">
<input type="hidden" name="action" value="pastInformation" />
<span class="body-text-bold">Enter your e-mail address:</span>
<input type="text" name="pastInformation" value="<?php echo htmlspecialchars(@$_REQUEST['pastInformation']) ?>" size="20" />
<input type="submit" name="submit" value="Submit" />
</form>

<?php endif ?>



I've attached the website membership plugin that I've worked on and could use some insight as to where I’m going wrong.

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

websitemembership2.php 10K

Re: [gkornbluth] Testing for existing user account

By Jason - May 25, 2010

Hi Jerry,

The problem was you were missing a } down at the bottom of your function. Add a } around line 234 and that should take care of your error.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Testing for existing user account

By gkornbluth - May 25, 2010 - edited: May 25, 2010

Hi Jason,

Here we go again... I wish I understood these things better.

I added the } at line 234 and that got rid of the original error message.

Now I'm getting this on trying to submit the original password reminder form.
Fatal error: Call to undefined function _websiteLogin_sendPasswordReminder() in /hsphere/local/home/apbcweb/artistsofpalmbeachcounty.org/cmsAdmin/plugins/websiteMembership.php on line 37

Boy I wish I understood this stuff better.

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Testing for existing user account

By Jason - May 25, 2010

Hi Jerry,

What happened is we just put the } in the wrong place. When we did this, we put one function definition inside another, which we can't do.

Take the } out of line 234 and put it in line 182. This should take care of both errors.

Let me know how that works.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Testing for existing user account

By gkornbluth - May 25, 2010

Thanks Jason,

That worked much better. The password reminder is working again.

I'm having a little problem with form required to check for the existence of an e-mail match.

I tried using the form <?php if (!@$CURRENT_USER): ?>
<form action="?" method="post">
<input type="hidden" name="action" value="pastInformation" />
<span class="body-text-bold">Enter your e-mail address:</span>
<input type="text" name="pastInformation" value="<?php echo htmlspecialchars(@$_REQUEST['pastInformation']) ?>" size="20" />
<input type="submit" name="submit" value="Submit" />
</form>

<?php endif ?>


I can't tell if that will work, because I get this error:Notice: Undefined variable: accountsRecords in /hsphere/local/home/apbcweb/artistsofpalmbeachcounty.org/cmsAdmin/plugins/websiteMembership.php on line 180

I've tried to define the $user variable but obviously with no success.

Can I push my luck and ask you to take a look a this once again?

Thanks,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Testing for existing user account

By Jason - May 25, 2010

Hi Jerry,

Are you sure you sent me the most up to date copy of the file? I did a search and couldn't find an instance of the variable $accountsRecords anywhere in the file.

If you define a variable called $accountRecords in one file, you can't reference it in a function unless you pass it in as an argument. Take a look and try to find where you use that variable. Maybe attach both files and I can take a closer look.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Testing for existing user account

By gkornbluth - May 25, 2010 - edited: May 25, 2010

Sorry, the variable in the error message for line 180 is $user

I was trying to solve the problem but never changed the error printout.

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Testing for existing user account

By Jason - May 25, 2010

Hi Jerry,

Yes, the variable $user isn't defined in your function. It would have to be defined inside of the function. However, I don't think that we need it. If all we're doing is seeing if an email address exists in the accounts table, we can replace the entire function like this:

function _websiteLogin_pastInformation() {
global $SETTINGS, $TABLE_PREFIX;

$exists=0;
if(@$_REQUEST['pastInformation']){
$where = "email ='".mysql_escape(@$_REQUEST['pastInformation'])."'";
$exists=mysql_select_count_from('accounts',$where);
}

if ($exists) {
alert("<span class='heading-text-yellow'>Congratulations!!!<br />Your Account Exists</span><br/><span class='body-text-yellow'>You do not need to create a new account.</span>\n");
}
}


In this, the variable $exists will only be true if a) the user entered something into the "pastInformation" text box and b) the email they entered is found in the database.

Give this a try and let me know if this works for you.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Testing for existing user account

By gkornbluth - May 28, 2011

Hi Jason,

In order to hide the form and instructions from the page after the pastInformation form is submitted, I’m using:
<?php if (@$errorsAndAlerts): ?>
<div ><br/>

<?php echo $errorsAndAlerts; ?><br/>
</div>

<?php else: ?>

The Form Code and Instructions...

<?php endif ?>

The problem I’ve got is that if a blank form is submitted, the form is also hidden and only the "address does not exist" alert message is displayed.

This might be the wrong approach, but to handle the submission of a blank form without hiding the form itself, I’ve tried setting up a second "errors and alerts" group.

Here’s what I tried so far, but I get a Fatal error: Call to undefined function alert2() and I'm not sure how to fix the problem.
// submit form
$errorsAndAlerts2 = alert2();
if (@$_REQUEST['submit'] && !@$_REQUEST['pastInformation']) { $errorsAndAlerts2 .= "Please enter an email address<br/><br/>\n"; }


(Hope that all makes sense)

Any insights would be appreciated.

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php