예제 #1
0
        public ActionResult Register(Vip vip, string verifyCode)
        {
            ViewBag.Title = "注册";

            if (string.IsNullOrEmpty(vip.MobileNo) || string.IsNullOrEmpty(vip.Password) || string.IsNullOrEmpty(vip.VipName))
            {
                ViewBag.Error = "请完善资料";
                return(View());
            }
            //验证手机号是否存在
            var isCheck = _dal.GetByMobile(vip.MobileNo);

            if (isCheck != null)
            {
                ViewBag.Error = "手机号已存在";
                return(View());
            }

            //验证身份证
            var user = _dal.GetByCardNo(vip.CardNo);

            if (user != null)
            {
                ViewBag.Error = "身份证号已存在";
                return(View());
            }

            //验证码
            if (Session["VerCode"] == null || Session["PhoneNo"] == null || Session["VerCode"].ToString() != verifyCode || Session["PhoneNo"].ToString() != vip.MobileNo)
            {
                ViewBag.Error = "验证码不正确";
                return(View());
            }

            var token = AccessTokenContainer.TryGetAccessToken(AppConfig.Instance.AppId, AppConfig.Instance.AppSecret);

            if (!string.IsNullOrEmpty(vip.CardImg))
            {
                var fileName = $"/upload/cardimg/{Guid.NewGuid().ToString("N")}.jpg";
                Senparc.Weixin.MP.AdvancedAPIs.MediaApi.Get(token, vip.CardImg, Server.MapPath("~" + fileName));

                vip.CardImg = fileName;
            }

            //添加用户
            vip.CreatedBy   = "system";
            vip.CreatedTime = DateTime.Now;
            vip.UpdatedBy   = "system";
            vip.UpdatedTime = DateTime.Now;
            vip.ImgPath     = "/assets/web/images/i_03.png";

            _dal.Insert(vip);

            OAuthHelper.DoOAuth(HttpContext, vip.MobileNo);

            return(new EmptyResult());
        }
예제 #2
0
        public ActionResult Login(string mobile, string password)
        {
            ViewBag.Title = "登录";

            if (string.IsNullOrEmpty(mobile) || string.IsNullOrEmpty(password))
            {
                ViewBag.Error = "手机号或密码为空";
                return(View());
            }
            var user = _dal.GetByMobile(mobile);

            if (user == null || user.Password != password)
            {
                ViewBag.Error = "手机号或密码错误";
                return(View());
            }


            if (string.IsNullOrEmpty(user.WeChatId))
            {
                OAuthHelper.DoOAuth(HttpContext, mobile);
                return(new EmptyResult());
            }

            var userInfo = new CurrentVipModel
            {
                VipId  = user.Id,
                OpenId = user.WeChatId,
                pwd    = EncryptHelper.Md5(password)
            };

            SetAuthCookie(userInfo);

            HttpContext.Items["CurrentVip"] = userInfo;
            return(RedirectToAction("Index", "User"));
        }