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