コード例 #1
0
ファイル: Account.cs プロジェクト: ttrr1/Midea
        /// <summary>
        /// 获得Cookie帐户身份
        /// </summary>
        /// <param name="IsAdmin">是否是管理员身份验证</param>
        /// <returns></returns>
        private static int GetCookieUserID(bool IsAdmin)
        {
            #region Cookie认证 Cookie
            //Cookie信息
            if (Utils.GetCookie(ConfigHelper.GetConfigString("CookieName")) == "")
            {
                //Cookie账户不存在
                Cookie.ClearUserCookie();
                return(-1);
            }

            //Cookie信息
            int    CookieUid = Utils.StrToInt(Cookie.GetCookie(ConfigHelper.GetConfigString("CookieUserid")), -1);
            string CookiePWD = Cookie.GetCookiePassword(Cookie.GetCookie(ConfigHelper.GetConfigString("CookiePassword")));
            if (CookieUid == -1 || CookiePWD == "")
            {
                //Cookie账户数据错误
                Cookie.ClearUserCookie();
                return(-1);
            }
            #endregion

            #region IP认证 IpBlock
            ////IP访问限制选项
            //int AdminIpBlockType = iPortal.BLL.SysConfig.GetInt("WebConfig", "AdminIpBlockType", 0);
            //if (AdminIpBlockType == 0)//无访问限制
            //{ }
            //else if (AdminIpBlockType == 1) //启用黑名单,禁止黑名单中的IP进行访问,其余允许访问
            //{
            //    SysIpBlock bllIpBlock = new SysIpBlock();
            //    if (bllIpBlock.Exists(0, 1, Utils.GetRealIP()))
            //        return -1;
            //}
            //else if (AdminIpBlockType == 2) //启用白名单,允许白名单中的IP进行访问,其余禁止访问
            //{
            //    SysIpBlock bllIpBlock = new SysIpBlock();
            //    if (!bllIpBlock.Exists(0, 0, Utils.GetRealIP()))
            //        return -1;
            //}
            #endregion

            #region 账户认证 Account
            //账户认证
            Account bllAccount = new Account();
            int     ret        = bllAccount.CheckLogin(CookieUid, CookiePWD);
            if (ret < 1)
            {
                //账户登陆失败
                Cookie.ClearUserCookie();
                return(-1);
            }
            #endregion

            #region 用户认证 Member
            //用户认证,错误检验
            //Member bllMember = new Member();
            //Model.Member modelMember = bllMember.GetModel(ret);
            //if (modelMember == null)
            //{
            //    //不是用户
            //    Cookie.ClearUserCookie();
            //    return -1;
            //}
            //else if (modelMember.State == 0)
            //{
            //    //用户锁定
            //    Cookie.ClearUserCookie();
            //    return -1;
            //}
            #endregion

            //用户登陆,成功返回
            if (!IsAdmin)
            {
                return(ret);
            }

            #region 管理员认证 Admin
            //管理员认证,错误检验
            Admin       bllAdmin   = new Admin();
            Model.Admin modelAdmin = bllAdmin.GetModel(ret);
            if (modelAdmin == null)
            {
                //不是管理员
                Cookie.ClearUserCookie();
                return(-1);
            }
            else if (modelAdmin.State == 0)
            {
                //管理员锁定
                Cookie.ClearUserCookie();
                return(-1);
            }
            #endregion

            //管理员认证,成功返回
            return(ret);
        }
コード例 #2
0
ファイル: login.aspx.cs プロジェクト: ttrr1/Midea
    /// <summary>
    /// 登陆
    /// </summary>
    private void UserLogin()
    {
        //URL登陆定向,涉及SSO登陆
        if (url.Length > 7 && url.Substring(0, 7) == "http://")
        {
            url = "";
        }
        else
        {
            url = Utils.UrlEncode(url);
        }

        //用户名字段判断
        if (username == "")
        {
            Response.Redirect("login.aspx?url=" + url + "&errmsg=帐户为空,请重新输入!&username="******"")
        {
            Response.Redirect("login.aspx?url=" + url + "&errmsg=密码为空,请重新输入!&username="******"")
        //    Response.Redirect("login.aspx?url=" + url + "&errmsg=验证码为空,请重新输入!&username="******"ValidateCode"].Value.ToLower())
        //    Response.Redirect("login.aspx?url=" + url + "&errmsg=验证码不正确,请重新输入!&username="******"WebConfig", "AdminIpBlockType", 0);
        switch (AdminIpBlockType)
        {
        case 0:
            break;

        case 1:
        {
            var bllIpBlock = new Sys.BLL.SysIpBlock();
            if (bllIpBlock.Exists(0, 1, Utils.GetRealIP()))
            {
                Response.Redirect("login.aspx?url=" + url + "&errmsg=当前IP被限制登录系统后台!&username="******"login.aspx?url=" + url + "&errmsg=当前IP被限制登录系统后台!&username="******"login.aspx?url=" + url + "&errmsg=帐户不存在!&username="******"login.aspx?url=" + url + "&errmsg=密码不正确!&username="******"login.aspx?url=" + url + "&errmsg=该账户无权登陆系统!&username="******"login.aspx?url=" + url + "&errmsg=该账户禁止登陆系统!&username="******"login.aspx?url=" + url + "&errmsg=该账户无权登陆系统后台!&username="******"login.aspx?url=" + url + "&errmsg=该账户禁止登陆系统后台!&username="******"managelogin", "登陆成功");

        //Cookie保存-帐户
        Sys.BLL.Admin.SetUsername(modelAdmin.Username);
        //Cookie保存-姓名
        Sys.BLL.Admin.SetRealName(modelAdmin.RealName);

        //Cookie保存-rememberme
        if (PageRequest.GetInt("rememberme", 0) == 1)
        {
            Utils.WriteCookie("manage_LoginName", Utils.UrlEncode(username), 518400, ConfigHelper.GetConfigString("CookieDomain"));
        }

        if (modelAdmin.Username == modelAdmin.RealName)
        {
            Response.Redirect("main.aspx?url=" + Utils.UrlEncode("user/profile.aspx"));
        }
        else if (url != "")
        {
            Response.Redirect("main.aspx?url=" + Utils.UrlEncode(url));
        }
        else
        {
            Response.Redirect("main.aspx");
        }
    }