protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         APIConfigInfo aci = APIConfigs.GetConfig();
         allowpassport.SelectedValue = aci.Enable ? "1" : "0";
         passportbody.Attributes.Add("style", "display:" + (aci.Enable ? "block" : "none"));
         allowpassport.Items[0].Attributes.Add("onclick", "setAllowPassport(1)");
         allowpassport.Items[1].Attributes.Add("onclick", "setAllowPassport(0)");
         ApplicationInfoCollection appColl = aci.AppCollection;
         DataTable dt = new DataTable();
         dt.Columns.Add("appname");
         dt.Columns.Add("callbackurl");
         dt.Columns.Add("apikey");
         dt.Columns.Add("secret");
         foreach (ApplicationInfo ai in appColl)
         {
             DataRow dr = dt.NewRow();
             dr["appname"]     = ai.AppName;
             dr["callbackurl"] = ai.CallbackUrl;
             dr["apikey"]      = ai.APIKey;
             dr["secret"]      = ai.Secret;
             dt.Rows.Add(dr);
         }
         DataGrid1.TableHeaderName = "整合程序列表";
         DataGrid1.DataKeyField    = "apikey";
         DataGrid1.DataSource      = dt;
         DataGrid1.DataBind();
     }
 }
Beispiel #2
0
        void Status_Load(object sender, EventArgs e)
        {
            APIConfigInfo apiInfo = APIConfigs.GetConfig();

            if (!apiInfo.Enable)
            {
                return;
            }
            ApplicationInfo           appInfo       = null;
            ApplicationInfoCollection appcollection = apiInfo.AppCollection;

            foreach (ApplicationInfo newapp in appcollection)
            {
                if (newapp.APIKey == DNTRequest.GetString("api_key"))
                {
                    appInfo = newapp;
                }
            }
            if (appInfo == null)
            {
                return;
            }


            string next  = DNTRequest.GetString("next");
            string reurl = string.Format("{0}{1}user_status={2}{3}", appInfo.CallbackUrl, appInfo.CallbackUrl.IndexOf("?") > 0 ? "&" : "?", userid > 0 ? "1" : "0", next == string.Empty ? next : "next=" + next);

            Response.Redirect(reurl);
        }
Beispiel #3
0
        void RESTServer_Load(object sender, EventArgs e)
        {
            List <DNTParam> parameters = GetParamsFromRequest(HttpContext.Current.Request);
            APIConfigInfo   apiInfo    = APIConfigs.GetConfig();

            if (!apiInfo.Enable)
            {
                RESTServerResponse(Util.CreateErrorMessage(ErrorType.API_EC_SERVICE, parameters));
                return;
            }

            //查找匹配客户端配置信息
            ApplicationInfo           appInfo       = null;
            ApplicationInfoCollection appcollection = apiInfo.AppCollection;

            foreach (ApplicationInfo newapp in appcollection)
            {
                if (newapp.APIKey == DNTRequest.GetString("api_key"))
                {
                    appInfo = newapp;
                    break;
                }
            }

            if (appInfo == null)
            {
                RESTServerResponse(Util.CreateErrorMessage(ErrorType.API_EC_APPLICATION, parameters));
                return;
            }

            //check request ip
            string ip = DNTRequest.GetIP();

            if (appInfo.IPAddresses != null && appInfo.IPAddresses.Trim() != string.Empty && !Utils.InIPArray(ip, appInfo.IPAddresses.Split(',')))
            {
                RESTServerResponse(Util.CreateErrorMessage(ErrorType.API_EC_BAD_IP, parameters));
                return;
            }

            string sig = GetSignature(parameters, appInfo.Secret);

            if (sig != DNTRequest.GetString("sig"))
            {
                //输出签名错误
                RESTServerResponse(Util.CreateErrorMessage(ErrorType.API_EC_SIGNATURE, parameters));
                return;
            }

            string method = DNTRequest.GetString("method").Trim().ToLower();

            //如果客户端未指定方法名称
            if (string.IsNullOrEmpty(method))
            {
                RESTServerResponse(Util.CreateErrorMessage(ErrorType.API_EC_METHOD, parameters));
                return;
            }

            RESTServerResponse(CommandManager.Run(new CommandParameter(method, parameters, appInfo)));
        }
Beispiel #4
0
        protected override void ShowPage()
        {
            int logoutUid = userid;

            pagetitle = "用户退出";
            username  = "******";
            userid    = -1;

            base.AddScript("if (top.document.getElementById('leftmenu')){ top.frames['leftmenu'].location.reload(); }");

            if (!DNTRequest.IsPost() || reurl != "")
            {
                string r = (!Utils.StrIsNullOrEmpty(reurl)) ? reurl : "";

                if (reurl == "")
                {
                    r = (DNTRequest.GetUrlReferrer() == "" || DNTRequest.GetUrlReferrer().IndexOf("login") > -1 || DNTRequest.GetUrlReferrer().IndexOf("logout") > -1) ?
                        "index.aspx" : DNTRequest.GetUrlReferrer();
                }

                Utils.WriteCookie("reurl", (reurl == "" || reurl.IndexOf("login.aspx") > -1) ? r : reurl);
            }

            if (DNTRequest.GetString("userkey") == userkey || IsApplicationLogout())
            {
                AddMsgLine("已经清除了您的登录信息, 稍后您将以游客身份返回首页");

                OnlineUsers.DeleteRows(olid);
                ForumUtils.ClearUserCookie();
                Utils.WriteCookie(Utils.GetTemplateCookieName(), "", -999999);

                System.Web.HttpContext.Current.Response.AppendCookie(new System.Web.HttpCookie("dntadmin"));

                //同步登录到第三方应用
                if (APIConfigs.GetConfig().Enable)
                {
                    AddMsgLine(Sync.GetLogoutScript(logoutUid));
                }

                if (!APIConfigs.GetConfig().Enable || !Sync.NeedAsyncLogout())
                {
                    MsgForward("logout_succeed");
                }
            }
            else
            {
                AddMsgLine("无法确定您的身份, 稍后返回首页");
            }

            SetUrl(Utils.UrlDecode(ForumUtils.GetReUrl()));
            SetMetaRefresh();
            SetShowBackLink(false);
        }
Beispiel #5
0
        /// <summary>
        /// 是否是来自应用程序的登出
        /// </summary>
        /// <returns></returns>
        private bool IsApplicationLogout()
        {
            if (!APIConfigs.GetConfig().Enable)
            {
                return(false);
            }

            if (DNTRequest.GetFormInt("confirm", -1) != 1)
            {
                return(false);
            }

            return(true);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            applicationtype.Items[0].Attributes.Add("onclick", "$('showurl').style.display='';");
            applicationtype.Items[1].Attributes.Add("onclick", "$('showurl').style.display='none';");

            asyncmode.Items[0].Attributes.Add("onclick", "$('tr_asyncurl').style.display='';$('tr_asynclist').style.display='none';");
            asyncmode.Items[1].Attributes.Add("onclick", "$('tr_asyncurl').style.display='none';$('tr_asynclist').style.display='none';");
            asyncmode.Items[2].Attributes.Add("onclick", "$('tr_asyncurl').style.display='';$('tr_asynclist').style.display='';");
            if (!IsPostBack)
            {
                string apikey = DNTRequest.GetString("apikey");
                if (apikey != "")
                {
                    APIConfigInfo aci = APIConfigs.GetConfig();
                    foreach (ApplicationInfo ai in aci.AppCollection)
                    {
                        if (ai.APIKey == apikey)
                        {
                            appname.Text = ai.AppName;
                            applicationtype.SelectedValue = ai.ApplicationType.ToString();
                            if (applicationtype.SelectedIndex == 1)
                            {
                                base.RegisterStartupScript("applicationtype", "<script>$('showurl').style.display='none';</script>");
                            }
                            appurl.Text      = ai.AppUrl;
                            callbackurl.Text = ai.CallbackUrl;
                            ipaddresses.Text = ai.IPAddresses;

                            asyncmode.SelectedValue = ai.SyncMode.ToString();
                            if (asyncmode.SelectedIndex == 1)
                            {
                                base.RegisterStartupScript("asyncmode", "<script>$('tr_asyncurl').style.display='none';$('tr_asynclist').style.display='none';</script>");
                            }
                            if (asyncmode.SelectedIndex == 2)
                            {
                                base.RegisterStartupScript("asyncmode", "<script>$('tr_asyncurl').style.display='';$('tr_asynclist').style.display='';</script>");
                            }
                            asyncurl.Text  = ai.SyncUrl;
                            asynclist.Text = ai.SyncList;
                            break;
                        }
                    }
                }
                apikeyhidd.Value = apikey;
            }
        }
Beispiel #7
0
        /// <summary>
        /// 是否是来自应用程序的登出
        /// </summary>
        /// <returns></returns>
        private bool IsApplicationLogout()
        {
            APIConfigInfo apiconfig = APIConfigs.GetConfig();

            if (!apiconfig.Enable)
            {
                return(false);
            }

            int confirm = DNTRequest.GetFormInt("confirm", -1);

            if (confirm != 1)
            {
                return(false);
            }

            return(true);
        }
Beispiel #8
0
        /// <summary>
        /// 获取需要数据同步的应用程序列表
        /// </summary>
        /// <param name="actionName"></param>
        /// <returns></returns>
        private static ApplicationInfoCollection GetAsyncTarget(string action)
        {
            ApplicationInfoCollection appCollection = new ApplicationInfoCollection();
            APIConfigInfo             apiInfo       = APIConfigs.GetConfig();

            if (!apiInfo.Enable)
            {
                return(appCollection);
            }
            foreach (ApplicationInfo appInfo in apiInfo.AppCollection)
            {
                if (appInfo.SyncMode == 1 || (appInfo.SyncMode == 2 && Utils.InArray(action, appInfo.SyncList)))
                {
                    if (appInfo.SyncUrl.Trim() == string.Empty)
                    {
                        continue;
                    }
                    appCollection.Add(appInfo);
                }
            }
            return(appCollection);
        }
Beispiel #9
0
        void Status_Load(object sender, EventArgs e)
        {
            if (!APIConfigs.GetConfig().Enable)
            {
                return;
            }

            ApplicationInfo appInfo = null;

            foreach (ApplicationInfo newapp in APIConfigs.GetConfig().AppCollection)
            {
                if (newapp.APIKey == DNTRequest.GetString("api_key"))
                {
                    appInfo = newapp;
                }
            }

            if (appInfo == null)
            {
                return;
            }

            if (DNTRequest.GetString("format").Trim().ToLower() == "json")
            {
                Response.ContentType = "text/html";
                Response.Write((userid > 0).ToString().ToLower());
                Response.End();
            }
            else
            {
                Response.Redirect(string.Format("{0}{1}user_status={2}{3}",
                                                appInfo.CallbackUrl,
                                                appInfo.CallbackUrl.IndexOf("?") > 0 ? "&" : "?",
                                                userid > 0 ? "1" : "0",
                                                DNTRequest.GetString("next") == "" ? DNTRequest.GetString("next") : "&next=" + DNTRequest.GetString("next"))
                                  );
            }
        }
Beispiel #10
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         string apikey = DNTRequest.GetString("apikey");
         if (apikey != "")
         {
             APIConfigInfo aci = APIConfigs.GetConfig();
             foreach (ApplicationInfo ai in aci.AppCollection)
             {
                 if (ai.APIKey == apikey)
                 {
                     appname.Text     = ai.AppName;
                     appurl.Text      = ai.AppUrl;
                     callbackurl.Text = ai.CallbackUrl;
                     ipaddresses.Text = ai.IPAddresses;
                     break;
                 }
             }
         }
         apikeyhidd.Value = apikey;
     }
 }
        protected void DelRec_Click(object sender, EventArgs e)
        {
            string apikeylist = DNTRequest.GetString("apikey");

            if (apikeylist == "")
            {
                return;
            }
            foreach (string apikey in apikeylist.Split(','))
            {
                APIConfigInfo             aci     = APIConfigs.GetConfig();
                ApplicationInfoCollection appColl = aci.AppCollection;
                foreach (ApplicationInfo ai in appColl)
                {
                    if (ai.APIKey == apikey)
                    {
                        aci.AppCollection.Remove(ai);
                        break;
                    }
                }
                APIConfigs.SaveConfig(aci);
            }
            Response.Redirect("global_passportmanage.aspx");
        }
Beispiel #12
0
        protected override void ShowPage()
        {
            pagetitle = "用户登录";
            inapi     = DNTRequest.GetInt("inapi", 0);
            if (userid != -1)
            {
                SetUrl(BaseConfigs.GetForumPath);
                AddMsgLine("您已经登录,无须重复登录");
                ispost = true;
                SetLeftMenuRefresh();

                if (APIConfigs.GetConfig().Enable)
                {
                    APILogin(APIConfigs.GetConfig());
                }
            }

            if (LoginLogs.UpdateLoginLog(DNTRequest.GetIP(), false) >= 5)
            {
                AddErrLine("您已经多次输入密码错误, 请15分钟后再登录");
                loginsubmit = false;
                return;
            }

            SetReUrl();

            //如果提交...
            if (DNTRequest.IsPost())
            {
                SetBackLink();

                //如果没输入验证码就要求用户填写
                if (isseccode && DNTRequest.GetString("vcode") == "")
                {
                    postusername = DNTRequest.GetString("username");
                    loginauth    = DES.Encode(DNTRequest.GetString("password"), config.Passwordkey).Replace("+", "[");
                    loginsubmit  = true;
                    return;
                }

                if (Utils.StrIsNullOrEmpty(DNTRequest.GetString("username")) &&
                    Utils.StrIsNullOrEmpty(DNTRequest.GetString("password")) &&
                    Utils.StrIsNullOrEmpty(DNTRequest.GetString("loginauth"))
                    )
                {
                    AddErrLine("用户名不能为空");
                    AddErrLine("密码不能为空");
                    return;
                }

                if (config.Emaillogin == 1 && Utils.IsValidEmail(DNTRequest.GetString("username")))//允许邮箱登录
                {
                    DataTable dt = Users.GetUserInfoByEmail(DNTRequest.GetString("username"));
                    if (dt.Rows.Count == 0)
                    {
                        AddErrLine("用户不存在");
                        return;
                    }
                    if (dt.Rows.Count > 1)
                    {
                        AddErrLine("您所使用Email不唯一,请使用用户名登陆");
                        return;
                    }
                    if (dt.Rows.Count == 1)
                    {
                        postusername = dt.Rows[0]["username"].ToString();
                    }
                }
                //json字符串反序列化成实体对象
                Discuz.Entity.feipiao_userinfo_response feipiaoXmlModel = null;

                if (config.Emaillogin == 0)//禁止邮箱登录
                {
                    postusername = DNTRequest.GetString("username");
                    postpassword = DNTRequest.GetString("password");

                    #region 测试主机头
                    //string strPath = HttpContext.Current.Server.MapPath("~/Log");
                    //strPath = strPath + "\\" + "FeiPiao_UserLoginAPI" + "_" + DateTime.Now.ToString().Replace(":", "") + ".txt";
                    //StreamWriter fs = new StreamWriter(strPath, false, System.Text.Encoding.Default);
                    //fs.Write("API地址" + Discuz.Common.ConfigOperator.ConfigReadValue("FeiPiao_UserLoginAPI"));
                    //fs.Close();
                    #endregion

                    #region 调用官网接口登陆
                    //调用官网接口登陆
                    string htmlText = Discuz.Common.SendData.Intsance.SendRequest(Discuz.Common.ConfigOperator.ConfigReadValue("FeiPiao_UserLoginAPI"), "UTF-8", "action=act_login&login_type=myfeipiao&username="******"&password="******"utf-8"));
                    if (!string.IsNullOrEmpty(htmlText))
                    {
                        htmlText        = htmlText.Substring(htmlText.IndexOf("_myfeipiao_") + 11);
                        feipiaoXmlModel = (Discuz.Entity.feipiao_userinfo_response)JavaScriptConvert.DeserializeObject(htmlText, typeof(Discuz.Entity.feipiao_userinfo_response));
                        //官网登陆成功
                        if (feipiaoXmlModel.result.id == "0000")
                        {
                        }
                        else
                        {
                            AddErrLine("用户和密码不匹配");
                        }
                    }
                    #endregion
                }

                if (IsErr())
                {
                    return;
                }

                //正常获取用户信息
                ShortUserInfo userInfo = GetShortUserInfo(feipiaoXmlModel.userinfo.UserAccount, postpassword, feipiaoXmlModel.userinfo.Mobile, feipiaoXmlModel.userinfo.Email);
                //通过官网接口获取用户信息

                if (userInfo != null)
                {
                    #region 当前用户所在用户组为"禁止访问"或"等待激活"时

                    if ((userInfo.Groupid == 4 || userInfo.Groupid == 5) && userInfo.Groupexpiry != 0 && userInfo.Groupexpiry <= Utils.StrToInt(DateTime.Now.ToString("yyyyMMdd"), 0))
                    {
                        //根据当前用户的积分获取对应积分用户组
                        UserGroupInfo groupInfo = UserCredits.GetCreditsUserGroupId(userInfo.Credits);
                        usergroupid      = groupInfo.Groupid != 0 ? groupInfo.Groupid : usergroupid;
                        userInfo.Groupid = usergroupid;
                        Users.UpdateUserGroup(userInfo.Uid, usergroupid);
                    }

                    if (userInfo.Groupid == 5)// 5-禁止访问
                    {
                        AddErrLine("您所在的用户组,已经被禁止访问");
                        return;
                    }

                    if (userInfo.Groupid == 8)
                    {
                        if (config.Regverify == 1)
                        {
                            needactiveuid = userInfo.Uid;
                            email         = userInfo.Email;
                            timestamp     = DateTime.Now.Ticks.ToString();
                            authstr       = Utils.MD5(string.Concat(userInfo.Password, config.Passwordkey, timestamp));
                            AddMsgLine("请您到您的邮箱中点击激活链接来激活您的帐号");
                        }
                        else if (config.Regverify == 2)
                        {
                            AddMsgLine("您需要等待一些时间, 待系统管理员审核您的帐户后才可登录使用");
                        }
                        else
                        {
                            AddErrLine("抱歉, 您的用户身份尚未得到验证");
                        }

                        loginsubmit = false;
                        return;
                    }
                    #endregion

                    if (!Utils.StrIsNullOrEmpty(userInfo.Secques) && loginsubmit && Utils.StrIsNullOrEmpty(DNTRequest.GetString("loginauth")))
                    {
                        loginauth = DES.Encode(DNTRequest.GetString("password"), config.Passwordkey).Replace("+", "[");
                    }
                    else
                    {
                        //通过api整合的程序登录
                        if (APIConfigs.GetConfig().Enable)
                        {
                            APILogin(APIConfigs.GetConfig());
                        }


                        AddMsgLine("登录成功, 返回登录前页面");

                        #region 无延迟更新在线信息和相关用户信息
                        ForumUtils.WriteUserCookie(userInfo.Uid, TypeConverter.StrToInt(DNTRequest.GetString("expires"), -1),
                                                   config.Passwordkey, DNTRequest.GetInt("templateid", 0), DNTRequest.GetInt("loginmode", -1));

                        //oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout);
                        oluserinfo    = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout, userInfo.Uid, "");
                        olid          = oluserinfo.Olid;
                        username      = feipiaoXmlModel.userinfo.UserAccount;
                        userid        = userInfo.Uid;
                        usergroupinfo = UserGroups.GetUserGroupInfo(userInfo.Groupid);
                        useradminid   = usergroupinfo.Radminid; // 根据用户组得到相关联的管理组id


                        OnlineUsers.UpdateAction(olid, UserAction.Login.ActionID, 0);
                        LoginLogs.DeleteLoginLog(DNTRequest.GetIP());
                        Users.UpdateUserCreditsAndVisit(userInfo.Uid, DNTRequest.GetIP());
                        #endregion

                        loginsubmit = false;
                        string reurl = Utils.UrlDecode(ForumUtils.GetReUrl());
                        SetUrl(reurl.IndexOf("register.aspx") < 0 ? reurl : forumpath + "index.aspx");

                        SetLeftMenuRefresh();

                        //同步登录到第三方应用
                        if (APIConfigs.GetConfig().Enable)
                        {
                            AddMsgLine(Sync.GetLoginScript(userid, username));
                        }

                        if (!APIConfigs.GetConfig().Enable || !Sync.NeedAsyncLogin())
                        {
                            MsgForward("login_succeed", true);
                        }
                    }
                }
                else
                {
                    int errcount = LoginLogs.UpdateLoginLog(DNTRequest.GetIP(), true);
                    if (errcount > 5)
                    {
                        AddErrLine("您已经输入密码5次错误, 请15分钟后再试");
                    }
                    else
                    {
                        AddErrLine(string.Format("密码或安全提问第{0}次错误, 您最多有5次机会重试", errcount));
                    }
                }
                if (IsErr())
                {
                    return;
                }

                ForumUtils.WriteUserCreditsCookie(userInfo, usergroupinfo.Grouptitle);
            }
        }
Beispiel #13
0
        protected override void ShowPage()
        {
            pagetitle = "用户登录";

            postusername = Utils.UrlDecode(DNTRequest.GetString("postusername")).Trim();

            if (this.userid != -1)
            {
                //SetUrl("/Forum/");
                SetMetaRefresh();
                SetShowBackLink(false);
                AddMsgLine("您已经登录,无须重复登录");
                ispost = true;
                SetLeftMenuRefresh();

                APIConfigInfo apiInfo = APIConfigs.GetConfig();
                if (apiInfo.Enable)
                {
                    APILogin(apiInfo);
                }
            }

            /*
             * if (LoginLogs.UpdateLoginLog(DNTRequest.GetIP(), false) >= 5)
             * {
             *  AddMsgLine("您已经多次输入密码错误, 请15分钟后再登录");
             *  loginsubmit = false;
             *  return;
             * }
             */

            //未提交或跨页提交时
            if (!DNTRequest.IsPost() || referer != "")
            {
                string r = "";
                if (referer != "")
                {
                    r = referer;
                }
                else
                {
                    if ((DNTRequest.GetUrlReferrer() == "") || (DNTRequest.GetUrlReferrer().IndexOf("login") > -1) ||
                        DNTRequest.GetUrlReferrer().IndexOf("logout") > -1)
                    {
                        r = "index.aspx";
                    }
                    else
                    {
                        r = DNTRequest.GetUrlReferrer();
                    }
                }
                Utils.WriteCookie("reurl", (DNTRequest.GetQueryString("reurl") == "" || DNTRequest.GetQueryString("reurl").IndexOf("login.aspx") > -1) ? r : DNTRequest.GetQueryString("reurl"));
            }

            //如果提交...
            if (DNTRequest.IsPost())
            {
                StringBuilder builder = new StringBuilder();
                foreach (string key in System.Web.HttpContext.Current.Request.QueryString.AllKeys)
                {
                    if (key != "postusername")
                    {
                        builder.Append("&");
                        builder.Append(key);
                        builder.Append("=");
                        builder.Append(DNTRequest.GetQueryString(key));
                    }
                }
                base.SetBackLink("login.aspx?postusername="******"username")) + builder.ToString());


                //如果没输入验证码就要求用户填写
                if (isseccode && DNTRequest.GetString("vcode") == "")
                {
                    postusername = DNTRequest.GetString("username");
                    loginauth    = DES.Encode(DNTRequest.GetString("password"), config.Passwordkey).Replace("+", "[");
                    loginsubmit  = true;
                    return;
                }

                bool isExistsUserByName = Discuz.Forum.Users.Exists(DNTRequest.GetString("username"));
                if (!isExistsUserByName)
                {
                    Discuz.Data.DatabaseProvider.GetInstance().ClubLoginLog(1, -1, System.Web.HttpContext.Current.Request.UserHostAddress, 7);
                    AddErrLine("用户不存在");
                }

                if (DNTRequest.GetString("password").Equals("") && DNTRequest.GetString("loginauth") == "")
                {
                    AddErrLine("密码不能为空");
                }

                if (IsErr())
                {
                    return;
                }

                if (!Utils.StrIsNullOrEmpty(loginauth))
                {
                    postpassword = DES.Decode(loginauth.Replace("[", "+"), config.Passwordkey);
                }
                else
                {
                    postpassword = DNTRequest.GetString("password");
                }

                if (postusername == "")
                {
                    postusername = DNTRequest.GetString("username");
                }

                int uid = -1;
                if (config.Passwordmode == 1)
                {
                    if (config.Secques == 1 && (!Utils.StrIsNullOrEmpty(loginauth) || !loginsubmit))
                    {
                        uid = Discuz.Forum.Users.CheckDvBbsPasswordAndSecques(postusername,
                                                                              postpassword,
                                                                              DNTRequest.GetInt("question", 0),
                                                                              DNTRequest.GetString("answer"));
                    }
                    else
                    {
                        uid = Discuz.Forum.Users.CheckDvBbsPassword(postusername, postpassword);
                    }
                }
                else
                {
                    if (config.Secques == 1 && (!Utils.StrIsNullOrEmpty(loginauth) || !loginsubmit))
                    {
                        uid = Discuz.Forum.Users.CheckPasswordAndSecques(postusername,
                                                                         postpassword,
                                                                         true,
                                                                         DNTRequest.GetInt("question", 0),
                                                                         DNTRequest.GetString("answer"));
                    }
                    else
                    {
                        uid = Discuz.Forum.Users.CheckPassword(postusername, postpassword, true);
                    }
                }


                if (uid != -1)
                {
                    ShortUserInfo userinfo = Discuz.Forum.Users.GetShortUserInfo(uid);
                    if (userinfo.Groupid == 8)
                    {
                        AddErrLine("抱歉, 您的用户身份尚未得到验证");
                        if (config.Regverify == 1)
                        {
                            AddMsgLine("请您到您的邮箱中点击激活链接来激活您的帐号");
                        }

                        if (config.Regverify == 2)
                        {
                            AddMsgLine("您需要等待一些时间, 待系统管理员审核您的帐户后才可登录使用");
                        }
                        loginsubmit = false;
                    }
                    else
                    {
                        if (!Utils.StrIsNullOrEmpty(userinfo.Secques) && loginsubmit && Utils.StrIsNullOrEmpty(DNTRequest.GetString("loginauth")))
                        {
                            loginauth = DES.Encode(DNTRequest.GetString("password"), config.Passwordkey).Replace("+", "[");
                        }
                        else
                        {
                            LoginLogs.DeleteLoginLog(DNTRequest.GetIP());
                            UserCredits.UpdateUserCredits(uid);
                            ForumUtils.WriteUserCookie(
                                uid,
                                Utils.StrToInt(DNTRequest.GetString("expires"), -1),
                                config.Passwordkey,
                                DNTRequest.GetInt("templateid", 0),
                                DNTRequest.GetInt("loginmode", -1));
                            OnlineUsers.UpdateAction(olid, UserAction.Login.ActionID, 0);
                            //无延迟更新在线信息
                            oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout);
                            olid       = oluserinfo.Olid;
                            Discuz.Forum.Users.UpdateUserLastvisit(uid, DNTRequest.GetIP());

                            string reurl = Utils.UrlDecode(ForumUtils.GetReUrl());
                            if (reurl.IndexOf("register.aspx") < 0)
                            {
                                SetUrl(reurl);
                            }
                            else
                            {
                                SetUrl("index.aspx");
                            }

                            APIConfigInfo apiInfo = APIConfigs.GetConfig();
                            if (apiInfo.Enable)
                            {
                                APILogin(apiInfo);
                            }

                            Discuz.Forum.Users.SaveUserIDToCookie(uid);

                            Discuz.Data.DatabaseProvider.GetInstance().ClubLoginLog(1, uid, System.Web.HttpContext.Current.Request.UserHostAddress, 5);
                            AddMsgLine("登录成功, 返回登录前页面");

                            userid        = uid;
                            usergroupinfo = UserGroups.GetUserGroupInfo(userinfo.Groupid);
                            // 根据用户组得到相关联的管理组id
                            useradminid = usergroupinfo.Radminid;

                            SetMetaRefresh();
                            SetShowBackLink(false);

                            SetLeftMenuRefresh();

                            loginsubmit = false;
                        }
                    }
                }
                else
                {
                    int errcount = LoginLogs.UpdateLoginLog(DNTRequest.GetIP(), true);
                    if (errcount > 5)
                    {
                        AddErrLine("您已经输入密码5次错误, 请15分钟后再试");
                    }
                    else
                    {
                        if (isExistsUserByName)
                        {
                            uid = Discuz.Data.DatabaseProvider.GetInstance().GetuidByusername(postusername);
                        }
                        Discuz.Data.DatabaseProvider.GetInstance().ClubLoginLog(1, uid, System.Web.HttpContext.Current.Request.UserHostAddress, 6);
                        AddErrLine(string.Format("密码或安全提问第{0}次错误, 您最多有5次机会重试", errcount.ToString()));
                    }
                }
            }
        }
Beispiel #14
0
        protected override void ShowPage()
        {
            pagetitle = "用户登录";
            inapi     = DNTRequest.GetInt("inapi", 0);
            if (userid != -1)
            {
                SetUrl(BaseConfigs.GetForumPath);
                AddMsgLine("您已经登录,无须重复登录");
                ispost = true;
                SetLeftMenuRefresh();

                if (APIConfigs.GetConfig().Enable)
                {
                    APILogin(APIConfigs.GetConfig());
                }
            }

            if (LoginLogs.UpdateLoginLog(DNTRequest.GetIP(), false) >= 5)
            {
                AddErrLine("您已经多次输入密码错误, 请15分钟后再登录");
                loginsubmit = false;
                return;
            }

            SetReUrl();

            //如果提交...
            if (DNTRequest.IsPost())
            {
                SetBackLink();

                //如果没输入验证码就要求用户填写
                if (isseccode && DNTRequest.GetString("vcode") == "")
                {
                    postusername = DNTRequest.GetString("username");
                    loginauth    = DES.Encode(DNTRequest.GetString("password"), config.Passwordkey).Replace("+", "[");
                    loginsubmit  = true;
                    return;
                }

                if (config.Emaillogin == 1 && Utils.IsValidEmail(DNTRequest.GetString("username")))
                {
                    DataTable dt = Users.GetUserInfoByEmail(DNTRequest.GetString("username"));
                    if (dt.Rows.Count == 0)
                    {
                        AddErrLine("用户不存在");
                        return;
                    }
                    if (dt.Rows.Count > 1)
                    {
                        AddErrLine("您所使用Email不唯一,请使用用户名登陆");
                        return;
                    }
                    if (dt.Rows.Count == 1)
                    {
                        postusername = dt.Rows[0]["username"].ToString();
                    }
                }

                if (config.Emaillogin == 0)
                {
                    if ((Users.GetUserId(DNTRequest.GetString("username")) == 0))
                    {
                        AddErrLine("用户不存在");
                    }
                }

                if (Utils.StrIsNullOrEmpty(DNTRequest.GetString("password")) && Utils.StrIsNullOrEmpty(DNTRequest.GetString("loginauth")))
                {
                    AddErrLine("密码不能为空");
                }

                if (IsErr())
                {
                    return;
                }

                ShortUserInfo userInfo = GetShortUserInfo();

                if (userInfo != null)
                {
                    #region 当前用户所在用户组为"禁止访问"或"等待激活"时

                    if ((userInfo.Groupid == 4 || userInfo.Groupid == 5) && userInfo.Groupexpiry != 0 && userInfo.Groupexpiry <= Utils.StrToInt(DateTime.Now.ToString("yyyyMMdd"), 0))
                    {
                        //根据当前用户的积分获取对应积分用户组
                        UserGroupInfo groupInfo = UserCredits.GetCreditsUserGroupId(userInfo.Credits);
                        usergroupid      = groupInfo.Groupid != 0 ? groupInfo.Groupid : usergroupid;
                        userInfo.Groupid = usergroupid;
                        Users.UpdateUserGroup(userInfo.Uid, usergroupid);
                    }

                    if (userInfo.Groupid == 5)// 5-禁止访问
                    {
                        AddErrLine("您所在的用户组,已经被禁止访问");
                        return;
                    }

                    if (userInfo.Groupid == 8)
                    {
                        if (config.Regverify == 1)
                        {
                            needactiveuid = userInfo.Uid;
                            email         = userInfo.Email;
                            timestamp     = DateTime.Now.Ticks.ToString();
                            authstr       = Utils.MD5(string.Concat(userInfo.Password, config.Passwordkey, timestamp));
                            AddMsgLine("请您到您的邮箱中点击激活链接来激活您的帐号");
                        }
                        else if (config.Regverify == 2)
                        {
                            AddMsgLine("您需要等待一些时间, 待系统管理员审核您的帐户后才可登录使用");
                        }
                        else
                        {
                            AddErrLine("抱歉, 您的用户身份尚未得到验证");
                        }

                        loginsubmit = false;
                        return;
                    }
                    #endregion

                    if (!Utils.StrIsNullOrEmpty(userInfo.Secques) && loginsubmit && Utils.StrIsNullOrEmpty(DNTRequest.GetString("loginauth")))
                    {
                        loginauth = DES.Encode(DNTRequest.GetString("password"), config.Passwordkey).Replace("+", "[");
                    }
                    else
                    {
                        //通过api整合的程序登录
                        if (APIConfigs.GetConfig().Enable)
                        {
                            APILogin(APIConfigs.GetConfig());
                        }


                        AddMsgLine("登录成功, 返回登录前页面");

                        #region 无延迟更新在线信息和相关用户信息
                        ForumUtils.WriteUserCookie(userInfo.Uid, TypeConverter.StrToInt(DNTRequest.GetString("expires"), -1),
                                                   config.Passwordkey, DNTRequest.GetInt("templateid", 0), DNTRequest.GetInt("loginmode", -1));
                        //oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout);
                        oluserinfo    = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout, userInfo.Uid, "");
                        olid          = oluserinfo.Olid;
                        username      = DNTRequest.GetString("username");
                        userid        = userInfo.Uid;
                        usergroupinfo = UserGroups.GetUserGroupInfo(userInfo.Groupid);
                        useradminid   = usergroupinfo.Radminid; // 根据用户组得到相关联的管理组id


                        OnlineUsers.UpdateAction(olid, UserAction.Login.ActionID, 0);
                        LoginLogs.DeleteLoginLog(DNTRequest.GetIP());
                        Users.UpdateUserCreditsAndVisit(userInfo.Uid, DNTRequest.GetIP());
                        #endregion

                        loginsubmit = false;
                        string reurl = Utils.UrlDecode(ForumUtils.GetReUrl());
                        SetUrl(reurl.IndexOf("register.aspx") < 0 ? reurl : forumpath + "index.aspx");

                        SetLeftMenuRefresh();

                        //同步登录到第三方应用
                        if (APIConfigs.GetConfig().Enable)
                        {
                            AddMsgLine(Sync.GetLoginScript(userid, username));
                        }

                        if (!APIConfigs.GetConfig().Enable || !Sync.NeedAsyncLogin())
                        {
                            MsgForward("login_succeed", true);
                        }
                    }
                }
                else
                {
                    int errcount = LoginLogs.UpdateLoginLog(DNTRequest.GetIP(), true);
                    if (errcount > 5)
                    {
                        AddErrLine("您已经输入密码5次错误, 请15分钟后再试");
                    }
                    else
                    {
                        AddErrLine(string.Format("密码或安全提问第{0}次错误, 您最多有5次机会重试", errcount));
                    }
                }
                if (IsErr())
                {
                    return;
                }

                ForumUtils.WriteUserCreditsCookie(userInfo, usergroupinfo.Grouptitle);
            }
        }
Beispiel #15
0
        void RESTServer_Load(object sender, EventArgs e)
        {
            Response.Clear();
            Response.ContentType = "text/xml";

            APIConfigInfo apiInfo = APIConfigs.GetConfig();
            if (!apiInfo.Enable)
            {
                ResponseErrorInfo((int)ErrorType.API_EC_SERVICE);
                return;
            }

            //check sig
            DNTParam[] parameters = GetParamsFromRequest(Request);


            //GetRequests

            /*---- optional ----*/

            //format
            string format = DNTRequest.GetString("format");
            //callback
            string callback = DNTRequest.GetString("callback");
           

            /*---- required ----*/

            //api_key
            string api_key = DNTRequest.GetString("api_key");
            //整合程序对象
            ApplicationInfo appInfo = null;
            ApplicationInfoCollection appcollection = apiInfo.AppCollection;
            foreach (ApplicationInfo newapp in appcollection)
            {
                if (newapp.APIKey == DNTRequest.GetString("api_key"))
                {
                    appInfo = newapp;
                }
            }

            if (appInfo == null)
            {
                //输出API Key错误
                ResponseErrorInfo((int)ErrorType.API_EC_APPLICATION);
                return;
            }
            //check request ip
            string ip = DNTRequest.GetIP();
            if (appInfo.IPAddresses != null && appInfo.IPAddresses.Trim() != string.Empty && !Utils.InIPArray(ip, appInfo.IPAddresses.Split(',')))
            {
                ResponseErrorInfo((int)ErrorType.API_EC_BAD_IP);
                return;
            }

            /*---- required by specific method----*/



            string sig = GetSignature(parameters, appInfo.Secret);
            //if (sig != DNTRequest.GetString("sig"))
            //{
            //    //输出签名错误
            //    ResponseErrorInfo((int)ErrorType.API_EC_SIGNATURE);
            //    return;
            //}

            //get session_key and check user
            string session_key = DNTRequest.GetString("session_key");
            int uid = GetUidFromSessionKey(session_key, appInfo.Secret);




            string method = DNTRequest.GetString("method");
            if (method == string.Empty)
            {
                ResponseErrorInfo((int)ErrorType.API_EC_METHOD);
                return;
            }
            string classname = method.Substring(0, method.LastIndexOf('.'));
            string methodname = method.Substring(method.LastIndexOf('.') + 1);

            string content;
            ActionBase action;
            double lastcallid = -1;
            double callid = -1;
            try
            {
                Type type = Type.GetType(string.Format("Discuz.Web.Services.API.Actions.{0}, Discuz.Web.Services", classname), false, true);
                action = (ActionBase)Activator.CreateInstance(type);
                action.ApiKey = api_key;
                action.Params = parameters;
                action.App = appInfo;
                action.Secret = appInfo.Secret;
                action.Uid = uid;
                action.Format = FormatType.XML;
                action.Signature = sig;

                //call_id    - milliseconds  record last callid
                double.TryParse(DNTRequest.GetString("call_id"), out callid);
                if (callid > -1)
                {
                    if (Session["call_id"] == null)
                        lastcallid = -1;
                    else
                        double.TryParse(Session["call_id"].ToString(), out lastcallid);
                }
                action.CallId = callid;
                action.LastCallId = lastcallid;

                if (format.Trim().ToLower() == "json")
                {
                    Response.ContentType = "text/html";
                    action.Format = FormatType.JSON;
                }

                content = type.InvokeMember(methodname, BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.IgnoreCase, null, action, new object[] { }).ToString();
            }
            catch
            {
                content = "";
                ResponseErrorInfo((int)ErrorType.API_EC_METHOD);
                return;
            }
            if (action.ErrorCode > 0)
            {
                ResponseErrorInfo(action.ErrorCode);
                return;
            }

            //update callid
            if (callid > lastcallid)
            {
                Session["call_id"] = callid;
            }

            //成功后适当的地方更新用户在线状态
            if (callback != string.Empty)
            {
                Response.ContentType = "text/html";
                if (action.Format == FormatType.JSON)
                {
                    content = callback + "(" + content + ");";
                }
                else
                {
                    content = callback + "(\"" + content.Replace("\"", "\\\"") + "\");";
                }
            }
            Response.Write(content);
            Response.End();

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int    pertask       = DNTRequest.GetInt("pertask", 0);
                int    lastnumber    = DNTRequest.GetInt("lastnumber", 0);
                int    startvalue    = DNTRequest.GetInt("startvalue", 0);
                int    endvalue      = DNTRequest.GetInt("endvalue", 0);
                string resultmessage = "";
                switch (Request.Params["opname"])
                {
                case "UpdatePostSP":
                    AdminForumStats.UpdatePostSP(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "UpdateMyPost":
                    AdminForumStats.UpdateMyPost(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetFourmTopicAPost":
                    //AdminForumStats.ReSetFourmTopicAPost(pertask, ref lastnumber);
                    AdminForumStats.ReSetFourmTopicAPost();
                    resultmessage = "-1";
                    break;

                case "ReSetUserDigestPosts":
                    //AdminForumStats.ReSetUserDigestPosts(pertask, ref lastnumber);
                    //resultmessage = lastnumber.ToString();
                    AdminForumStats.ReSetUserDigestPosts();
                    resultmessage = "-1";
                    break;

                case "ReSetUserPosts":
                    AdminForumStats.ReSetUserPosts(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetTopicPosts":
                    AdminForumStats.ReSetTopicPosts(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetFourmTopicAPost_StartEnd":
                    AdminForumStats.ReSetFourmTopicAPost(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ReSetUserDigestPosts_StartEnd":
                    AdminForumStats.ReSetUserDigestPosts(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ReSetUserPosts_StartEnd":
                    AdminForumStats.ReSetUserPosts(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ReSetTopicPosts_StartEnd":
                    AdminForumStats.ResetLastRepliesInfoOfTopics(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ftptest":
                    FTPs   ftps    = new FTPs();
                    string message = "";
                    bool   ok      = ftps.TestConnect(DNTRequest.GetString("serveraddress"), DNTRequest.GetInt("serverport", 0), DNTRequest.GetString("username"),
                                                      DNTRequest.GetString("password"), DNTRequest.GetInt("timeout", 0), DNTRequest.GetString("uploadpath"), ref message);
                    resultmessage = ok ? "ok" : "远程附件设置测试出现错误!\n描述:" + message;
                    break;

                case "setapp":
                    APIConfigInfo aci = APIConfigs.GetConfig();
                    aci.Enable = DNTRequest.GetString("allowpassport") == "1";
                    APIConfigs.SaveConfig(aci);
                    resultmessage = "ok";
                    break;

                case "location":
                    string city = DNTRequest.GetString("city");
                    resultmessage = "ok";
                    DataTable dt = MallPluginProvider.GetInstance().GetLocationsTable();
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr["country"].ToString() == DNTRequest.GetString("country") && dr["state"].ToString() == DNTRequest.GetString("state") && dr["city"].ToString() == city)
                        {
                            resultmessage = "<img src='../images/false.gif' title='" + city + "已经存在!'>";
                            break;
                        }
                    }
                    break;

                case "goodsinfo":
                    int       goodsid   = DNTRequest.GetInt("goodsid", 0);
                    Goodsinfo goodsinfo = MallPluginProvider.GetInstance().GetGoodsInfo(goodsid);
                    if (goodsinfo == null)
                    {
                        resultmessage = "商品不存在!";
                        break;
                    }
                    //GoodsattachmentinfoCollection attachmentinfos = GoodsAttachments.GetGoodsAttachmentsByGoodsid(goodsinfo.Goodsid);
                    //string img = "";
                    //if (attachmentinfos != null)
                    //{
                    //    img = attachmentinfos[0].Filename;
                    //}
                    PostpramsInfo param = new PostpramsInfo();
                    param.Allowhtml  = 1;
                    param.Showimages = 1;
                    param.Sdetail    = goodsinfo.Message;
                    resultmessage    = "<table width='100%'><tr><td>" + UBB.UBBToHTML(param) + "</td></tr></table>";
                    break;

                case "downloadword":
                    dt = BanWords.GetBanWordList();
                    string words = "";
                    if (dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            words += dt.Rows[i][2].ToString() + "=" + dt.Rows[i][3].ToString() + "\r\n";
                        }
                    }

                    string filename = "words.txt";
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.Buffer          = false;
                    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
                    HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(filename));
                    HttpContext.Current.Response.ContentType = "text/plain";
                    HttpContext.Current.Response.Write(words);
                    HttpContext.Current.Response.End();
                    break;

                case "gettopicinfo":
                    StringBuilder sb   = new StringBuilder();
                    TopicInfo     info = Topics.GetTopicInfo(DNTRequest.GetInt("tid", 0));
                    sb.Append("[");
                    if (info != null)
                    {
                        sb.Append(string.Format("{{'tid':{0},'title':'{1}'}}", info.Tid, info.Title));
                    }

                    System.Web.HttpContext.Current.Response.Clear();
                    System.Web.HttpContext.Current.Response.ContentType = "application/json";
                    System.Web.HttpContext.Current.Response.Expires     = 0;
                    System.Web.HttpContext.Current.Response.Cache.SetNoStore();
                    System.Web.HttpContext.Current.Response.Write(sb.Append("]").ToString());
                    System.Web.HttpContext.Current.Response.End();
                    break;
                }
                Response.Write(resultmessage);
                Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
                Response.Expires         = -1;
                Response.End();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int    pertask       = DNTRequest.GetInt("pertask", 0);
                int    lastnumber    = DNTRequest.GetInt("lastnumber", 0);
                int    startvalue    = DNTRequest.GetInt("startvalue", 0);
                int    endvalue      = DNTRequest.GetInt("endvalue", 0);
                string resultmessage = "";
                switch (Request.Params["opname"])
                {
                case "ReSetFourmTopicAPost":
                    AdminForumStats.ReSetFourmTopicAPost(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetUserDigestPosts":
                    AdminForumStats.ReSetUserDigestPosts(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetUserPosts":
                    AdminForumStats.ReSetUserPosts(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetTopicPosts":
                    AdminForumStats.ReSetTopicPosts(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetFourmTopicAPost_StartEnd":
                    AdminForumStats.ReSetFourmTopicAPost(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ReSetUserDigestPosts_StartEnd":
                    AdminForumStats.ReSetUserDigestPosts(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ReSetUserPosts_StartEnd":
                    AdminForumStats.ReSetUserPosts(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ReSetTopicPosts_StartEnd":
                    AdminForumStats.ReSetTopicPosts(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ftptest":
                    string serveraddress = DNTRequest.GetString("serveraddress");
                    string serverport    = DNTRequest.GetString("serverport");
                    string username      = DNTRequest.GetString("username");
                    string password      = DNTRequest.GetString("password");
                    string timeout       = DNTRequest.GetString("timeout");
                    string uploadpath    = DNTRequest.GetString("uploadpath");
                    FTPs   ftps          = new FTPs();
                    string message       = "";
                    bool   ok            = ftps.TestConnect(serveraddress, int.Parse(serverport), username, password, int.Parse(timeout), uploadpath, ref message);
                    if (ok)
                    {
                        resultmessage = "ok";
                    }
                    else
                    {
                        resultmessage = "远程附件设置测试出现错误!\n描述:" + message;
                    }
                    break;

                case "setapp":
                    string        allowpassport = DNTRequest.GetString("allowpassport");
                    APIConfigInfo aci           = APIConfigs.GetConfig();
                    aci.Enable = allowpassport == "1";
                    APIConfigs.SaveConfig(aci);
                    resultmessage = "ok";
                    break;
                }
                Response.Write(resultmessage);
                Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
                Response.Expires         = -1;
                Response.End();
            }
        }
        protected void savepassportinfo_Click(object sender, EventArgs e)
        {
            if (appname.Text.Trim() == "")
            {
                base.RegisterStartupScript("PAGE", "alert('整合程序名称不能为空!');");
                return;
            }
            if (applicationtype.SelectedValue != "2")
            {
                if (appurl.Text.Trim() == "")
                {
                    base.RegisterStartupScript("PAGE", "alert('整合程序 Url 地址不能为空!');");
                    return;
                }
                if (applicationtype.SelectedValue == "1" && callbackurl.Text.Trim() == "")
                {
                    base.RegisterStartupScript("PAGE", "alert('登录完成后返回地址不能为空!');");
                    return;
                }
            }
            if (ipaddresses.Text.Trim() != "")
            {
                foreach (string ip in ipaddresses.Text.Replace("\r\n", "").Replace(" ", "").Split(','))
                {
                    if (!Utils.IsIP(ip))
                    {
                        base.RegisterStartupScript("PAGE", "alert('IP地址格式错误!');");
                        return;
                    }
                }
            }
            if (apikeyhidd.Value == "") //增加
            {
                ApplicationInfo ai = new ApplicationInfo();
                ai.AppName         = appname.Text;
                ai.AppUrl          = appurl.Text;
                ai.APIKey          = Utils.MD5(System.Guid.NewGuid().ToString());
                ai.Secret          = Utils.MD5(System.Guid.NewGuid().ToString());
                ai.ApplicationType = Convert.ToInt32(applicationtype.SelectedValue);
                if (ai.ApplicationType == 1)
                {
                    ai.CallbackUrl = callbackurl.Text;
                }
                else
                {
                    ai.CallbackUrl = "";
                }
                ai.CallbackUrl = callbackurl.Text;
                ai.IPAddresses = ipaddresses.Text.Replace("\r\n", "").Replace(" ", "");

                ai.SyncMode = Convert.ToInt32(asyncmode.SelectedValue);
                ai.SyncUrl  = asyncurl.Text;
                ai.SyncList = asynclist.Text;

                APIConfigInfo aci = APIConfigs.GetConfig();
                if (aci.AppCollection == null)
                {
                    aci.AppCollection = new ApplicationInfoCollection();
                }
                aci.AppCollection.Add(ai);
                APIConfigs.SaveConfig(aci);
            }
            else   //修改
            {
                APIConfigInfo aci = APIConfigs.GetConfig();
                foreach (ApplicationInfo ai in aci.AppCollection)
                {
                    if (ai.APIKey == apikeyhidd.Value)
                    {
                        ai.AppName         = appname.Text;
                        ai.AppUrl          = appurl.Text;
                        ai.ApplicationType = Convert.ToInt32(applicationtype.SelectedValue);
                        if (ai.ApplicationType == 1)
                        {
                            ai.CallbackUrl = callbackurl.Text;
                        }
                        else
                        {
                            ai.CallbackUrl = "";
                        }
                        ai.CallbackUrl = callbackurl.Text;
                        ai.IPAddresses = ipaddresses.Text.Replace("\r\n", "").Replace(" ", "");

                        ai.SyncMode = Convert.ToInt32(asyncmode.SelectedValue);
                        ai.SyncUrl  = asyncurl.Text;
                        ai.SyncList = asynclist.Text;
                        break;
                    }
                }
                APIConfigs.SaveConfig(aci);
            }
            Response.Redirect("global_passportmanage.aspx");
        }