Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder: Plugins & Add-ons:
Testing for existing user account

 

 


gkornbluth
Veteran

May 23, 2010, 8:25 AM

Post #1 of 18 (9306 views)
Shortcut
Testing for existing user account Can't Post

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:


Code
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 line

Code
if (@$_REQUEST['action'] == 'pastInformation') { _websiteLogin_pastInformation(); }



Then above the existing:

Code
 function _websiteLogin_sendPasswordReminder() { 
global $SETTINGS, $TABLE_PREFIX;

I added;

Code
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).

Code
<?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

(This post was edited by gkornbluth on May 23, 2010, 8:31 AM)
Attachments: websiteMembership2.php (9.99 KB)


Jason
Staff / Moderator


May 25, 2010, 10:02 AM

Post #2 of 18 (8745 views)
Shortcut
Re: [gkornbluth] Testing for existing user account [In reply to] Can't Post

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 - Programmer 
interactivetools.com

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


gkornbluth
Veteran

May 25, 2010, 11:43 AM

Post #3 of 18 (8742 views)
Shortcut
Re: [Jason] Testing for existing user account [In reply to] Can't Post

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.

Code
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

(This post was edited by gkornbluth on May 25, 2010, 11:44 AM)
Attachments: websiteMembership2.php (9.99 KB)


Jason
Staff / Moderator


May 25, 2010, 12:04 PM

Post #4 of 18 (8738 views)
Shortcut
Re: [gkornbluth] Testing for existing user account [In reply to] Can't Post

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 - Programmer 
interactivetools.com

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


gkornbluth
Veteran

May 25, 2010, 12:32 PM

Post #5 of 18 (8732 views)
Shortcut
Re: [Jason] Testing for existing user account [In reply to] Can't Post

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

Code
<?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:

Code
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
Attachments: websiteMembership2.php (9.99 KB)


Jason
Staff / Moderator


May 25, 2010, 12:41 PM

Post #6 of 18 (8731 views)
Shortcut
Re: [gkornbluth] Testing for existing user account [In reply to] Can't Post

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 - Programmer 
interactivetools.com

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


gkornbluth
Veteran

May 25, 2010, 12:47 PM

Post #7 of 18 (8730 views)
Shortcut
Re: [Jason] Testing for existing user account [In reply to] Can't Post

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!
http://www.thecmsbcookbook.com

(This post was edited by gkornbluth on May 25, 2010, 12:52 PM)


Jason
Staff / Moderator


May 25, 2010, 1:12 PM

Post #8 of 18 (8726 views)
Shortcut
Re: [gkornbluth] Testing for existing user account [In reply to] Can't Post

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:


Code
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 - Programmer 
interactivetools.com

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


gkornbluth
Veteran

May 25, 2010, 1:24 PM

Post #9 of 18 (8724 views)
Shortcut
Re: [Jason] Testing for existing user account [In reply to] Can't Post

Jason,

You've done it again.

I've learned sooo... much from you.

Thanks,

Jerry


gkornbluth
Veteran

May 28, 2011, 6:32 AM

Post #10 of 18 (4135 views)
Shortcut
Re: [Jason] Testing for existing user account [In reply to] Can't Post

Hi Jason,

In order to hide the form and instructions from the page after the pastInformation form is submitted, I’m using:

Code
<?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.

Code
// 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!
http://www.thecmsbcookbook.com


Jason
Staff / Moderator


May 30, 2011, 9:50 AM

Post #11 of 18 (4002 views)
Shortcut
Re: [gkornbluth] Testing for existing user account [In reply to] Can't Post

Hi Jerry,

There's isn't a function defined in CMS Builder called alert2(), so that's where that error is coming from.

To be sure I understand what you're trying to do, when a form is submitted, if there are errors, you want to display the form and the errors. If the form is submitted and there are no errors, you want to display a message, but not the form. Is that right?

If so, I would suggest a different approach. You can create a variable called $success and set it equal to false. You only set $success to true if the form was submitted successfully with no errors:

Example:


Code
<?php 

$success = false;
$errorsAndAlerts = "";

if (@$_REQUEST['submit']) { // form has been submitted

// error checking

...

if (!$errorsAndAlerts) { // no errors found

// code executed when form is submitted successfully

$errorsAndAlerts = "Congratulations! Your form was submitted successfully!";
$success = true;
}

}
?>


Then you can output $errorsAndAlerts whenever it has a value (either an error message or a success message) and decide whether or not to display the form independently like this:


Code
<?php if (@$errorsAndAlerts): ?>  
<div ><br/>

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

<?php endif: ?>

<?php if (!$success): ?>

The Form Code and Instructions...

<?php endif ?>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

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


gkornbluth
Veteran

May 30, 2011, 10:56 AM

Post #12 of 18 (3999 views)
Shortcut
Re: [Jason] Testing for existing user account [In reply to] Can't Post

Thanks Jason,

Actually what I'm trying to do is display 2 separate (groups of) error messages and either show or hide the form and instructions depending on which message is displayed.

EXISTS NOW
The conditions which exist now, as alert():

A) Display a success message if the email address is found and a failure message if the email address is not found.

B) Hide the instructions and the form since their purpose has been accomplished, thus focusing the applicant on the next step in the signup process.

TO ADD
What I was trying to do with alert2() was to add a separate error message that shows only if the form is blank when submitted.

This condition would not hide the form or the instructions, allowing the applicant to try again.

Hope that makes more sense,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!
http://www.thecmsbcookbook.com

(This post was edited by gkornbluth on May 30, 2011, 12:38 PM)


Jason
Staff / Moderator


May 30, 2011, 1:38 PM

Post #13 of 18 (3991 views)
Shortcut
Re: [gkornbluth] Testing for existing user account [In reply to] Can't Post

Hi Jerry,

How about this:

You can still use $errorsAndAlerts to display all messages, but then set another variable to decide if you should display the form or not. You would default this variable to true so that you show the form when the page first loads.

So the top of your page would look like this:


Code
<?php 

$errorsAndAlerts = "";
$showForm = true;

if (@$_REQUEST['submit']) {

if (!@$_REQUEST['pastInformation']) {
$errorsAndAlerts = "Please enter an email address<br/><br/>\n";

}

if (!$errorsAndAlerts) {
$showForm = false;

// check if the email address exists
}
}
?>


And the display portion of your page would look like this:


Code
<?php if (@$errorsAndAlerts): ?>   
<div ><br/>

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

<?php endif ?>

<?php if ($showForm): ?>

The Form Code and Instructions...

<?php endif ?>


Does this look more like what you're looking for?
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

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


gkornbluth
Veteran

May 30, 2011, 2:05 PM

Post #14 of 18 (3988 views)
Shortcut
Re: [Jason] Testing for existing user account [In reply to] Can't Post

Thanks Jason,

I'll plug it in and give it a try.

You're the best

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!
http://www.thecmsbcookbook.com


gkornbluth
Veteran

Jun 1, 2011, 5:47 AM

Post #15 of 18 (3965 views)
Shortcut
Re: [gkornbluth] Testing for existing user account [In reply to] Can't Post

Hi Jason,

What I ended up with, which is similar to what you suggested is the following. Hope it helps someone else.

There's a lot more on this topic, including the changes required in the Website Membership plugin to make it all work, in my CMSB Cookbook http://www.thecmsbcookbook.com

Again, thanks for all your help,

Jerry Kornbluth
__________________________

At the top of the page, I used:


Code
<?php if (!@$GLOBALS['WEBSITE_MEMBERSHIP_PLUGIN']) { die("You must activate the Website Membership plugin before you can access this page."); } ?> 
<?php
// clear errors and set form to show on page load
$errorsAndAlerts = "";
$showForm = true;

if (@$_REQUEST['submit']) {
$showForm = false;
if (!@$_REQUEST['pastInformation']) {
$emptyField = "<span class='heading-text-yellow'>Please enter an email address<br/><br/></span>\n";
$showForm = true;
}
}
// error checking
$errorsAndAlerts = alert();

if (@$CURRENT_USER) {
$errorsAndAlerts = "<span class='heading-text-yellow'>YOU ARE ALREADY LOGGED IN!</span><br><a class='special' href='{$GLOBALS['WEBSITE_LOGIN_POST_LOGIN_URL']}'>CLICK HERE TO CONTINUE TO THE WEB SITE</a> or <a class='special' href='?action=logoff'>LOG OUT</a>.";
}

?>


Then in the body of the page.


Code
<?php if (@$emptyField): ?> 
<?php $showform = true; ?>
<div ><br/><?php echo $emptyField; ?></div>

<?php elseif (@$errorsAndAlerts): ?>
<?php $showform = false; ?>
<div ><br/><?php echo $errorsAndAlerts; ?><br/></div>

<?php else: ?>

...some code and text that shows if there are no errors...

<?php if ($showForm == 'true'): ?>

... some text that shows only when $showform is "true"...

<?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 ?>

...more instructions that show when there are no errors...

<?php endif ?>

The first CMS Builder reference book is now available on-line!
http://www.thecmsbcookbook.com


gkornbluth
Veteran

Jun 1, 2011, 7:16 AM

Post #16 of 18 (3963 views)
Shortcut
Re: [Jason] Testing for existing user account [In reply to] Can't Post

Hi Jason,

My question is, is what I've done below OK, or have I opened up either security or other issues?

I wanted to allow a member who received a no record available error after submitting their email address, to be able to return to the previous page and try again with another address.

Since the error code is in the Membership Plugin, and will be called from more than one page, I added the code in red:

Thanks,

Jerry Kornbluth


Code
// Existing Account Request 
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);
}
$ref=@$HTTP_REFERER;
if ($exists) {
alert("<span class='heading-text-yellow'>Congratulations!!!<br />Your Account Information Exists</span><br /><span class='body-text-yellow'>You don't
need to create a new account, just use the link below to pay your current year's dues.<br /></span>\n");
}
if (!$exists) {
alert("<span class='heading-text-yellow'>Sorry!!!<br />Your Account Information No Longer Exists</span><br /><span class='body-text-yellow'>You'll have to fill out a new membership application after you you've paid your current year's dues.<br />To search for your information using another email address
<a href='$ref'><span class='heading-text-yellow'>CLICK HERE</span></a>
<br /></span>\n");

}
}

The first CMS Builder reference book is now available on-line!
http://www.thecmsbcookbook.com


Jason
Staff / Moderator


Jun 1, 2011, 9:10 AM

Post #17 of 18 (3959 views)
Shortcut
Re: [gkornbluth] Testing for existing user account [In reply to] Can't Post

Hi Jerry,

Since all the function is really doing is checking to see if a value exists in the database, I don't see any security issues. The only issue with putting it inside the membership plugin is that if you ever need to upgrade the plugin, your changes will be overwritten.

A good approach to take would be to create a plugin that uses no hooks where you can put in custom functions. Since these functions are inside a plugin, they're available on any page that connects to CMS Builder.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Programmer 
interactivetools.com

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


gkornbluth
Veteran

Jun 1, 2011, 9:39 AM

Post #18 of 18 (3958 views)
Shortcut
Re: [Jason] Testing for existing user account [In reply to] Can't Post

Thanks

I feel more comfortable now

Jerry
The first CMS Builder reference book is now available on-line!
http://www.thecmsbcookbook.com