⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
字号:
namespace PowerEasy.WebSite
{
    using PowerEasy.Accessories;
    using PowerEasy.Components;
    using PowerEasy.Contents;
    using PowerEasy.Controls;
    using PowerEasy.Enumerations;
    using PowerEasy.Model.UserManage;
    using PowerEasy.UserManage;
    using PowerEasy.Web.UI;
    using System;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class Login : BasePage
    {
        protected Button BtnLogin;
        protected Button BtnReturn;
        protected DropDownList DropExpiration;
        protected HtmlForm form1;
        protected Literal LitErrorMessage;
        protected Literal LitLoginTime;
        protected Literal LitMessage;
        protected Literal LitMoney;
        protected Literal LitPoint;
        protected Literal LitSignin;
        protected Literal LitUserExp;
        protected Literal LitUserName;
        protected PlaceHolder PhValCode;
        protected Panel PnlLogin;
        protected Panel PnlLoginMessage;
        protected Panel PnlLoginStatus;
        protected TextBox TxtPassword;
        protected TextBox TxtUserName;
        protected TextBox TxtValidateCode;
        protected ValidationSummary ValidationSummary1;
        protected PowerEasy.Controls.RequiredFieldValidator ValrPassword;
        protected PowerEasy.Controls.RequiredFieldValidator ValrUserName;
        protected PowerEasy.Controls.RequiredFieldValidator ValrValidateCode;
        protected ValidateCode VcodeLogin;

        protected void BtnLogin_Click(object sender, EventArgs e)
        {
            UserPrincipal principal;
            UserInfo userInfo = new UserInfo();
            userInfo.UserName = this.TxtUserName.Text.Trim();
            userInfo.UserPassword = this.TxtPassword.Text.Trim();
            if (SiteConfig.UserConfig.EnableCheckCodeOfLogin && (string.Compare(this.TxtValidateCode.Text.Trim(), this.VcodeLogin.ValidateCodeValue, true) != 0))
            {
                this.PnlLoginMessage.Visible = true;
                this.PnlLogin.Visible = false;
                this.PnlLoginStatus.Visible = false;
                this.LitMessage.Text = "<li>您输入的验证码和系统产生的不一致,请重新输入。</li>";
            }
            if (Users.ValidateUser(userInfo) != UserStatus.None)
            {
                this.PnlLoginMessage.Visible = true;
                this.PnlLogin.Visible = false;
                this.PnlLoginStatus.Visible = false;
                this.LitErrorMessage.Text = "<li>用户登录名称或用户密码不对或用户帐号处于非正常状态!</li><br />";
                return;
            }
            bool isPersistent = false;
            DateTime now = DateTime.Now;
            DateTime expiration = DateTime.Now;
            string selectedValue = this.DropExpiration.SelectedValue;
            if (selectedValue != null)
            {
                if (!(selectedValue == "None"))
                {
                    if (selectedValue == "Day")
                    {
                        isPersistent = true;
                        expiration = now.AddDays(1.0);
                        goto Label_015A;
                    }
                    if (selectedValue == "Month")
                    {
                        isPersistent = true;
                        expiration = now.AddMonths(1);
                        goto Label_015A;
                    }
                    if (selectedValue == "Year")
                    {
                        isPersistent = true;
                        expiration = now.AddYears(1);
                        goto Label_015A;
                    }
                }
                else
                {
                    isPersistent = false;
                    expiration = now.AddDays(1.0);
                    goto Label_015A;
                }
            }
            isPersistent = false;
            expiration = now.AddMinutes(20.0);
        Label_015A:
            principal = new UserPrincipal();
            principal.UserName = userInfo.UserName;
            principal.LastPassword = userInfo.LastPassword;
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, userInfo.UserName, now, expiration, isPersistent, principal.SerializeToString());
            string str = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, str);
            if (isPersistent)
            {
                cookie.Expires = expiration;
            }
            cookie.HttpOnly = true;
            cookie.Path = FormsAuthentication.FormsCookiePath;
            cookie.Secure = FormsAuthentication.RequireSSL;
            base.Response.Cookies.Add(cookie);
            this.Session["UserName"] = userInfo.UserName;
            base.Response.Redirect(base.Request.RawUrl);
        }

        protected void BtnReturn_Click(object sender, EventArgs e)
        {
            base.Response.Redirect(base.Request.RawUrl);
        }

        private void InitLoginStatus()
        {
            UserInfo usersByUserName = Users.GetUsersByUserName(PEContext.Current.User.UserName);
            this.LitUserName.Text = usersByUserName.UserName;
            this.LitMoney.Text = "资金余额:" + usersByUserName.Balance.ToString("0.00") + "元";
            this.LitUserExp.Text = "经验积分:" + usersByUserName.UserExp.ToString() + "分 ";
            this.LitPoint.Text = "可用" + SiteConfig.UserConfig.PointName + ":" + usersByUserName.UserPoint.ToString() + SiteConfig.UserConfig.PointUnit;
            this.LitLoginTime.Text = "登录次数:" + usersByUserName.LoginTimes.ToString() + "次";
            this.LitSignin.Text = "待签文章:" + SigninLog.GetNotSigninContentCountByUserName(usersByUserName.UserName).ToString() + "篇";
            this.LitMessage.Text = "待阅短信:" + Message.UnreadMessageCount(usersByUserName.UserName).ToString() + "条";
            if (!SiteConfig.SiteOption.EnablePointMoneyExp)
            {
                this.LitMoney.Visible = false;
                this.LitUserExp.Visible = false;
                this.LitPoint.Visible = false;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (PEContext.Current.User.Identity.IsAuthenticated)
            {
                this.PnlLoginStatus.Visible = true;
                this.PnlLogin.Visible = false;
                this.InitLoginStatus();
            }
            else
            {
                this.PnlLogin.Visible = true;
                this.PnlLoginStatus.Visible = false;
                if (!SiteConfig.UserConfig.EnableCheckCodeOfLogin)
                {
                    this.PhValCode.Visible = false;
                }
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -