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! |
This demonstration gives you an overview of IBM® Rational® Build Forge Express Edition, a global offering that provides a framework to automate and execute software processes. Rational Build Forge provides a software assembly line that can support all of your tools, technologies, and platforms so you can achieve a repeatable, reliable, and traceable build and release process. FREE! Go There Now!
|
|
|
|
Hear how IBM Rational Project and Portfolio Management integrated solutions help teams put the right tools and processes in place to maximize the effectiveness and efficiency of project teams and ensure that the business vision is being executed correctly. Learn how to automate and integrate requirements prioritization, top-down project planning, communications and controls, and methodology deployment to keep your scope, costs, and schedules under control. Tackle with an end-to-end approach the management of scope and scope changes, usage of methodology to control and empower project teams, and optimization of resources to align activity costs with the overall project plan. FREE! Go There Now!
|
|
|
|
The XO laptop (of the One-Laptop-Per-Child initiative) is an inexpensive laptop project intended to help educate children around the world. The XO laptop includes many innovations, such as a novel, inexpensive, and durable hardware design and the use of GNU/Linux as the underlying operating system. The XO also includes an application environment written in Python with a human interface called Sugar, accessible to everyone (including kids). Explore the Sugar APIs and learn how to develop and debug a graphical activity in Sugar using Python. FREE! Go There Now!
|
|
|
|
Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM DB2 9.5 for Linux, UNIX, and Windows. DB2 9 is the result of a five-year development project that transformed traditional (static) database technology into an interactive data server that merges the high performance and ease of use of DB2 with the self-describing benefits of XML. FREE! Go There Now!
|
|
|
|
Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization. FREE! Go There Now!
|
|
|
|
Rational Build Forge Express Edition is an automation framework that packages the latest enterprise-grade technologies into a reliable, flexible and robust configuration designed and priced specifically for small to midsize businesses. The new Rational Build Forge Express eKit provides you with valuable resources – including a case study, podcast, demo, and articles – to help you increase staff productivity, compress development cycles and deliver better software, fast. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Tester for SOA Quality V7.0.1, a functional and regression testing tool that enables the creation, comprehension, modification and execution of testing GUI-less Web services. FREE! Go There Now!
|
|
|
|
Learn how IBM Rational Tester for SOA Quality addresses IBM WebSphere MQ with Web services. You get hands-on experience in creating a test, handling the WebSphere MQ series protocol, configuring the test, and then replaying it. FREE! Go There Now!
|
|
|
|
The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |