实验室网站:用户登录

2017-07-09 21:00:23  访问(1894) 赞(0) 踩(0)


  • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserLogin.aspx.cs" Inherits="UserLogin" ValidateRequest="false" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>用户登录__<%=WB.AdminTitle %>
        </title>
    
        <script language="javascript" type="text/javascript">
    
            function win_top() {
                if (window.top != null && window.self != null && top.location != self.location)
                    window.top.location = window.self.location;
            }
    
            win_top();
    
        </script>
    </head>
    <body style="margin: 0px;">
        <form id="form1" runat="server">
            <table width="100%" height="166" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td height="42" valign="top">
                        <table width="100%" height="42" border="0" cellpadding="0" cellspacing="0" class="login_top_bg">
                            <tr>
                                <td width="1%" height="21">&nbsp;
                                </td>
                                <td height="42">&nbsp;
                                </td>
                                <td width="17%">&nbsp;
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td valign="top">
                        <table width="100%" height="532" border="0" cellpadding="0" cellspacing="0" class="login_bg">
                            <tr>
                                <td width="49%" align="right">
                                    <table width="91%" height="532" border="0" cellpadding="0" cellspacing="0" class="login_bg2">
                                        <tr>
                                            <td height="138" valign="top">
                                                <table width="89%" height="427" border="0" cellpadding="0" cellspacing="0">
                                                    <tr>
                                                        <td height="149">&nbsp;
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td height="80" align="right" valign="middle">
                                                            <img src="<%=WB.AdminThemes %>/images/login/logo.png" alt="" width="65" height="68"
                                                                border="0" /><font style="font-size: 22px; font-weight: bold; color: Blue;">
                                                                    <%=WB.AdminTitle %></font>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td height="198" align="right" valign="top">
                                                            <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                                                <tr>
                                                                    <td width="35%">&nbsp;
                                                                    </td>
                                                                    <td height="25" colspan="2" class="left_txt" align="left"></td>
                                                                </tr>
                                                                <tr>
                                                                    <td>&nbsp;
                                                                    </td>
                                                                    <td height="25" colspan="2" class="left_txt" align="left"></td>
                                                                </tr>
                                                                <tr>
                                                                    <td>&nbsp;
                                                                    </td>
                                                                    <td width="30%" height="40" align="left"></td>
                                                                    <td width="35%" align="left"></td>
                                                                </tr>
                                                            </table>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <td width="1%">&nbsp;
                                </td>
                                <td width="50%" valign="bottom">
                                    <table width="100%" height="59" border="0" align="center" cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td width="4%">&nbsp;
                                            </td>
                                            <td width="96%" height="38">
                                                <span class="login_txt_bt">欢迎登录 </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>&nbsp;
                                            </td>
                                            <td height="21">
                                                <table cellspacing="0" cellpadding="0" width="100%" border="0" id="table211" height="328">
                                                    <tr>
                                                        <td height="164" colspan="2" align="middle">
                                                            <table cellspacing="0" cellpadding="0" width="100%" border="0" height="143" id="table212">
                                                                <tr>
                                                                    <td width="18%" height="35" class="top_hui_text" align="right">
    
                                                                        <span
                                                                            class="login_txt">登录帐号:</span>
                                                                    </td>
                                                                    <td height="35" colspan="2" class="top_hui_text" align="left">
                                                                        <asp:TextBox ID="txt_UserName" runat="server" Style="width: 164px;"></asp:TextBox>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td height="35" class="top_hui_text" align="right">
    
                                                                        <span class="login_txt">密码:</span>
                                                                    </td>
                                                                    <td height="35" colspan="2" class="top_hui_text" align="left">
                                                                        <asp:TextBox ID="txt_Pwd" TextMode="Password" runat="server" Style="width: 164px;"></asp:TextBox>
                                                                        <img src="<%=WB.AdminThemes %>/images/login/luck.gif" width="19" height="18" alt="密码" />
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td height="35" class="top_hui_text" align="right">
    
                                                                        <span class="login_txt">验证码:</span>
                                                                    </td>
                                                                    <td height="35" colspan="2" class="top_hui_text" align="left">
                                                                        <asp:TextBox ID="txt_Ver" runat="server" Style="width: 85px;"></asp:TextBox>
                                                                        &nbsp;
                                                <span title="验证码,如果看不清,点击图片换一张" onclick="FnFCAVerifyCodeClick();" style="cursor: pointer;">
                                                    <img src="Ajax/Common/VerifyCode.ashx?dt=<%=DateTime.Now.Ticks.ToString() %>" id="FCAVerifyCode_Img" onclick="FnFCAVerifyCode1()" align="absMiddle" alt="" style="height: 23px; width: 52px" border="0" /></span>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td height="35" class="top_hui_text" align="right"></td>
                                                                    <td height="35" colspan="2" class="top_hui_text" align="left">
                                                                        <asp:CheckBox ID="chk_Remember" runat="server" Text="记住密码" />
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td height="35">&nbsp;
                                                                    </td>
                                                                    <td width="20%" align="left" height="35">
                                                                        <asp:ImageButton ID="imgBtn_Login" runat="server" Width="95" Height="34" ImageUrl="~/App_Themes/Admin/images/login/login.gif"
                                                                            OnClick="imgBtn_Login_Click" AlternateText="登录" />
                                                                    </td>
                                                                    <td width="67%" class="top_hui_text"></td>
                                                                </tr>
                                                            </table>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td width="433" height="164" align="right" valign="bottom">
                                                            <img src="<%=WB.AdminThemes %>/images/login/login-wel.gif" width="242" height="138"
                                                                alt="" border="0" />
                                                        </td>
                                                        <td width="57" align="right" valign="bottom">&nbsp; 
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td height="20">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="login-buttom-bg">
                            <tr>
                                <td align="center">
                                    <span class="login-buttom-txt">Copyright &copy; </span>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </form>
    </body>
    </html>
    
    
    <script language="javascript" type="text/javascript">
    
        // 取消登录 //
        function CancelLogin() {
    
            document.getElementById("<%=txt_UserName.ClientID%>").value = "";
    
            document.getElementById("<%=txt_Pwd.ClientID%>").value = "";
    
            document.getElementById("<%=txt_Ver.ClientID%>").value = "";
    
        }
    
        // 校验登录 //
        function CheckLogin() {
    
            var theCtrl = null;
            var theValue = "";
    
            theCtrl = document.getElementById("<%=txt_UserName.ClientID%>");
            theValue = theCtrl.value;
    
            if (theValue == "") {
    
                alert("请输入用户名。");
    
                theCtrl.focus();
                theCtrl.select();
    
                return false;
            }
    
            theCtrl = document.getElementById("<%=txt_Pwd.ClientID%>");
            theValue = theCtrl.value;
    
            if (theValue == "") {
    
                alert("请输入密码。");
    
                theCtrl.focus();
                theCtrl.select();
                return false;
            }
    
            theCtrl = document.getElementById("<%=txt_Ver.ClientID%>");
            theValue = theCtrl.value;
    
            if (theValue == "") {
                alert("请输入验证码。");
    
                theCtrl.focus();
                theCtrl.select();
    
                return false;
            }
    
            return true;
        }
    
        function FnFCAVerifyCodeClick() {
            var theImg = document.getElementById("FCAVerifyCode_Img");
    
            if (theImg == null)
                return;
    
            var theUrl = "Ajax/Common/VerifyCode.ashx?dt=" + (new Date());
    
            theImg.src = theUrl;
        }
    
    </script>
    
    
  • using System;
    using System.Data;
    using System.Web.UI;
    using SlowX.DAL.Helpers;
    using SlowX.Functions.Functions;
    using SlowX.UserLib.IHelpers;
    using SlowX.WebSite.Classes;
    using SlowX.WebSite.Common;
    using SlowX.WebSite.Pages;
    
    public partial class UserLogin 
        : 
        PageBase
    {
    
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void imgBtn_Login_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                LoginClick(null);
            }
            catch (Exception err)
            {
                throw err;
            }
        }
    
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="xdbHelper">数据库链接串</param>
        protected void LoginClick(DBHelper xdbHelper)
        {
            string strVerCode = this.txt_Ver.Text.Trim();
    
            object sessionCode = Session["VerCode"];
    
    
            if (sessionCode == null)
            {
                JSSlowXFunctions.Alert("验证码失效。");
    
                return;
    
            }
    
            string strSessionCode = sessionCode.ToString();
    
            if (strSessionCode.Length == 0)
            {
                JSSlowXFunctions.Alert("验证码失效。");
    
                return;
            }
    
            if (strVerCode != strSessionCode)
            {
                JSSlowXFunctions.Alert("验证码错误。");
    
                return;
    
            }
    
            string strUserName = this.txt_UserName.Text.Trim();
            string strPwd = this.txt_Pwd.Text;
            long userStatusId = 0;
    
            string resultPwd = WebSiteBLL.instance.i_IWebAppCommonBLL.MD5ConvertPwd(strUserName, strPwd);
    
            string strMsg = "";
            bool isSucc = false;
    
            ISlowXUserLibHelper iSlowXUserLibHelperInstance
                = SlowX.UserLib.Helpers.SlowXUserLibHelper.instance;
    
    
            bool bIsCreate = true;
    
            if (xdbHelper == null)
            {
                xdbHelper = SlowX.DAL.Helpers.DBHelper.CreateDBHelper();
            }
            else
            {
                // 没有打开链接 //
                bIsCreate = xdbHelper.IsNotOpen();
            }
    
            try
            {
                if (bIsCreate)
                    xdbHelper.OpenDBHelper();
    
                SlowX.UserLib.Business.UTB_SLOWX_USER
                    bll
                    =
                    SlowX.UserLib.Business.UTB_SLOWX_USER.instance;
    
                SlowX.UserLib.Entity.UTB_SLOWX_USER
                    entity
                    =
                    new SlowX.UserLib.Entity.UTB_SLOWX_USER();
    
                entity.i_iqueryDriver.AddIQueryItemWithEntityFieldInfo
                    (
                        entity._UserName,
                        SlowX.Core.CoreClasses.DataColumnQueryAssist.dataColumnQueryAssistEmStringCaseLower,
                        strUserName.Trim().ToLower()
                    );
    
                entity.i_iorderByDriver.AddIOrderByItemWithEntityFieldInfo(entity._ID, SlowX.Core.Enums.OrderBy.EmOrderBy.ASC);
    
                DataSet ds = bll.List(entity, xdbHelper);
    
    
                if (ds == null)
                {
                    strMsg = "用户不存在。";
    
                    if (bIsCreate)
                        xdbHelper.EndDBHelper();
    
                    iSlowXUserLibHelperInstance.InsertLoginLogUserNameNoExist(strUserName, xdbHelper);
    
                    JSSlowXFunctions.Alert(strMsg);
    
                    return;
                }
    
                int iCount = ds.Tables[0].Rows.Count;
    
                if (iCount == 0)
                {
                    strMsg = "用户不存在。";
    
                    iSlowXUserLibHelperInstance.InsertLoginLogUserNameNoExist(strUserName, xdbHelper);
    
    
                    if (bIsCreate)
                        xdbHelper.EndDBHelper();
    
                    JSSlowXFunctions.Alert(strMsg);
    
                    return;
                }
    
                DataRow findDataRow = null;
    
                if (iCount == 1)
                {
                    findDataRow = ds.Tables[0].Rows[0];
    
                    userStatusId = long.Parse(findDataRow[entity._UserStatusId._Name].ToString());
    
                    if (!UserSessionData.UserStatusIsEnabled(userStatusId, xdbHelper))
                    {
                        strMsg = "用户被禁用,请与管理员联系。";
    
                        iSlowXUserLibHelperInstance.InsertLoginLogUserDisable
                            (
                                long.Parse(findDataRow[entity._ID._Name].ToString()),
                                strUserName,
                                xdbHelper
                            );
    
                        if (bIsCreate)
                            xdbHelper.EndDBHelper();
    
                        JSSlowXFunctions.Alert(strMsg);
    
                        return;
                    }
                }
                else
                {
                    DataRow drr = null;
    
                    for (int idx = 0; idx < iCount; ++idx)
                    {
                        drr = ds.Tables[0].Rows[idx];
    
                        userStatusId = long.Parse(drr[entity._UserStatusId._Name].ToString());
    
                        if (!UserSessionData.UserStatusIsEnabled(userStatusId, xdbHelper))
                            continue;
    
                        if (findDataRow == null)
                        {
                            findDataRow = drr;
                        }
                        else
                        {
                            strMsg = "系统错误,存在两个以上的同名帐号,请与管理员联系。";
    
                            iSlowXUserLibHelperInstance.InsertLoginLogUserNameRepeat(strUserName, xdbHelper);
    
                            if (bIsCreate)
                                xdbHelper.EndDBHelper();
    
                            JSSlowXFunctions.Alert(strMsg);
    
                            return;
                        }
                    }
    
                    if (findDataRow == null)
                    {
                        strMsg = "用户被禁用,请与管理员联系。";
    
                        iSlowXUserLibHelperInstance.InsertLoginLogUserDisable
                            (
                                0,
                                strUserName,
                                xdbHelper
                            );
    
                        if (bIsCreate)
                            xdbHelper.EndDBHelper();
    
                        JSSlowXFunctions.Alert(strMsg);
    
                        return;
                    }
                }
    
    
    
    
                if (resultPwd != findDataRow[entity._Pwd._Name].ToString())
                {
                    strMsg = "密码错误。";
    
    
    
                    iSlowXUserLibHelperInstance.InsertLoginLogPwdError
                        (
                            long.Parse(findDataRow[SlowX.UserLib.TableDataColumnName.UTB_SLOWX_USER.ID].ToString()),
                            strUserName,
                            xdbHelper
                        );
    
                    if (bIsCreate)
                        xdbHelper.EndDBHelper();
    
                    JSSlowXFunctions.Alert(strMsg);
    
                    return;
                }
    
                UserCookieInfo ui = null;
    
                if (chk_Remember.Checked)
                {
                    ui = new UserCookieInfo
                        (
                            long.Parse(findDataRow[entity._ID._Name].ToString()),
                            findDataRow[entity._Pwd._Name].ToString(),
                            DateTime.Now,
                            9999 * 60 * 24
                        );
                }
                else
                {
                    ui = UserCookieInfo.BuildDefaultUserCookieInfo
                        (
                            long.Parse(findDataRow[entity._ID._Name].ToString()),
                            findDataRow[entity._Pwd._Name].ToString(),
                            DateTime.Now
                        );
                }
    
                UserSessionInfo userSessionInfoValue
                    =
                    new UserSessionInfo(findDataRow);
    
                UserSessionData.SetUserSessionInfo
                    (
                        userSessionInfoValue,
                        ui
                    );
    
                isSucc = true;
    
                iSlowXUserLibHelperInstance.InsertLoginLogSucc
                        (
                            userSessionInfoValue.ID,
                            strUserName,
                            xdbHelper
                        );
    
                iSlowXUserLibHelperInstance.UpdateUserLoginInfo
                    (
                        userSessionInfoValue.ID,
                        SlowX.UserLib.Enums.LoginFrom.EmLoginFrom.用户输入,
                        xdbHelper
                    );
    
    
                if (bIsCreate)
                    xdbHelper.EndDBHelper();
    
            }
            catch (Exception err)
            {
                if (bIsCreate)
                    xdbHelper.TranDBHelper();
    
                throw err;
            }
            finally
            {
                if (bIsCreate)
                    xdbHelper.FinallyDBHelper();
            }
    
            if (isSucc)
                Response.Redirect(WB.ManageUrl);
        }
    
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                string str = HttpContextSlowXFunctions.GetParameter("menu");
    
                if (str != null && str.Trim().ToLower() == "logout")
                {
                    UserSessionData.SetUserSessionInfo(null, null);
                }
            }
    
            WebSiteBLL.instance.i_IWebAppCommonBLL.SetPageCss
                    (
                        Header,
                        WB.AdminThemes + "/css/login.css"
                    );
        }
    }
    

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)