Esempio n. 1
0
        public ActionResult JoinAdminPost(string code)
        {
            if (MemoryCache.Get <string>("InvitationCode_" + code) == null)
            {
                return(ReturnJson(false, "邀请码不正确"));
            }

            if (MemberInfo.Role == (int)MemberRole.管理员)
            {
                return(ReturnJson(false, "您已经是管理员"));
            }


            MemberInfo.Role = (int)MemberRole.管理员;
            var b = new MemberInfoDal().Update(MemberInfo, "Role");

            if (b)
            {
                MemoryCache.Remove("InvitationCode_" + code);
                return(ReturnJson(true, "注册成功"));
            }
            else
            {
                return(ReturnJson(false, "注册失败请重试"));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 绑定用户
        /// </summary>
        /// <param name="wxuser"></param>

        private MemberInfo BindUser(WechatUserInfo wxuser)
        {
            var memberInfoDal = new MemberInfoDal();
            var memberInfo    = memberInfoDal.GetModel(string.Format("OpenId='{0}'", wxuser.OpenId));

            if (memberInfo == null)
            {
                memberInfo = new MemberInfo
                {
                    OpenId   = wxuser.OpenId,
                    NickName = wxuser.Nickname,
                    Role     = (int)MemberRole.顾客,
                    CreateOn = DateTime.Now.ToUnixStamp()
                };

                memberInfo.Uid = memberInfoDal.Add(memberInfo);
            }
            else
            {
                memberInfo.NickName = wxuser.Nickname;

                memberInfoDal.Update(memberInfo);
            }

            SetCookie(memberInfo);
            return(memberInfo);
        }
Esempio n. 3
0
        public void OnActionExecuting(ActionExecutingContext context)
        {
            ////非微信来源不执行微信授权步骤
            //if (!WxHelper.IsFromWx(context.HttpContext))
            //{
            //    context.Controller.ViewBag.isFromWx = false;
            //    context.Result = new ContentResult() { Content = "仅支持在微信端打开此页面" };
            //    return;
            //}

            //context.Controller.ViewBag.isFromWx = true;
            var request = context.HttpContext.Request;

            MemberInfo member = null;
            var        uid    = ConvertHelper.StrToInt(CookieHelper.GetCookie("weispaUser"));

            if (uid > 0)
            {
                member = new MemberInfoDal().GetModel(uid);
            }

            //已登录直接通过
            if (member != null)
            {
                return;
            }

            //post提交时验证登录状态,仅支持get请求授权
            if (!request.HttpMethod.Equals("GET", StringComparison.OrdinalIgnoreCase))
            {
                context.Result = new JsonResult()
                {
                    Data = new { Success = false, Info = "您未登录成功,请先刷新页面" }
                };
                return;
            }

            //跳转授权绑定页面
            var urlHelper   = ((Controller)context.Controller).Url;
            var url         = request.Url;
            var webrootPath = url.Scheme + "://" + url.Authority;
            var bindUrl     = webrootPath + urlHelper.Action("Login", "Account",
                                                             new { redirect = HttpUtility.UrlEncode(request.Url.ToString()) });

            context.Result = new RedirectResult(WxHelper.Oauth2AuthorizeUrl(bindUrl, 1, "clientAuthed"));
        }
Esempio n. 4
0
 public MemberInfoBll()
 {
     miDal = new MemberInfoDal();
 }