Exemple #1
0
        public ActionResult Register(string code = "")
        {
            InvitationCode invitationCode = new InvitationCode();
            //PublicUserModel loginUser = this.GetLoginUser();
            //if (loginUser != null && loginUser.UserID > 0)
            //{
            //    return Redirect("/Home");
            //}

            List <Regions> regionList = ncBase.CurrentEntities.Regions.Where(r => r.Layer == 1).ToList();

            ViewData["RegionList"] = regionList;

            if (ConfigUtility.GetBoolValue("InvitationRegister") || !string.IsNullOrEmpty(code))
            {
                invitationCode =
                    ncBase.CurrentEntities.InvitationCode.Where(o => o.Code == code && o.IsUsed == false)
                    .FirstOrDefault();
                if (invitationCode.IsNull())
                {
                    return(RedirectToAction("InvitationRegister", "User"));
                }
            }

            return(View(invitationCode));
        }
Exemple #2
0
        public ActionResult AddNewUser(string tel)
        {
            InvitationCode invitationCode = ncBase.CurrentEntities.InvitationCode.Where(o => o.BindTel == tel && o.IsUsed == false).FirstOrDefault();

            if (invitationCode.IsNull())
            {
                invitationCode            = new InvitationCode();
                invitationCode.Code       = StringUtility.GetSubfix();
                invitationCode.BindTel    = tel;
                invitationCode.Invitee    = "";
                invitationCode.IsUsed     = false;
                invitationCode.UsedTime   = Convert.ToDateTime("1900-1-1");
                invitationCode.CreateTime = DateTime.Now;
                invitationCode.VipType    = 2;
                ncBase.CurrentEntities.AddToInvitationCode(invitationCode);
                ncBase.CurrentEntities.SaveChanges();
            }
            ViewBag.Code = invitationCode.Code;
            return(View());
        }
Exemple #3
0
        public JsonResult DoRegister(PublicUserModel user, string code, string invitationCode)
        {
            bool isNeedCode = true;//是否需要手机短信验证码

            InvitationCode invitationEntity = new InvitationCode();

            #region 是否需要邀请码验证
            if (ConfigUtility.GetBoolValue("InvitationRegister") || !string.IsNullOrEmpty(invitationCode))
            {
                #region 判断 如果邀请码对应的手机号存在 则无需手机短信验证码 否则需要手机短信验证码

                invitationEntity = ncBase.CurrentEntities.InvitationCode.Where(i => i.Code == invitationCode && i.IsUsed == false).FirstOrDefault();
                if (invitationEntity.IsNull())
                {
                    return(Json(new { status = 1, msg = "邀请码不存在或已被使用" }));
                }
                user.VipType = (int)invitationEntity.VipType;
                if (!string.IsNullOrEmpty(invitationEntity.BindTel))
                {
                    user.Tel   = invitationEntity.BindTel; //邀请码有绑定手机号码,防止填入其他手机号码
                    isNeedCode = false;
                }
            }
            #endregion
            #endregion

            #region 表单验证
            if (string.IsNullOrEmpty(user.Tel))
            {
                return(Json(new { status = 1, msg = "手机号不能为空" }));
            }
            if (isNeedCode)
            {
                if (string.IsNullOrEmpty(code) || Session["Phone_Code" + user.Tel] == null || (code != "" && Session["Phone_Code" + user.Tel] != null && code != Session["Phone_Code" + user.Tel].ToString()))
                {
                    return(Json(new { status = 1, msg = "验证码错误" }));
                }
            }
            if (string.IsNullOrEmpty(user.Name))
            {
                return(Json(new { status = 1, msg = "用户名不能为空" }));
            }
            if (string.IsNullOrEmpty(user.Password) || (user.Password != null && user.Password.Length < 6))
            {
                return(Json(new { status = 1, msg = "密码至少6位数" }));
            }
            if (user.CityID <= 0)
            {
                return(Json(new { status = 1, msg = "所属城市必填" }));
            }
            if (user.CompanyId <= 0)
            {
                return(Json(new { status = 1, msg = "所属公司必填" }));
            }
            if (user.StoreId <= 0)
            {
                if (user.DistrictId <= 0 || user.RegionId <= 0)
                {
                    return(Json(new { status = 1, msg = "所属分店必填" }));
                }
            }
            #endregion
            user.IP          = Request.UserHostAddress;
            user.LastLoginIP = Request.UserHostAddress;
            user.VipType     = 0; //待审用户
            UserBll userBll = new UserBll();
            int     userid  = userBll.addPublicUser(user);
            if (userid == -1)
            {
                return(Json(new { status = 1, msg = "用户名已经存在" }));
            }
            else if (userid == -2)
            {
                return(Json(new { status = 1, msg = "手机号已被注册" }));
            }
            if (userid > 0)//自动登录
            {
                #region 邀请码状态更改
                if (ConfigUtility.GetBoolValue("InvitationRegister"))
                {
                    invitationEntity.IsUsed   = true;
                    invitationEntity.UsedTime = DateTime.Now;
                    invitationEntity.UsedUid  = userid;
                    ncBase.CurrentEntities.SaveChanges();
                }
                #endregion

                if (Session[user.Tel] != null)
                {
                    Session[user.Tel] = null;
                    Session.Remove(user.Tel);
                }
                PublicUserModel newUser = userBll.PublicUserLogin(user.Name, user.Password);
                String          saveKey = System.Configuration.ConfigurationManager.AppSettings["AuthSaveKey"];
                if (String.IsNullOrEmpty(saveKey))
                {
                    saveKey = "WXLoginedUser";
                }
                Session[saveKey] = newUser;
                HttpCookie loginUserCookie = new HttpCookie(saveKey, CryptoUtility.TripleDESEncrypt(newUser.UserID.ToString()));
                loginUserCookie.Expires = DateTime.Now.AddDays(10);
                HttpContext.Response.Cookies.Add(loginUserCookie);
            }
            return(Json(new { status = 0, msg = "注册成功" }));
        }