When it comes to ASP coding, James is a guru. In this tutorial James will prepare you so you can go ahead and remove unconfimed members from your own membership system.
One part of my membership system is that members have to confirm their email address by clicking on a link sent to them. As it turned out, this was the easy part to implement! (Read the article to see how it was done.)
The more complicated part was to manage the removal of members that didn't confirm their email.
Doing it Manually
The concept was simple. The prospective user is told when they sign up that they must confirm within 10 days, or the account will be deleted.
What I have been doing (manually, believe it or not) is sending out an email reminder on the 9th day. When the prospective member replied to me, I'd edit the database appropriately.
With the traffic doubling each month, it didn't take me long to realize this was a short-term solution!
Doing it Automatically
I've talked before about my BrandNewDay( ) function, and how it gets called once per day.
Sending out emails to members unconfirmed for 9 days, and deleting at 10 days is another example of how I use this function. To start with I added another call to BrandNewDay( )...
// ============================================
// anything that needs doing once per day!
// ============================================
function BrandNewDay ( )
{
if ( Application ( 'BrandNewDay' ) == 1 )
{
// now set data into Application variables
Application.Lock ( );
Application ( 'BrandNewDay' ) = 0;
Application.Unlock ( );
// send out email or delete unconfirmed members
RemindMembers ( );
}
}
...and then I just had to write the function RemindMembers!
function RemindMembers ( )
{
// get cutoff date, which is todays date - 10 days
var dCutoff = new Date;
var nDate = dCutoff.getDate ( ) - 10;
dCutoff.setDate ( nDate );
// get email date, which is todays date - 11 days
var dEmail = new Date;
dEmail.setDate ( nDate-1 );
nDate = dEmail.getDate ( );
// not get the members that are not confirmed after 10 days
DBInitConnection ( );
DBGetRecords ( 'SELECT MemberID,Email,Name,LastVisit FROM Members WHERE Confirmed=False AND LastVisit<=' + DBWrapDate ( FormatDateDMY ( dCutoff ) ) );
I started by getting today's date and setting dCutoff and dEmail to 10 and 11 days earlier respectively. I then opened the database and queried it for all records in the Members table that had been unconfirmed for that long.
The simple loop below then went through each record in turn, and either emailed the user that he had one day left to confirm his membership, or deleted the record.
I'll show you the details of those two processes in the next few pages.
while ( !oRecordSet.EOF )
{
var nID = oRecordSet ( 0 ) - 0;
var dDate = new Date ( oRecordSet ( 3 ) );
// either send an email, or delete them..
if ( dDate.getDate ( ) == nDate )
{
// send email
}
else
{
// delete them
}
oRecordSet.moveNext ( );
}
Emailing a Reminder
I wanted to email the prospective member, and give the option in the email to quickly confirm his membership, so I used the same code as in the original sign up page to include the link to C.asp. Of course, it's possible that I should have moved this "duplicate code" into an SSI, but I judged that the duplication was minimal.
if ( dDate.getDate ( ) == nDate )
{
var sEmail = '' + oRecordSet ( 1 );
var sName = '' + oRecordSet ( 2 );
var sDate = FormatDateDMY ( dDate );
// send Email with our generic function
var sBody = 'Dear ' + sName + '\n\n';
sBody += 'Today is your last chance to confirm your membership on CoverYourASP.com!\n\n';
sBody += 'Membership accounts have to be confirmed via email - and unconfirmed accounts are only kept for 10 days. Since you registered on ' + sDate + ' your membership account will be deleted tomorrow unless you confirm your account.\n\n';
sBody += 'To confirm your CoverYourASP membership account please click on the link below, or copy and paste the entire URL into your browser.\n\n';
sBody += 'IMPORTANT: if the link below is wrapped onto two lines by your email software please copy from the "http" to the end of the number on the second line, then paste that into your browser.\n\n';
sBody += 'http://CoverYourASP.com/C.asp?a=a&e=' + sEmail + '&i=' + nID + '\n\n';
sBody += 'I hope to hear back from you soon!\n\n';
sBody += 'Member Services\n';
sBody += 'MemberServices@CoverYourASP.com\n';
sBody += 'http://CoverYourASP.com/';
if ( -1 == sServer.indexOf ( 'localhost' ) )
SendEmail ( 'MemberServices@' + sHostDomain, sEmail, '', 'Final Notice: Lapsing CoverYourASP membership', sBody );
}
Fairly straight-forward code I hope you'll agree. Get the email and name of the member from the recordset, then make up the body of the email in the sBody variable.
Two things to note:
The use of \n as a linefeed in JavaScript.
How I don't send the email if running from localhost, i.e. my development machine! The sServer variable is set globally in Init( ), and contains the value of Request.ServerVariables ( 'SERVER_NAME' ).
Deleting Unconfirmed Members
Deleting the members still unconfirmed after 10 days was done by looping through the records, and making up a SQL statement that included all of the member ID's.
That way I only had one SQL statement to execute, outside of the loop.
var sDelete = '';
while ( !oRecordSet.EOF )
{
var nID = oRecordSet ( 0 ) - 0;
var dDate = new Date ( oRecordSet ( 3 ) );
// either send an email, or delete them..
if ( dDate.getDate ( ) == nDate )
{
...
}
else
{
if ( sDelete.length )
sDelete += ' OR ';
sDelete += 'MemberID=' + nID;
}
oRecordSet.moveNext ( );
}
if ( sDelete.length )
oConnection.Execute ( 'DELETE FROM Members WHERE ' + sDelete );
And that's it. The first new visitor to arrive on my site after midnight (server time) will cause the RemindMembers( ) function to be called, and unconfirmed members dealt with as appropriate.
And one less job for me to do manually, which I personally think is very cool!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Articles
More By James Shaw
developerWorks - FREE Tools! |
Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br /> FREE! Go There Now!
|
|
|
|
Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects. FREE! Go There Now!
|
|
|
|
Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server. FREE! Go There Now!
|
|
|
|
Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered! FREE! Go There Now!
|
|
|
|
This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components. FREE! Go There Now!
|
|
|
|
Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |