DNN站点用户验证模块Validation具体实现

用户验证模块Validation用于验证S/N条码和生产条码的匹配性,通过验证则赋予注册资格。
具体实现步骤:
1.使用Visual Studio 2005解决方案资源管理器打开DNN站点文件夹DotNetNuke。
2.展开DotNetNuke文件夹,右击DesktopModules文件夹,选择"新建文件夹",并命名为Validation。 
3.右击Validation文件夹,选择"添加新项",然后选择Visual Studio已安装的模板->Web用户控件,名称Validation.ascx,语言选择Visual Basic(或者选择C#,J#,选择你熟悉的即可),勾选"将代码放在单独的文件中"选项,然后单击"添加"。 
4.打开Validation.ascx设计视图,按实际需求设计控件。
 
5.打开Validation.ascx.vb,编写功能模块代码。 
6.功能模块validation设计编写完成后,以host身份登录DNN站点,进入HOST->Module Definitions,选择Create New Module,Name填写EriC Validation,Friendly Name填写Validation,然后一直Next,直到模块创建完成。 
7.返回HOST->Module Definitions,找到刚才创建的模块Validation,点击铅笔图标以Edit this Extension。 
8.进入Configure Validation Extension Settings,点击Select Definition->Add Definition,然后Friendly Name填写Validation,Default Cache Name默认填写0,然后确认Creat Definition。 
9.创建模块定义成功后,出现Module Controls,点击Add Module Control,进入Edit Module Control面板,Source选择DesktopModules/Validation/Validation.ascx,最后点击update。
至此,功能模块Validation成功添加到DNN站点上,以后需要使用时,在Add New Module中选择Validation即可。

 

附:Validation.ascx源代码

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Validation.ascx.vb" Inherits="DesktopModules_Validation_Validation" %> <table> <tr> <td> <asp:Image ID="Image_Label_SNCode" runat="server" ImageUrl="~/images/help.gif" ToolTip="请输入显卡S/N条码" /> <asp:Label ID="Label_SNCode" runat="server" Text="S/N条码"></asp:Label></td> <td> <asp:TextBox ID="TextBox_SNCode" runat="server"></asp:TextBox></td> <td> <asp:Image ID="Image_SNCode" runat="server" ImageUrl="~/images/required.gif" ToolTip="S/N条码为必填项" /> <asp:RequiredFieldValidator ID="RequiredFieldValidator_SNCode" runat="server" ControlToValidate="TextBox_SNCode" ErrorMessage="请输入S/N条码"></asp:RequiredFieldValidator> <asp:RegularExpressionValidator ID="RegularExpressionValidator_SNCode" runat="server" ControlToValidate="TextBox_SNCode" ErrorMessage="S/N条码格式不合法" ValidationExpression="^([a-zA-Z])([a-zA-Z0-9])([a-zA-Z])/d{6}$"></asp:RegularExpressionValidator></td> </tr> <tr> <td> <asp:Image ID="Image_Label_ManufactureCode" runat="server" ImageUrl="~/images/help.gif" ToolTip="请输入显卡生产条码" /> <asp:Label ID="Label_ManufactureCode" runat="server" Text="验证条码"></asp:Label></td> <td> <asp:TextBox ID="TextBox_ManufactureCode" runat="server"></asp:TextBox></td> <td> <asp:Image ID="Image_ManufactureCode" runat="server" ImageUrl="~/images/required.gif" ToolTip="生产条码为必填项" /> <asp:RequiredFieldValidator ID="RequiredFieldValidator_ManufactureCode" runat="server" ControlToValidate="TextBox_ManufactureCode" ErrorMessage="请输入验证条码"></asp:RequiredFieldValidator> <asp:RegularExpressionValidator ID="RegularExpressionValidator_ManufactureCode" runat="server" ControlToValidate="TextBox_ManufactureCode" ErrorMessage="验证条码格式不合法" ValidationExpression="^00000000/d{8}$|^/d{8}$|^/d{12}$|^/d{25}$"></asp:RegularExpressionValidator></td> </tr> <tr> <td> </td> <td>                          <asp:Button ID="Button_Validation" runat="server" Text=" 验证 " /></td> <td> </td> </tr> </table> <table> <tr> <td> <asp:Image ID="Image_Validation" runat="server" Visible="False" /> <asp:Label ID="Label_Validation" runat="server" ForeColor="Red"></asp:Label></td> <td> </td> </tr> <tr> <td> </td> <td> <asp:Image ID="Image_Next" runat="server" ImageUrl="~/Images/action_import.gif" Visible="False" /> <asp:HyperLink ID="HyperLink_Next" runat="server" NavigateUrl="~/Register.aspx" Visible="False">注册</asp:HyperLink></td> </tr> </table>

 

      Validation.ascx.vb源代码

Imports DotNetNuke Imports System.Web.UI Imports System.Collections.Generic Imports System.Reflection Imports DotNetNuke.Security.PortalSecurity Imports System.data Imports System.data.SqlClient Imports System Imports System.Configuration Imports System.Collections Imports System.Web Imports System.Web.Security Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Imports System.Security.Cryptography Partial Class DesktopModules_Validation_Validation Inherits Entities.Modules.PortalModuleBase Protected Sub Button_Validation_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_Validation.Click Dim conn As SqlConnection conn = New SqlConnection("Server=(local);Database=databasename;uid=username;pwd=password") conn.Open() Dim SNCode As String = TextBox_SNCode.Text.Trim() Dim ManufactureCode As String = TextBox_ManufactureCode.Text.Trim() '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim strValidation_IsValid As String = "select IsValid from xjt_Validation where SNCode ='" & Trim(TextBox_SNCode.Text) & "' and IsValid = 1" Dim cmdValidation_IsValid As SqlCommand = New SqlCommand(strValidation_IsValid, conn) Dim DataReader_IsValid As SqlDataReader = cmdValidation_IsValid.ExecuteReader() If DataReader_IsValid.Read() Then Label_Validation.Text = "S/N条码已经注册,请检查!" Image_Validation.ImageUrl = "~/images/deny.gif" Image_Validation.Visible = True Image_Next.Visible = False HyperLink_Next.Visible = False DataReader_IsValid.Close() Else DataReader_IsValid.Close() '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim valueValidation_SNCode As Boolean Dim strValidation_SNCode As String = "select SNCode from xjt_Validation where SNCode ='" & Trim(TextBox_SNCode.Text) & "'" Dim cmdValidation_SNCode As SqlCommand = New SqlCommand(strValidation_SNCode, conn) Dim drValidation_SNCode As SqlDataReader = cmdValidation_SNCode.ExecuteReader() If drValidation_SNCode.Read() Then valueValidation_SNCode = True drValidation_SNCode.Close() Else valueValidation_SNCode = False drValidation_SNCode.Close() End If Dim valueValidation_ManufactureCode As Boolean If TextBox_ManufactureCode.Text.Length = 16 Then Dim strValidation_ManufactureCode As String = "select ManufactureCode from xjt_Validation where SNCode ='" & Trim(TextBox_SNCode.Text) & "' and ManufactureCode ='" & Trim(TextBox_ManufactureCode.Text) & "' " Dim cmdValidation_ManufactureCode As SqlCommand = New SqlCommand(strValidation_ManufactureCode, conn) Dim DataReader_ManufactureCode As SqlDataReader = cmdValidation_ManufactureCode.ExecuteReader() If DataReader_ManufactureCode.Read() Then valueValidation_ManufactureCode = True DataReader_ManufactureCode.Close() Else valueValidation_ManufactureCode = False DataReader_ManufactureCode.Close() End If ElseIf TextBox_ManufactureCode.Text.Length = 12 Then Dim strValidation_ManufactureCode As String = "select ManufactureCode from xjt_Validation where SNCode ='" & Trim(TextBox_SNCode.Text) & "' and ManufactureCode ='" & Trim(TextBox_ManufactureCode.Text) & "' " Dim cmdValidation_ManufactureCode As SqlCommand = New SqlCommand(strValidation_ManufactureCode, conn) Dim DataReader_ManufactureCode As SqlDataReader = cmdValidation_ManufactureCode.ExecuteReader() If DataReader_ManufactureCode.Read() Then valueValidation_ManufactureCode = True DataReader_ManufactureCode.Close() Else valueValidation_ManufactureCode = False DataReader_ManufactureCode.Close() End If ElseIf TextBox_ManufactureCode.Text.Length = 8 Then Dim strValidation_ManufactureCode As String = "select ManufactureCode from xjt_Validation where SNCode ='" & Trim(TextBox_SNCode.Text) & "' and ManufactureCode ='00000000" & Trim(TextBox_ManufactureCode.Text) & "' " Dim cmdValidation_ManufactureCode As SqlCommand = New SqlCommand(strValidation_ManufactureCode, conn) Dim DataReader_ManufactureCode As SqlDataReader = cmdValidation_ManufactureCode.ExecuteReader() If DataReader_ManufactureCode.Read() Then valueValidation_ManufactureCode = True DataReader_ManufactureCode.Close() Else valueValidation_ManufactureCode = False DataReader_ManufactureCode.Close() End If End If If valueValidation_SNCode = True And valueValidation_ManufactureCode = True Then Label_Validation.Text = "恭喜您,通过验证,点击注册进入注册页面!" Image_Validation.ImageUrl = "~/images/grant.gif" Image_Validation.Visible = True Image_Next.Visible = True HyperLink_Next.Visible = True valueValidation_SNCode = False valueValidation_ManufactureCode = False Session.Add("SNCode", TextBox_SNCode.Text) Session.Add("ManufactureCode", TextBox_ManufactureCode.Text) Session.Timeout = 60 ElseIf valueValidation_SNCode = True And valueValidation_ManufactureCode = False Then Label_Validation.Text = "S/N条码与验证条码不匹配,请检查!" Image_Validation.ImageUrl = "~/images/deny.gif" Image_Validation.Visible = True Image_Next.Visible = False HyperLink_Next.Visible = False valueValidation_SNCode = False valueValidation_ManufactureCode = False ElseIf valueValidation_SNCode = False And valueValidation_ManufactureCode = True Then Label_Validation.Text = "S/N条码不存在,请检查!" Image_Validation.ImageUrl = "~/images/deny.gif" Image_Validation.Visible = True Image_Next.Visible = False HyperLink_Next.Visible = False valueValidation_SNCode = False valueValidation_ManufactureCode = False ElseIf valueValidation_SNCode = False And valueValidation_ManufactureCode = False Then Label_Validation.Text = "S/N条码不存在,请检查!" Image_Validation.ImageUrl = "~/images/deny.gif" Image_Validation.Visible = True Image_Next.Visible = False HyperLink_Next.Visible = False valueValidation_SNCode = False valueValidation_ManufactureCode = False End If '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' End If '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' conn.Close() End Sub End Class

你可能感兴趣的:(DNN站点用户验证模块Validation具体实现)