Testing for existing user account

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

Re: [Jason] Testing for existing user account

By gkornbluth - May 30, 2011 - edited: May 30, 2011

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!







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

By Jason - May 30, 2011

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:

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

<?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 - 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 30, 2011

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!







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

By gkornbluth - June 1, 2011

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:

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

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







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

Re: [Jason] Testing for existing user account

By gkornbluth - June 1, 2011

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

// 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!







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

By Jason - June 1, 2011

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 - 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 - June 1, 2011

Thanks

I feel more comfortable now

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