Exemplo n.º 1
0
        protected void IbtnEnter_Click(object sender, ImageClickEventArgs e)
        {
            string        str2;
            UserPrincipal principal;
            UserInfo      userInfo = new UserInfo();

            userInfo.UserName     = this.TxtUserName.Text.Trim();
            userInfo.UserPassword = this.TxtPassword.Text.Trim();
            if (SiteConfig.UserConfig.EnableCheckCodeOfLogOn && (string.Compare(this.TxtValidateCode.Text.Trim(), this.VcodeLogOn.ValidateCodeValue, StringComparison.OrdinalIgnoreCase) != 0))
            {
                DynamicPage.WriteErrMsg("<li>您输入的验证码和系统产生的不一致,请重新输入。</li>");
            }
            UserStatus status = Users.ValidateUser(userInfo);

            if ((int)status >= 100)
            {
                DynamicPage.WriteErrMsg("<li>用户登录名称或用户密码不对!</li>");
            }
            if (status != UserStatus.None)
            {
                switch (status)
                {
                case UserStatus.Locked:
                    DynamicPage.WriteErrMsg("<li>用户帐户被锁定!</li>");
                    return;

                case UserStatus.WaitValidateByEmail:
                    DynamicPage.WriteErrMsg("<li>用户帐户等待邮件验证!</li>");
                    return;

                case (UserStatus.WaitValidateByEmail | UserStatus.Locked):
                    goto Label_0344;

                case UserStatus.WaitValidateByAdmin:
                    DynamicPage.WriteErrMsg("<li>用户帐户等待管理员验证!</li>");
                    return;

                case UserStatus.WaitValidateByMobile:
                    DynamicPage.WriteErrMsg("<li>用户帐户等待手机验证!</li>");
                    return;
                }
                goto Label_0344;
            }
            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_013F;
                    }
                    if (selectedValue == "Month")
                    {
                        isPersistent = true;
                        expiration   = now.AddMonths(1);
                        goto Label_013F;
                    }
                    if (selectedValue == "Year")
                    {
                        isPersistent = true;
                        expiration   = now.AddYears(1);
                        goto Label_013F;
                    }
                }
                else
                {
                    isPersistent = false;
                    expiration   = now.AddDays(1.0);
                    goto Label_013F;
                }
            }
            isPersistent = false;
            expiration   = now.AddMinutes(20.0);
Label_013F:
            if (!ApiData.IsAPiEnable())
            {
                goto Label_0230;
            }
            string savecookie = "";
            string str5       = this.DropExpiration.SelectedValue;

            if (str5 != null)
            {
                if (!(str5 == "None"))
                {
                    if (str5 == "Day")
                    {
                        savecookie = "1";
                        goto Label_01C5;
                    }
                    if (str5 == "Month")
                    {
                        savecookie = "30";
                        goto Label_01C5;
                    }
                    if (str5 == "Year")
                    {
                        savecookie = "365";
                        goto Label_01C5;
                    }
                }
                else
                {
                    savecookie = "-1";
                    goto Label_01C5;
                }
            }
            savecookie = "-1";
Label_01C5:
            str2 = ApiFunction.LogOn(this.TxtUserName.Text, this.TxtPassword.Text, savecookie);
            if (str2 != "true")
            {
                DynamicPage.WriteErrMsg(str2 + "<br><li>用户登录名称或用户密码不对或用户帐号处于非正常状态!</li>");
                return;
            }
            str2 = ApiFunction.RegLogOn(this.TxtUserName.Text, this.TxtPassword.Text, savecookie);
            base.Response.Write(str2);
Label_0230:
            principal              = new UserPrincipal();
            principal.UserName     = userInfo.UserName;
            principal.LastPassword = userInfo.LastPassword;
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, userInfo.UserName, now, expiration, isPersistent, principal.SerializeToString());
            string     str3   = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, str3);

            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.Write("<script language=\"JavaScript\">window.location='" + GetRedirectUrl() + "';</script>");
            return;

Label_0344:
            DynamicPage.WriteErrMsg("<li>用户登录名称或用户密码不对!</li>");
        }
Exemplo n.º 2
0
        private void UserLogin(XmlDocument xmlDoc)
        {
            bool          flag;
            DateTime      now;
            DateTime      time2;
            string        str7;
            UserPrincipal principal;
            string        nodeInnerText = GetNodeInnerText(xmlDoc, "//username");
            string        str2          = GetNodeInnerText(xmlDoc, "//password");
            string        str3          = GetNodeInnerText(xmlDoc, "//checkcode");
            string        str4          = GetNodeInnerText(xmlDoc, "//expiration");

            if (string.IsNullOrEmpty(nodeInnerText))
            {
                this.PutErrMessage("用户名不能为空!");
                return;
            }
            if (string.IsNullOrEmpty(str2))
            {
                this.PutErrMessage("密码不能为空!");
                return;
            }
            if (SiteConfig.UserConfig.EnableCheckCodeOfLogOn && string.IsNullOrEmpty(str3))
            {
                this.PutErrMessage("验证码不能为空!");
                return;
            }
            UserInfo userInfo = new UserInfo();

            userInfo.UserName     = nodeInnerText;
            userInfo.UserPassword = str2;
            if (SiteConfig.UserConfig.EnableCheckCodeOfLogOn)
            {
                string strB = (this.Session["ValidateCodeSession"] == null) ? "" : this.Session["ValidateCodeSession"].ToString();
                if (string.Compare(str3, strB, StringComparison.OrdinalIgnoreCase) > 0)
                {
                    this.PutErrMessage("您输入的验证码错误!");
                    return;
                }
            }
            UserStatus status = Users.ValidateUser(userInfo);

            if ((Int32)status >= 100)
            {
                this.PutErrMessage("用户登录名称或用户密码不对!");
                return;
            }
            switch (status)
            {
            case UserStatus.None:
                flag  = false;
                now   = DateTime.Now;
                time2 = DateTime.Now;
                switch (str4)
                {
                case "None":
                    flag  = false;
                    time2 = now.AddMinutes(20.0);
                    break;

                case "Day":
                    flag  = true;
                    time2 = now.AddDays(1.0);
                    break;

                case "Month":
                    flag  = true;
                    time2 = now.AddMonths(1);
                    break;

                case "Year":
                    flag  = true;
                    time2 = now.AddYears(1);
                    break;
                }
                flag  = false;
                time2 = now.AddMinutes(20.0);
                break;

            case UserStatus.Locked:
                this.PutErrMessage("用户帐户被锁定!");
                return;

            case UserStatus.WaitValidateByEmail:
                this.PutErrMessage("用户帐户等待邮件验证!");
                return;

            case UserStatus.WaitValidateByAdmin:
                this.PutErrMessage("用户帐户等待管理员验证!");
                return;

            case UserStatus.WaitValidateByMobile:
                this.PutErrMessage("用户帐户等待手机验证!");
                return;

            default:
                this.PutErrMessage("用户登录名称或用户密码不对!");
                return;
            }
            string savecookie = "";

            if (!ApiData.IsAPiEnable())
            {
                goto Label_028F;
            }
            string str13 = str4;

            if (str13 != null)
            {
                if (!(str13 == "None"))
                {
                    if (str13 == "Day")
                    {
                        savecookie = "1";
                        goto Label_0263;
                    }
                    if (str13 == "Month")
                    {
                        savecookie = "30";
                        goto Label_0263;
                    }
                    if (str13 == "Year")
                    {
                        savecookie = "365";
                        goto Label_0263;
                    }
                }
                else
                {
                    savecookie = "-1";
                    goto Label_0263;
                }
            }
            savecookie = "-1";
Label_0263:
            str7 = ApiFunction.LogOn(nodeInnerText, str2, savecookie);
            if (str7 != "true")
            {
                this.PutErrMessage("登陆失败!" + str7);
                return;
            }
Label_028F:
            principal              = new UserPrincipal();
            principal.UserName     = userInfo.UserName;
            principal.LastPassword = userInfo.LastPassword;
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, userInfo.UserName, now, time2, flag, principal.SerializeToString());
            string     str8   = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, str8);

            if (flag)
            {
                cookie.Expires = time2;
            }
            base.Response.Cookies.Add(cookie);
            HttpCookie cookie2 = new HttpCookie(FormsAuthentication.FormsCookieName + "IsUserLogOut", "false");

            cookie2.HttpOnly = true;
            cookie2.Path     = FormsAuthentication.FormsCookiePath;
            cookie2.Secure   = FormsAuthentication.RequireSSL;
            base.Response.Cookies.Add(cookie2);
            this.Session["UserName"] = userInfo.UserName;
            this.XmlResponseWriter.WriteElementString("status", "ok");
            this.XmlResponseWriter.WriteElementString("username", userInfo.UserName);
            this.XmlResponseWriter.WriteElementString("usergroup", userInfo.GroupName);
            if (ApiData.IsAPiEnable())
            {
                ApiData data   = new ApiData();
                string  apiKey = data.ApiKey;
                apiKey = StringHelper.MD5GB2312(userInfo.UserName + apiKey).Substring(8, 0x10);
                string str10 = "";
                foreach (string str11 in data.Urls)
                {
                    str10 = str10 + "<iframe width=\"0\" height=\"0\" src=\"" + str11 + "?syskey=" + apiKey + "&username="******"GB2312")) + "&password="******"&savecookie=" + savecookie + "\"></iframe>";
                }
                this.XmlResponseWriter.WriteElementString("API_Enable", "1");
                this.XmlResponseWriter.WriteElementString("LoginString", str10);
            }
            else
            {
                this.XmlResponseWriter.WriteElementString("API_Enable", "0");
            }
        }
Exemplo n.º 3
0
        protected void BtnLogOn_Click(object sender, EventArgs e)
        {
            bool          flag;
            DateTime      now;
            DateTime      time2;
            string        str2;
            UserPrincipal principal;
            UserInfo      userInfo = new UserInfo();

            userInfo.UserName     = this.TxtUserName.Text.Trim();
            userInfo.UserPassword = this.TxtPassword.Text.Trim();
            if (SiteConfig.UserConfig.EnableCheckCodeOfLogOn && (string.Compare(this.TxtValidateCode.Text.Trim(), this.VcodeLogOn.ValidateCodeValue, StringComparison.OrdinalIgnoreCase) != 0))
            {
                this.PnlLogOnMessage.Visible = true;
                this.PnlLogOn.Visible        = false;
                this.PnlLogOnStatus.Visible  = false;
                this.LitMessage.Text         = "<li>您输入的验证码和系统产生的不一致,请重新输入。</li>";
            }
            UserStatus status = Users.ValidateUser(userInfo);

            if ((int)status >= 100)
            {
                this.PnlLogOnMessage.Visible = true;
                this.PnlLogOn.Visible        = false;
                this.PnlLogOnStatus.Visible  = false;
                this.LitErrorMessage.Text    = "<li>用户登录名称或用户密码不对!</li><br />";
                return;
            }
            switch (status)
            {
            case UserStatus.None:
                flag  = false;
                now   = DateTime.Now;
                time2 = DateTime.Now;
                switch (this.DropExpiration.SelectedValue)
                {
                case "None":
                    flag  = false;
                    time2 = now.AddDays(1.0);
                    break;

                case "Day":
                    flag  = true;
                    time2 = now.AddDays(1.0);
                    break;

                case "Month":
                    flag  = true;
                    time2 = now.AddMonths(1);
                    break;

                case "Year":
                    flag  = true;
                    time2 = now.AddYears(1);
                    break;
                }
                flag  = false;
                time2 = now.AddMinutes(20.0);
                break;

            case UserStatus.Locked:
                this.PnlLogOnMessage.Visible = true;
                this.PnlLogOn.Visible        = false;
                this.PnlLogOnStatus.Visible  = false;
                this.LitErrorMessage.Text    = "<li>用户帐号被锁定!</li><br />";
                return;

            case UserStatus.WaitValidateByEmail:
                this.PnlLogOnMessage.Visible = true;
                this.PnlLogOn.Visible        = false;
                this.PnlLogOnStatus.Visible  = false;
                this.LitErrorMessage.Text    = "<li>用户帐号等待邮件验证!</li><br />";
                return;

            case UserStatus.WaitValidateByAdmin:
                this.PnlLogOnMessage.Visible = true;
                this.PnlLogOn.Visible        = false;
                this.PnlLogOnStatus.Visible  = false;
                this.LitErrorMessage.Text    = "<li>用户帐号等待管理员验证!</li><br />";
                return;

            case UserStatus.WaitValidateByMobile:
                this.PnlLogOnMessage.Visible = true;
                this.PnlLogOn.Visible        = false;
                this.PnlLogOnStatus.Visible  = false;
                this.LitErrorMessage.Text    = "<li>用户帐号等待手机验证!</li><br />";
                return;

            default:
                this.PnlLogOnMessage.Visible = true;
                this.PnlLogOn.Visible        = false;
                this.PnlLogOnStatus.Visible  = false;
                this.LitErrorMessage.Text    = "<li>用户登录名称或用户密码不对或用户帐号处于非正常状态!</li><br />";
                return;
            }
            if (!ApiData.IsAPiEnable())
            {
                goto Label_02B0;
            }
            string savecookie    = "";
            string selectedValue = this.DropExpiration.SelectedValue;

            if (selectedValue != null)
            {
                if (!(selectedValue == "None"))
                {
                    if (selectedValue == "Day")
                    {
                        savecookie = "1";
                        goto Label_0247;
                    }
                    if (selectedValue == "Month")
                    {
                        savecookie = "30";
                        goto Label_0247;
                    }
                    if (selectedValue == "Year")
                    {
                        savecookie = "365";
                        goto Label_0247;
                    }
                }
                else
                {
                    savecookie = "-1";
                    goto Label_0247;
                }
            }
            savecookie = "-1";
Label_0247:
            str2 = ApiFunction.LogOn(this.TxtUserName.Text, this.TxtPassword.Text, savecookie);
            if (str2 != "true")
            {
                this.PnlLogOnMessage.Visible = true;
                this.PnlLogOn.Visible        = false;
                this.PnlLogOnStatus.Visible  = false;
                this.LitErrorMessage.Text    = "<li>登陆失败</li><br>" + str2;
                return;
            }
Label_02B0:
            principal              = new UserPrincipal();
            principal.UserName     = userInfo.UserName;
            principal.LastPassword = userInfo.LastPassword;
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, userInfo.UserName, now, time2, flag, principal.SerializeToString());
            string     str3   = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, str3);

            if (flag)
            {
                cookie.Expires = time2;
            }
            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);
        }