Example #1
0
        /// <summary>
        /// 用户淘宝店授权信息(用户获取淘宝的权限)
        /// </summary>
        /// <param name="strMsg"></param>
        public void getUserTaobao(string[] strMsg)
        {
            List <model.taoAppUser> taoAppUserMdList = new List <model.taoAppUser>(); //用户淘宝店授权信息
            string access_tokens = strMsg[3].ToString();
            string nicks         = HttpUtility.UrlDecode(strMsg[2].ToString());

            if (!string.IsNullOrEmpty(access_tokens) && !string.IsNullOrEmpty(nicks))
            {
                string[] Access_tokens = access_tokens.Split(',');
                string[] Nicks         = nicks.Split(',');

                for (int i = 0; i < Access_tokens.Length; i++)
                {
                    bll.taoAppUserbll taoAppUserBll = new bll.taoAppUserbll();

                    #region
                    IDataParameter[] iparaNick = new IDataParameter[] {
                        new SqlParameter("tbUserNick", SqlDbType.NVarChar, 200),
                    };
                    iparaNick[0].Value = Nicks[i];
                    #endregion
                    //model.taoAppUser taoAppUserMd = taoAppUserBll.GetModelByNick(Nicks[i]);
                    model.taoAppUser taoAppUserMd = taoAppUserBll.GetModelByNick(iparaNick, "taoAppUsersNickSelect");
                    if (taoAppUserMd == null)
                    {
                        taoAppUserMd = new model.taoAppUser();
                    }
                    taoAppUserMd.accessToken = Access_tokens[i];
                    taoAppUserMd.tbUserNick  = Nicks[i];

                    taoAppUserMdList.Add(taoAppUserMd);
                }
            }
            us.TaoAppUserList = taoAppUserMdList;
        }
Example #2
0
        //public ActionResult Index(FormCollection collention)

        public ActionResult Index(string userName, string password)
        {
            IDataParameter[] ipara = new IDataParameter[] {
                new SqlParameter("userName", SqlDbType.NVarChar, 20),
                new SqlParameter("userPwd", SqlDbType.NVarChar, 50)
            };


            if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
            {
                // 密码加密
                password = helpcommon.PasswordHelp.encrypt(password);
                //密码二次加密
                password       = helpcommon.PasswordHelp.encrypt(password);
                ipara[0].Value = userName;
                ipara[1].Value = password;

                pbxdata.bll.usersbll userBll = new bll.usersbll();
                //是否存在
                List <model.users>  listUserMd = userBll.GetModel(ipara, "usersSelect");
                pbxdata.model.users userMd     = null;
                if (listUserMd.Count > 0)
                {
                    userMd = listUserMd[0];
                }

                if (userMd != null)
                {
                    //设置cookie
                    pbxdata.bll.taoAppUserbll taoAppUserBll = new bll.taoAppUserbll();

                    #region
                    IDataParameter[] iparaTaoAppUser = new IDataParameter[] {
                        new SqlParameter("userId1", SqlDbType.Int, 4),
                    };
                    iparaTaoAppUser[0].Value = userMd.Id;

                    #endregion

                    List <pbxdata.model.taoAppUser> taoShopList = taoAppUserBll.GetModelList(iparaTaoAppUser, "taoAppUsersSelect");
                    StringBuilder taoNames      = new StringBuilder();
                    StringBuilder access_tokens = new StringBuilder();
                    foreach (pbxdata.model.taoAppUser t in taoShopList)
                    {
                        taoNames.Append(t.refreshToken + ",");
                        access_tokens.Append(t.accessToken + ",");
                    }

                    string TaoBaoNames = taoNames.ToString();
                    if (!string.IsNullOrEmpty(TaoBaoNames))
                    {
                        TaoBaoNames = TaoBaoNames.Substring(0, TaoBaoNames.Length - 1);
                    }
                    string AccessTokens = access_tokens.ToString();
                    if (!string.IsNullOrEmpty(AccessTokens))
                    {
                        AccessTokens = AccessTokens.Substring(0, AccessTokens.Length - 1);
                    }

                    HttpCookie cookie = new HttpCookie("userInfo");
                    cookie.Values["userName"]    = userMd.userName;
                    cookie.Values["ID"]          = userMd.Id.ToString();
                    cookie.Values["nick"]        = HttpUtility.UrlEncode(TaoBaoNames);
                    cookie.Values["accessToken"] = AccessTokens;


                    string[] st = new string[] { userMd.userName, userMd.Id.ToString(), HttpUtility.UrlEncode(TaoBaoNames), AccessTokens, userMd.personaId.ToString() };
                    Session["UserMsg"] = st;
                    Response.Cookies.Add(cookie);

                    this.Response.Clear();                       //这里是关键,清除在返回前已经设置好的标头信息,这样后面的跳转才不会报错
                    this.Response.BufferOutput = true;           //设置输出缓冲
                    if (!this.Response.IsRequestBeingRedirected) //在跳转之前做判断,防止重复
                    {
                        return(RedirectToAction("../Home/Index"));
                    }
                }
            }

            return(View());
        }