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! |
Learn field-tested SOA principles, methodology, technology and implementation from the global SOA market leader - in a new e-book by an IBM SOA expert. Written by IBM Certified SOA Solution Designer Bobby Woolf, "Exploring IBM SOA Technology & Practice" is the ultimate insider's guide to SOA - a PDF e-book packed cover to cover with IBM's specific advice on how to make your SOA implementation a success. 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!
|
|
|
|
WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
|
|
|
|
Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points. FREE! Go There Now!
|
|
|
|
Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services. FREE! Go There Now!
|
|
|
|
As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br /> 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 Functional Tester V7.0.1. Rational Functional Tester is an automated functional and regression testing solution for QA teams concerned with the quality of their Java, Microsoft Visual Studio .NET, and Web-based applications. FREE! Go There Now!
|
|
|
|
The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |