Exemplo n.º 1
0
 public Account GetAuthenticatedAccount()
 {
     if (HttpContext.Current.Request["Authenticator"] != null && HttpContext.Current.Request["accountID"] != null)
     {
         SSORequest ssoRequest = SSORequest.GetRequest(HttpContext.Current);
         string     actID      = ssoRequest.AccountID;
         if (Authentication.ValidateEACToken(ssoRequest) && !string.IsNullOrEmpty(actID) && We7Helper.IsGUID(actID))
         {
             Security.SetAccountID(actID);
             return(RemoteHelper.GetAccount(actID, null));
         }
         else
         {
             return(null);
         }
     }
     else if (HttpContext.Current.Request["Authenticator"] == null)
     {
         SSORequest req = new SSORequest();
         req.Action = "authenticate";
         req.SiteID = SiteConfigs.GetConfig().SiteID;
         Authentication.CreateAppToken(req);
         Authentication.Post(req, SiteConfigs.GetConfig().PassportAuthPage);
         return(null);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 2
0
 protected override void OnLoad(EventArgs e)
 {
     base.OnLoad(e);
     IsSignIn = Security.IsAuthenticated();
     if (Html.IsPostBack)
     {
         InitParam();
         if (Action == "login")
         {
             Authenticate();
         }
         else if (Action == "logout")
         {
             Signout();
         }
     }
     if (!String.IsNullOrEmpty(Request["Authenticator"]) && !String.IsNullOrEmpty(Request["accountID"]))
     {
         SSORequest ssoRequest = SSORequest.GetRequest(HttpContext.Current);
         string     actID      = ssoRequest.AccountID;
         if (Authentication.ValidateEACToken(ssoRequest) && !string.IsNullOrEmpty(actID) && We7Helper.IsGUID(actID))
         {
             Security.SetAccountID(actID);
             IsSignIn = true;
         }
     }
     if (Security.IsAuthenticated())
     {
         Response.Redirect(ReturnUrl);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 验证用户
        /// </summary>
        void Authenticate()
        {
            if (String.Compare(LoginName, SiteConfigs.GetConfig().AdministratorName, false) == 0)
            {
                if (CDHelper.AdminPasswordIsValid(Password))
                {
                    Security.SetAccountID(We7Helper.EmptyGUID);
                    UserName = SiteConfigs.GetConfig().AdministratorName;
                    IsSignIn = true;
                }
                else
                {
                    IsSignIn = false;
                    Message  = "密码错误";
                }
            }
            else
            {
                if (Request["Authenticator"] != null && Request["accountID"] != null)
                {
                    SSORequest ssoRequest = SSORequest.GetRequest(HttpContext.Current);
                    string     actID      = ssoRequest.AccountID;
                    if (Authentication.ValidateEACToken(ssoRequest) && !string.IsNullOrEmpty(actID) && We7Helper.IsGUID(actID))
                    {
                        Security.SetAccountID(actID, IsPersist);
                        UserName = ssoRequest.UserName;
                        IsSignIn = true;
                    }
                    else if (Request["message"] != null)
                    {
                        Message  = Request["message"];
                        IsSignIn = false;
                        return;
                    }
                }
                else
                {
                    IAccountHelper AccountHelper = AccountFactory.CreateInstance();

                    string[] result = AccountHelper.Login(LoginName, Password);

                    if (result[0] == "false")
                    {
                        Message  = result[1];
                        IsSignIn = false;
                    }
                    else
                    {
                        IsSignIn = true;
                        UserName = AccountHelper.GetAccount(result[1], new string[] { "LoginName" }).LoginName;
                        Response.Redirect(ReturnUrl);
                    }
                }
            }
        }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GeneralConfigInfo si = GeneralConfigs.GetConfig();
                if (si != null)
                {
                    if (si.IsOEM)
                    {
                        CopyrightLiteral.Text = si.Copyright;
                    }
                    else
                    {
                        CopyrightLiteral.Text = si.CopyrightOfWe7;
                    }
                }

                SiteConfigInfo sci = SiteConfigs.GetConfig();
                if (sci == null)
                {
                    Response.Write("对不起,您的系统已升级,但配置文件尚未升级,您需要对配置数据进行升级。现在升级吗?<a href='../install/upgradeconfig.aspx'><u>现在升级</u></a>");
                    Response.End();
                }
                else
                {
#if DEBUG
                    LoginNameTextBox.Text = sci.AdministratorName;
#endif
                    GenerateRandomCode();
                    if (Request["action"] != null && Request["action"].ToString() == "logout" && Request["Authenticator"] == null)
                    {
                        //记录日志
                        string content = string.Format("退出站点");
                        AddLog("站点登录", content);
                        string result = SignOut();
                        if (!string.IsNullOrEmpty(result))
                        {
                            ShowMessage("登录退出没有成功!原因:" + result);
                        }
                        else
                        {
                            SSOLogout();
                        }
                    }
                }
            }

            if (Request["user"] != null && Request["pass"] != null)
            {
                LoginAction(Request["user"].ToString(), Request["pass"].ToString());
            }

            if (Request["Authenticator"] != null && Request["accountID"] != null)
            {
                SSORequest ssoRequest = SSORequest.GetRequest(HttpContext.Current);
                string     actID      = ssoRequest.AccountID;
                if (Authentication.ValidateEACToken(ssoRequest) && !string.IsNullOrEmpty(actID) && We7Helper.IsGUID(actID))
                {
                    Security.SetAccountID(actID);
                    SSOLogin(ssoRequest.UserName, ssoRequest.Password);
                    GoWhere();
                }
                else if (Request["message"] != null)
                {
                    ShowMessage("登录失败!原因:" + Request["message"]);
                    return;
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 验证用户
        /// </summary>
        void Authenticate()
        {
            if (Request["Authenticator"] != null && Request["accountID"] != null)
            {
                SSORequest ssoRequest = SSORequest.GetRequest(HttpContext.Current);
                string     actID      = ssoRequest.AccountID;
                if (Authentication.ValidateEACToken(ssoRequest) && !string.IsNullOrEmpty(actID) && We7Helper.IsGUID(actID))
                {
                    Security.SetAccountID(actID);
                }
                else if (Request["message"] != null)
                {
                    Message = Request["message"];
                    return;
                }
            }
            else
            {
                Session["$ActionFrom"] = Request.UrlReferrer.PathAndQuery;
                Session["$_ActionID"]  = _ActionID;
                IAccountHelper AccountHelper = AccountFactory.CreateInstance();
                string         loginName     = Name;
                //邮箱格式
                if (Name.IndexOf('@') > -1)
                {
                    Account account = AccountHelper.GetAccountByEmail(Name);
                    if (account != null)
                    {
                        loginName = account.LoginName;
                    }
                }

                string[] result = AccountHelper.Login(loginName, Password);
                if (result[0] == "false")
                {
                    Message = result[1];
                    return;
                }
                else
                {
                    Author = result[1];
                }
            }

            if (!string.IsNullOrEmpty(ReturnUrl))
            {
                Response.Redirect(ReturnUrl);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 从Url中取得ID号
        /// </summary>
        /// <returns></returns>
        public static string GetIDFromUrl()
        {
            string path = HttpContext.Current.Request.RawUrl; //取得Url的原始地址

            GeneralConfigInfo si = GeneralConfigs.GetConfig();

            if (si == null)
            {
                return("");
            }
            string ext = si.UrlFormat;

            if (ext == null || ext.Length == 0)
            {
                ext = "html";
            }

            if (path.LastIndexOf("?") > -1)
            {
                if (path.ToLower().IndexOf("article=") > -1)
                {
                    path = path.Substring(path.ToLower().IndexOf("article=") + 8);
                }
                else
                {
                    path = path.Remove(path.LastIndexOf("?"));
                }
            }

            string mathstr = @"/(\w|\s|(-)|(_))+\." + ext + "$";

            if (path.ToLower().EndsWith("default." + ext))
            {
                path = path.Remove(path.Length - 12);
            }
            if (path.ToLower().EndsWith("index." + ext))
            {
                path = path.Remove(path.Length - 10);
            }

            if (Regex.IsMatch(path, mathstr))
            {
                int lastSlash = path.LastIndexOf("/");
                if (lastSlash > -1)
                {
                    path = path.Remove(0, lastSlash + 1);
                }

                int lastDot = path.LastIndexOf(".");
                if (lastDot > -1)
                {
                    path = path.Remove(lastDot, path.Length - lastDot);
                }

                if (We7Helper.IsGUID(We7Helper.FormatToGUID(path)))
                {
                    path = We7Helper.FormatToGUID(path);
                }
                else
                {
                    int lastSub = path.LastIndexOf("-");
                    if (lastSub > -1)
                    {
                        path = path.Remove(0, lastSub + 1);
                    }

                    if (!We7Helper.IsNumber(path))
                    {
                        path = "";
                    }
                    else
                    {
                        path = HelperFactory.Instance.GetHelper <ArticleHelper>().GetArticleIDBySN(path);
                    }
                }

                return(path);
            }
            else
            {
                return(string.Empty);
            }
        }