Exemple #1
0
        public ActionResult MemberBind()
        {
            var openId = CookieUtil.Get("OpenId");

#if DEBUG
            openId = Guid.NewGuid().ToString().Replace("-", "");
            openId = "30";
            //登录成功
            var response = CustomerApp.Instance.OpenIdLogin(new LoginRequest()
            {
                OpenId = openId
            });
            if (response.Status)
            {
                return(RedirectToAction("Index", "Me"));
            }
            CookieUtil.SetCookie("OpenId", openId);
#endif
            //openId = Guid.NewGuid().ToString().Replace("-", "");
            CookieUtil.SetCookie("OpenId", openId);
            ViewBag.openId = openId;

            ViewBag.returnUrl = "/me/index";
            return(View());
        }
        /// <summary>
        /// OAuthScope.snsapi_userinfo方式回调
        /// </summary>
        /// <param name="code"></param>
        /// <param name="state"></param>
        /// <returns>视图</returns>
        public ActionResult Index(string code, string state)
        {
            Log4Helper.WriteInfoLog("账号:" + code, "Oauth2");

            if (string.IsNullOrEmpty(code))
            {
                return(Content("您拒绝了授权!"));
            }
            if (string.IsNullOrEmpty(state))
            {
                return(Content("验证失败!请从正规途径进入!"));
            }
            var result = OAuthApi.GetAccessToken(appKey, appSecret, code);

            if (result.errcode != ReturnCode.请求成功)
            {
                return(Content("错误:" + result.errmsg));
            }

            try
            {
                //因为这里还不确定用户是否关注本微信,所以只能试探性地获取一下
                var userInfo = OAuthApi.GetUserInfo(result.access_token, result.openid);
                if (userInfo != null)
                {
                    //用户信息
                    var openId     = userInfo.openid;
                    var nickname   = userInfo.nickname;
                    var headimgurl = userInfo.headimgurl;
                    //保存用户信息
                    CookieUtil.SetCookie("OpenId", openId);
                    CookieUtil.SetCookie("HeadImgUrl", headimgurl);
                    CookieUtil.SetCookie("Nickname", nickname);

                    Log4Helper.WriteInfoLog(string.Format("OpenId:{0}", userInfo.ToJson2()), "Login");

                    var url = "http://app.1000n.com/me/vip";

                    return(Redirect(url));
                }
                else
                {
                    return(Content("用户已授权,获取UserInfo失败"));
                }
            }
            catch (ErrorJsonResultException ex)
            {
                return(Content("用户已授权,授权Token:" + result));
            }
        }
Exemple #3
0
 /// <summary>
 /// 设置当前用户ID
 /// </summary>
 /// <param name="userID"></param>
 public static void SetCurrentUserID(int userID)
 {
     if (userID <= 0)
     {
         return;
     }
     ExceptionUtil.LogException(() =>
     {
         var encodeString = DESProviderUtil.Encode(userID.ToString(), GetCurrentUserSignKey);
         CookieUtil.SetCookie(_CurrentUserID_Key, encodeString);
         string cookieSign = (encodeString + GetCurrentUserCookieSignKey).ToMd5();
         CookieUtil.SetCookie(_CurrentUserCookieSign_Key, cookieSign);
     }, memberName: "PublicUtil-SetCurrentUserID");
 }
Exemple #4
0
        /// <summary>
        /// 用户登录
        /// 添加人:周 鹏
        /// 添加时间:2014-01-03
        /// </summary>
        /// <param name="loginName">登录名</param>
        /// <param name="passWord">密码</param>
        /// <param name="remberPwd">保存登录账号密码</param>
        /// <param name="decodePassWord">是否对密码进行加密</param>
        /// <param name="createPersistentCookie">是否永久保存</param>
        /// <returns></returns>
        public UserLoginStatus UserLogin(string loginName, string passWord, string remberPwd, bool decodePassWord = true, bool createPersistentCookie = false)
        {
            var user            = new CrmUserBll().GetUserEntity(loginName, "Account");
            var loginErrorCount = new ComLoginLogBll().GetLoginErrorCount(loginName);

            if (loginErrorCount >= 5)
            {
                return(UserLoginStatus.TemporaryLocked);
            }
            if (user != null && !string.IsNullOrEmpty(user.Id))
            {
                passWord = DESHelper.ToDESEncrypt(passWord, AppConst.EncryptKey);  //将密码进行加密
                if (!user.Password.Equals(passWord))
                {
                    return(UserLoginStatus.PasswordError);
                }

                if (!string.IsNullOrEmpty(remberPwd) && remberPwd.Equals("checked"))
                {
                    //验证通过,设置Cookie信息
                    CookieUtil.SetCookie(AppConst.LoginUserNameCookieName,
                                         createPersistentCookie ? HttpUtility.UrlEncode(user.Account) : "",
                                         DateTime.MaxValue);
                    //验证通过,设置Cookie信息
                    CookieUtil.SetCookie(AppConst.LoginUserCookiePwd,
                                         createPersistentCookie ? HttpUtility.UrlEncode(user.Password) : "",
                                         DateTime.MaxValue);
                }
                else
                {
                    CookieUtil.Remove(AppConst.LoginUserNameCookieName);
                    CookieUtil.Remove(AppConst.LoginUserCookiePwd);
                }

                var ticket    = new FormsAuthenticationTicket(1, user.Id, DateTime.Now, DateTime.Now.AddDays(1), false, "");
                var strTicket = FormsAuthentication.Encrypt(ticket);
                var cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, strTicket);
                HttpContext.Current.Response.Cookies.Add(cookie);
                return(UserLoginStatus.Sucess);
            }
            return(UserLoginStatus.NotUser);
        }
Exemple #5
0
        /// <summary>
        /// [Cookie]设置产品浏览记录(写入Cookie)
        /// </summary>
        /// <param name="productSysNo">产品Id</param>
        /// <param name="productName">产品名称</param>
        /// <param name="count">浏览记录总数</param>
        /// <returns></returns>
        /// <remarks>
        /// 2013-03-18 吴文强 创建
        /// 2013-08-08 邵  斌 迁移,添加商品图片路径到cooki
        /// </remarks>
        public void SetHistoryLook(int productSysNo, string productName, int count, string productImage = null)
        {
            //清除名字中包含的@和;
            productName = productName.Replace("@", " ").Replace(";", " ");
            //新加入的产品(产品Id@产品名称)
            var value = string.Format("{0}@{1}@{2}", productSysNo, productName.Trim(), productImage);
            //历史产品
            var hostory = CookieUtil.Get(COOKIE_HISTORYLOOK);
            //新构造的产品集合(产品Id@产品名称),新添加的记录写入最后
            var listHostory = hostory.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            listHostory = listHostory.Where(
                s => s.Split(new[] { "@" }, StringSplitOptions.RemoveEmptyEntries)[0] != productSysNo.ToString()).ToList();
            if (listHostory.Count >= count)
            {
                listHostory.RemoveAt(0);
            }
            listHostory.Add(value);
            CookieUtil.SetCookie(COOKIE_HISTORYLOOK, string.Join(";", listHostory), DateTime.Now.AddYears(1));
        }
Exemple #6
0
        //
        // POST: /Home/SwitchTheme
        public JsonResult SwitchTheme(string uItheme)
        {
            try
            {
                //设置Cookie信息
                CookieUtil.SetCookie(AppConst.Uitheme, uItheme, DateTime.MaxValue);
                var rtEntity = new StatusModel <TreeMenuNode>
                {
                    rtData  = null,
                    rtMsrg  = "成功",
                    rtState = 0
                };

                var json = Json(rtEntity, JsonRequestBehavior.AllowGet);
                return(json);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemple #7
0
        public ActionResult Register()
        {
            var openId = CookieUtil.Get("OpenId");

#if DEBUG
            openId = "openId002";
            CookieUtil.SetCookie("OpenId", openId);
#endif
            ViewBag.openId = openId;

            ViewBag.returnUrl = "/me/index";
            //注册支付类型
            ViewBag.RegisterPayType = EnumUtil.ToDictionary(typeof(CustomerEnum.RegisterPayType));

            var recommend = RecommendApp.Instance.GetByopenId(openId);
            if (recommend != null)
            {
                var customer = CustomerApp.Instance.Get(recommend.ReferrerSysNo);
                return(View(customer));
            }
            return(View(new CrCustomer()
            {
            }));
        }
Exemple #8
0
        /// <summary>
        /// OAuthScope.snsapi_userinfo方式回调
        /// </summary>
        /// <param name="code"></param>
        /// <param name="state"></param>
        /// <returns>视图</returns>
        public ActionResult Index(string code, string state)
        {
            if (string.IsNullOrEmpty(code))
            {
                return(Content("您拒绝了授权!"));
            }
            if (string.IsNullOrEmpty(state))
            {
                return(Content("验证失败!请从正规途径进入!"));
            }
            var result = OAuthApi.GetAccessToken(appKey, appSecret, code);

            if (result.errcode != ReturnCode.请求成功)
            {
                return(Content("错误:" + result.errmsg));
            }
            try
            {
                //因为这里还不确定用户是否关注本微信,所以只能试探性地获取一下
                var userInfo = OAuthApi.GetUserInfo(result.access_token, result.openid);
                if (userInfo != null)
                {
                    //用户信息
                    var openId     = userInfo.openid;
                    var nickname   = userInfo.nickname;
                    var headimgurl = userInfo.headimgurl;
                    //保存用户信息
                    CookieUtil.SetCookie("OpenId", openId);
                    CookieUtil.SetCookie("HeadImgUrl", headimgurl);
                    CookieUtil.SetCookie("Nickname", nickname);

                    var customerExt = CustomerApp.Instance.GetByOpenId(openId);

                    Log4Helper.WriteInfoLog(string.Format("OpenId:{0}", openId), "Login");
                    Log4Helper.WriteInfoLog(string.Format("会员对象:{0}", customerExt.ToJson2()), "Login");
                    if (customerExt == null)
                    {
                        return(RedirectToAction("Register", "Account"));
                    }
                    else
                    {
                        //登录成功
                        var response = CustomerApp.Instance.OpenIdLogin(new LoginRequest()
                        {
                            OpenId = openId
                        });

                        Log4Helper.WriteInfoLog(string.Format("登录成功:{0}", response.ToJson()), "Login");

                        if (response.Status)
                        {
                            return(RedirectToAction("Index", "Me"));
                        }
                        else
                        {
                            return(RedirectToAction("MemberBind", "Account"));
                        }
                    }
                }
                else
                {
                    return(Content("用户已授权,获取UserInfo失败"));
                }
            }
            catch (ErrorJsonResultException ex)
            {
                return(Content("用户已授权,授权Token:" + result));
            }
        }
Exemple #9
0
 /// <summary>
 /// [Cookie]清除产品浏览记录
 /// </summary>
 /// <returns></returns>
 /// <remarks>
 /// 2013-03-18 吴文强 创建
 /// 2013-08-08 邵  斌 迁移
 /// </remarks>
 public void ClearHistoryLook()
 {
     CookieUtil.SetCookie(COOKIE_HISTORYLOOK, string.Empty);
 }