Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old March 27th, 2008, 03:54 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Copenhagen, , Denmark.
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi :)

I'm not sure if I did implement the cleanup. I might have written the procedure, but I don't think my hosting provider allows me to run scheduled SQL tasks :( I'll be sure to check my mail some time soon :)

Cheers.

http://entropia-online.blogspot.com/
  #12 (permalink)  
Old March 27th, 2008, 05:10 AM
Authorized User
 
Join Date: Mar 2008
Location: New York, NY, USA.
Posts: 62
Thanks: 1
Thanked 3 Times in 3 Posts
Send a message via Yahoo to kalel_4444
Default

Hi Peter!

I haven't seen your procedure yet, but the cleanup can be included in the same Activation procedure when a user confirms the account via the email link. It won't be scheduled, but every time a legit user confirms his account it will do a cleanup... Something like adding a:

DELETE FROM where if the asp_Membership.UserId = temp_ActivationTable.UserId AND asp_Membership.CreateDate is <= then 10 days from today, then delete.

No need to worry about deleting users that have a CreateDate more then 10 days and confirmed, because from what you mentioned the UserId won't be in the temp_ActivationTable, so it won't run.

Or better yet, you can execute the procedure every time a user is created. So if these 'dingleberries' as you call them keep adding accounts, they'll be doing the cleanup for you..

Whenever you can, send me what you've done with this thus far, and I'd be happy to contribute with the cleanup.

Thanks,
Ronnie

  #13 (permalink)  
Old March 31st, 2008, 03:13 PM
Friend of Wrox
 
Join Date: Mar 2006
Location: , , Portugal.
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As I said before, if you just add one role: "Temp_User" you can always see witch users didn't activated their logins!



  #14 (permalink)  
Old March 31st, 2008, 06:55 PM
Authorized User
 
Join Date: Mar 2008
Location: New York, NY, USA.
Posts: 62
Thanks: 1
Thanked 3 Times in 3 Posts
Send a message via Yahoo to kalel_4444
Default

Quote:
quote:Originally posted by Maxxim
 As I said before, if you just add one role: "Temp_User" you can always see witch users didn't activated their logins!
Maxxim,

The first time I reviewed your method I wasn't 100% clear and wasn't sure it was direction I wanted to go.

But I just reviewed it again and I see it's the preferred way to go. All the work can be done programmatically!

- No need for another SQL table and a separate SP.
- I can still run cleanup easily by querying for stale registrations in the TempUser role and DELETE.
- And, like you said, I can monitor how many people didn't activate.

Thanks for the repost on this!

  #15 (permalink)  
Old April 1st, 2008, 10:31 AM
Registered User
 
Join Date: Apr 2008
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ViagraFalls -
Could you send me the code for the pages to get this working?

Thanks.

Quote:
quote:Originally posted by ViagraFalls
 Hi kabel,

I've done something along the following:

* User is initially created as inactive. I threw in a captcha during the registration process as well, in an attempt to weed out bots.
* A GUID is created and stored in a temporary table along with the userID and the mail address.
* The user is sent a mail with said link.
* When the user hops to the activation page, the temporary table is checked to verify the existance of the code / mail address combination. If present, the line will be deleted, and the account activated.

I must admit my code doesn't quite stick to the whole TBH approach (in that I do not use objects, but directly fire some procedures), but that ought to be easy enough to change.

Drop me a PM if you'd like to see my implementation :-) (The PM so I'll receive a mail about it, and will remember it).

Cheers,

Peter

http://entropia-online.blogspot.com/
  #16 (permalink)  
Old April 13th, 2008, 05:44 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Copenhagen, , Denmark.
Posts: 143
Thanks: 0
Thanked 1 Time in 1 Post
Default

My apologies about the late reply. I've been rather busy recently.

I altered the Registration page a bit, in order to facilitate the extra work. The captcha control I use came from codeproject. The markup for register.aspx:

Code:
<%@ Page Language="C#" MasterPageFile="~/Template.master" 
    AutoEventWireup="true" CodeFile="Register.aspx.cs" 
    EnableSessionState="False"
    Inherits="EO.EntropiaOnline.UI.Register" 
    Title="EntropiaOnline - Register" %>

<%--<%@ Register Src="Controls\UserProfile.ascx"
    TagName="UserProfile" TagPrefix="EO" %>--%>
<%@ Register Assembly="EO.EntropiaOnline.WebControlCaptcha" 
    Namespace="WebControlCaptcha" TagPrefix="EO" %>

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
    <asp:CreateUserWizard runat="server" ID="CreateUserWizard1" 
        AutoGeneratePassword="false" 
        ContinueDestinationPageUrl="~/Default.aspx"
        FinishDestinationPageUrl="~/Default.aspx"
        LoginCreatedUser="false"
        DisableCreatedUser="true" 
        OnSendingMail="SendMail"
         >
        <%-- OnFinishButtonClick="CreateUserWizard1_FinishButtonClick"--%>
        <WizardSteps>
            <asp:CreateUserWizardStep runat="server">
                <ContentTemplate>
                    <div class="sectiontitle">Create your new account</div>
                    <p></p>
                    <table cellpadding="2">
                        <tr>
                            <td width="155" class="fieldname">UserName:</td>
                            <td width="300">
                                <asp:TextBox runat="server" ID="UserName" Width="100%" />
                            </td>
                            <td>
                                <asp:RequiredFieldValidator ID="valrequiredUserName"
                                    runat="server" ControlToValidate="UserName" 
                                    SetFocusOnError="true" Display="Dynamic"
                                    ErrorMessage="Username is required."
                                    ValidationGroup="CreateUserWizard1">*
                                </asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td class="fieldname">Password:</td>
                            <td>
                                <asp:TextBox runat="server" ID="Password"
                                    TextMode="Password" Width="100%" />
                            </td>
                            <td>
                                <asp:RequiredFieldValidator ID="valRequiredPassword"
                                    runat="server" ControlToValidate="Password" 
                                    SetFocusOnError="true" Display="Dynamic"
                                    ErrorMessage="Password is required."
                                    ValidationGroup="CreateUserWizard1">*
                                </asp:RequiredFieldValidator>
                                <asp:RegularExpressionValidator ID="valPasswordLength"
                                    runat="server" ControlToValidate="Password"
                                    SetFocusOnError="true" Display="Dynamic"
                                    ValidationExpression="\w{5,}"
                                    ErrorMessage="Password must be at least 5 characters long."
                                    ValidationGroup="CreateUserWizard1">*
                                </asp:RegularExpressionValidator>
                            </td>
                        </tr>
                        <tr>
                            <td class="fieldname">Confirm password:</td>
                            <td>
                                <asp:TextBox runat="server" ID="ConfirmPassword"
                                    TextMode="Password" Width="100%" />
                            </td>
                            <td>
                                <asp:RequiredFieldValidator ID="valrequiredConfirmPassword"
                                    runat="server" ControlToValidate="ConfirmPassword" 
                                    SetFocusOnError="true" Display="Dynamic"
                                    ErrorMessage="Confirm password is required."
                                    ValidationGroup="CreateUserWizard1">*
                                </asp:RequiredFieldValidator>
                                <asp:CompareValidator ID="valComparePasswords" runat="server"
                                    ControlToCompare="Password" SetFocusOnError="true" 
                                    ControlToValidate="ConfirmPassword" Display="Dynamic"
                                    ErrorMessage="Password and Confirmation Password must match."
                                    ValidationGroup="CreateUserWizard1">*
                                </asp:CompareValidator>
                            </td>
                        </tr>
                        <tr>
                            <td class="fieldname">E-mail:</td>
                            <td>
                                <asp:TextBox runat="server" ID="Email" Width="100%" 
                                    Text='<%# Email %>' />
                            </td>
                            <td>
                                <asp:RequiredFieldValidator ID="valRequiredEmail"
                                    runat="server" ControlToValidate="Email" 
                                    SetFocusOnError="true" Display="Dynamic"
                                    ErrorMessage="Email is required."
                                    ValidationGroup="CreateUserWizard1">*
                                </asp:RequiredFieldValidator>
                                <asp:RegularExpressionValidator ID="valEmailPattern" runat="server"
                                    Display="Dynamic" SetFocusOnError="true" 
                                    ControlToValidate="Email" 
                                    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                                    ErrorMessage="The format of the E-mail address is invalid."
                                    ValidationGroup="CreateUserWizard1">*
                                </asp:RegularExpressionValidator>
                            </td>
                        </tr>
                        <tr>
                            <td class="fieldname">Security question:</td>
                            <td>
                                <asp:TextBox runat="server" ID="Question" Width="100%" />
                            </td>
                            <td>
                                <asp:RequiredFieldValidator ID="valRequiredQuestion"
                                    runat="server" ControlToValidate="Question" 
                                    SetFocusOnError="true" Display="Dynamic"
                                    ErrorMessage="Security question is required."
                                    ValidationGroup="CreateUserWizard1">*
                                </asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td class="fieldname">Security answer:</td>
                            <td>
                                <asp:TextBox runat="server" ID="Answer" Width="100%" />
                            </td>
                            <td>
                                <asp:RequiredFieldValidator ID="valRequiredAnswer"
                                    runat="server" ControlToValidate="Answer" 
                                    SetFocusOnError="true" Display="Dynamic"
                                    ErrorMessage="Security answer is required."
                                    ValidationGroup="CreateUserWizard1">*
                                </asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td></td>
                            <td colspan="3" align="right">
                                <asp:Label ID="ErrorMessage" SkinID="FeedbackKO" runat="server"
                                    EnableViewState="false" />
                            </td>
                        </tr>
                    </table>
                    <p></p>
                    In order to stop automated programs that will sign up
                    to spam the site and forum, please enter the code you 
                    see in the generated image:
                    <p></p>
                    <EO:CaptchaControl ID="CaptchaControl1" runat="server" 
                        CaptchaHeight="50" Text=""
                        CaptchaLineNoise="Low" CaptchaWidth="150" CssClass="fieldname" />
                    <asp:ValidationSummary ValidationGroup="CreateUserWizard1"
                        ID="ValidationSummary1" runat="server" ShowMessageBox="True"
                        ShowSummary="False" />
                </ContentTemplate>
            </asp:CreateUserWizardStep>

<%--            <asp:WizardStep runat="server" Title="Set preferences">
                <div class="sectiontitle">Set up your profile</div>
                <p></p>All settings in this section are required only if you want to order
                products from our e-store. However, we ask you to fill in these details in
                all cases, because they help us know our target audience, and improve the
                site and its contents accordingly. Thank you for your cooperation!
                <p></p>
                <EO:UserProfile ID="UserProfile1" runat="server" />
            </asp:WizardStep>--%>
<%--            <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="Server"  />
--%>   
            <asp:CompleteWizardStep runat="Server" ID="CompleteWizardStep1" >
                <ContentTemplate>
                    <b>Congratulations! You have succesfully signed up for the site.</b>
                    <p></p>
                    You will receive an E-mail shortly containing a confirmation link and
                    code. Your registration will not be complete until after you followed
                    the instructions in the mail.
                    <p></p>
                    Hotmail and/or Yahoo users, if you do not get an E-mail within 10 minutes,
                    try checking your "Junk mail" folder. 
                    <p></p>
                    The code in the E-mail is only valid for 48 hours, so be sure to check
                    before those expire.
                    <p></p>
                    Kind regards, and may the HOF be with you!
                    <p></p>
                    The EntropiaOnline team!
                </ContentTemplate>
            </asp:CompleteWizardStep>
        </WizardSteps>
        <MailDefinition
            BodyFileName="~/RegistrationMail.txt"
            From="webmaster@EntropiaOnline.com"
            Subject="EntropiaOnline - Welcome!"
            />
    </asp:CreateUserWizard>
</asp:Content>
The asp code:

Code:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
using EO.EntropiaOnline;

namespace EO.EntropiaOnline.UI
{
    public partial class Register : System.Web.UI.Page
    {
        protected string Email = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack && !string.IsNullOrEmpty(this.Request.QueryString["Email"]))
            {
                Email = this.Request.QueryString["Email"];
                CreateUserWizard1.DataBind();
            }
        }

        protected void SendMail(object sender, MailMessageEventArgs e)
        {
            // Generate a GUID
            Guid guidResult = System.Guid.NewGuid();

            string path = "<a href=" + (char)32;

            string url = "http://www.EntropiaOnline.com/ValidateUser.aspx"; 
            path += url + "?email=" + CreateUserWizard1.Email + "&GUID=" + guidResult.ToString() +
                (char)32 + ">" + url + "?email=" + CreateUserWizard1.Email + "&GUID=" +
                guidResult.ToString() + "</a>";

            e.Message.IsBodyHtml = true;
            e.Message.Body = e.Message.Body.Replace("<%Link%>", path);
            e.Message.Body = e.Message.Body.Replace("<%Page%>", url);
            e.Message.Body = e.Message.Body.Replace("<%GUID%>", guidResult.ToString());

            // Make sure that the GUID and E-mail address also get stored
            // into the database
            using (SqlConnection cn = new SqlConnection(Globals.Settings.Articles.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand(
                    "aspnet_Membership_CreateUserValidationDetails", cn);

                cmd.Parameters.Add("@EmailAddress", SqlDbType.NVarChar, 50).Value = CreateUserWizard1.Email;
                cmd.Parameters.Add("@GUID", SqlDbType.UniqueIdentifier).Value = guidResult;
                cmd.Parameters.Add("@DateEntered", SqlDbType.DateTime).Value = DateTime.Now;
                cmd.CommandType = CommandType.StoredProcedure;
                cn.Open();
                cmd.ExecuteNonQuery();
            }

            //// Just for now, we get a mail as well. Cause we're cool and stuff.
            //MailMessage adminMail = new MailMessage();
            //adminMail.To = "admin@entropiaonline.com";
            //adminMail.From = "booyah@entropiaonline.com";
            //adminMail.Body = "Hi! A new user just signed up: " + CreateUserWizard1.UserName;
            //adminMail.Body += "\r\n";
            //adminMail.Body += "Booyah!";

            //SmtpMail.Send(adminMail);
        }
    }
}
The last commented bit was intended to receive a mail myself whenever a new user signs up, but it threw errors, so I disabled that. Should anyone want to try this and find a solution, please feel free to add the working code :)

The validateUser page - markup:

Code:
<%@ Page Language="C#" MasterPageFile="~/Template.master" 
    AutoEventWireup="true" CodeFile="ValidateUser.aspx.cs" 
    Inherits="EO.EntropiaOnline.UI.ValidateUser" 
    Title="EntropiaOnline - Validate useraccount" %>
<asp:Content ID="Content1" ContentPlaceHolderID="RightContent" Runat="Server">
</asp:Content>
<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" Runat="Server">
<div class="sectiontitle">Validate useraccount</div>
<asp:Panel runat="server" ID="panIntro">
<p></p>
Please enter your E-mail address and the registration code you received in your
registration mail into the textboxes below to finish the registrationprocess.
<p />
Thanks!
<br />
The EntropiaOnline team.
<p></p>

<div class="sectiontitle">Create your new account</div>
<p></p>
<table cellpadding="2">
    <tr>
        <td class="fieldname">E-mail:</td>
        <td width="300">
            <asp:TextBox runat="server" ID="txtEmail" Width="100%" />
        </td>
        <td>
            <asp:RequiredFieldValidator ID="valRequiredEmail"
                runat="server" ControlToValidate="txtEmail" 
                SetFocusOnError="true" Display="Dynamic"
                ErrorMessage="Email is required."
                ValidationGroup="CreateUserWizard1">*
            </asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="valEmailPattern" runat="server"
                Display="Dynamic" SetFocusOnError="true" 
                ControlToValidate="txtEmail" 
                ValidationExpression="\w+@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                ErrorMessage="The format of the E-mail address is invalid."
                ValidationGroup="CreateUserWizard1">*
            </asp:RegularExpressionValidator>
        </td>
    </tr>
    <tr>
        <td class="fieldname">Registration code:</td>
        <td width="300">
            <asp:TextBox runat="server" ID="txtRegistrationCode" Width="100%" />
        </td>
        <td>
            <asp:RequiredFieldValidator ID="valRequiredRegistrationCode"
                runat="server" ControlToValidate="txtRegistrationCode" 
                SetFocusOnError="true" Display="Dynamic"
                ErrorMessage="Registration code is required."
                ValidationGroup="CreateUserWizard1">*
            </asp:RequiredFieldValidator>
        </td>
    </tr>
</table>
</asp:Panel>
<table cellpadding="2">
    <tr>
    <td colspan="3" style="text-align: right;">
        <asp:Label runat="server" ID="lblFeedbackKO" Text="Sorry, there was a problem activating your account. Please verify you entered the proper values." SkinID="FeedbackKO" Visible="false" />
        <asp:Button runat="server" ID="btnActivate" Text="Activate!"
            OnClick="btnActivate_Click" /></td>
    </tr>
    </table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="LeftContent" Runat="Server">
</asp:Content>
And asp code:
Code:
using System;
using System.Data;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace EO.EntropiaOnline.UI
{
    public partial class ValidateUser : System.Web.UI.Page
    {
        private string Email = "";
        private string RegistrationCode = "";
        private string UserName = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack && 
                    !string.IsNullOrEmpty(this.Request.QueryString["Email"]) && 
                    !string.IsNullOrEmpty(this.Request.QueryString["Guid"]))
            {
                RegistrationCode = this.Request.QueryString["Guid"];
                Email = this.Request.QueryString["Email"];
                ValidateAccount();
            }
        }

        protected void btnActivate_Click(object sender, EventArgs e)
        {
            Email = txtEmail.Text;
            RegistrationCode = txtRegistrationCode.Text;
            ValidateAccount();
        }

        protected void ValidateAccount()
        {
            Guid guid = new Guid(RegistrationCode);

            using (SqlConnection cn = new SqlConnection(Globals.Settings.Articles.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand(
                    "aspnet_Membership_ValidateUserDetails", cn);

                cmd.Parameters.Add("@EmailAddress", SqlDbType.NVarChar, 50).Value = Email;
                cmd.Parameters.Add("@GUID", SqlDbType.UniqueIdentifier).Value = 
                     guid;
                cmd.Parameters.Add("@UserName", SqlDbType.NVarChar, 256).Direction = ParameterDirection.Output;

                cmd.CommandType = CommandType.StoredProcedure;
                cn.Open();

                try
                {
                    cmd.ExecuteNonQuery();

                    // If we got here, the user is now validated and enabled. We will
                    // also add the user to the Poster role so they can start posting
                    // on the forum
                    UserName = (string)cmd.Parameters["@UserName"].Value;
                    Roles.AddUserToRole(UserName, "Posters");

                    // And finally we redirect the user to the rules.
                    Response.Redirect("SiteRules.aspx");
                }

                catch (Exception ex)
                {
                    lblFeedbackKO.Visible = true;
                    lblFeedbackKO.Text = lblFeedbackKO.Text + " - " + ex.Message;
                }
            }
        }
    }
}
Currently, ,my evaluation version of SQL Server expired, so I'm unable to retrieve the code for the procedures, but they're pretty straight forward.

Let me know if I missed anything in which case I'll alter it. Also, again, note this does not use the regular object oriented approach Marco uses, but was a quick hack in order to achieve some quick results.

http://entropia-online.blogspot.com/
The Following User Says Thank You to ViagraFalls For This Useful Post:
Calvin63 (November 11th, 2009)
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending email problem - SMTP server response: 554 Havokx Beginning PHP 0 July 27th, 2007 04:04 AM
Registration Form Help invisible bunny king Classic ASP Databases 7 February 5th, 2007 05:30 PM
COM+ components registration ajindal General .NET 1 September 1st, 2006 03:31 AM
Registration database jacob C# 2 January 22nd, 2004 01:25 PM



All times are GMT -4. The time now is 01:58 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.