Example #1
0
        /// <summary>
        /// 完善手机
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public ActionResult PostMobile(string mobile, string code)
        {
            if (!MyRegex.IsPhone(mobile))
            {
                return(JsonResult(APIErrCode.PhoneFormatError, "手机格式错误"));
            }

            var authenticationUser = BLLAuthentication.GetAuthenticationUser();
            var obj = new XCache().Get("Code" + authenticationUser.openid);//写入缓存

            if (obj == null)
            {
                return(JsonResult(APIErrCode.CheckCodeErr, "验证码已过期"));
            }
            if (obj.ToString().ToUpper() != code.Trim().ToUpper())
            {
                return(JsonResult(APIErrCode.CheckCodeErr, "验证码错误"));
            }
            ht_user user = BLLUser.GetUserByOpenid(authenticationUser.openid);

            if (user == null)
            {
                user          = new ht_user();
                user.addtime  = DateTime.Now;
                user.username = user.openid;
                user.openid   = authenticationUser.openid;
                user.salt     = Utils.GetSalt();
                user.password = EncryptUtil.DesEncrypt("123456", user.salt);
                user.points   = 0;
                user.money    = 0;
                if (authenticationUser.parent_id.HasValue)
                {
                    user.parent_id = authenticationUser.parent_id;
                    ht_user parentUser = BLLUser.GetUserById(authenticationUser.parent_id.Value);
                    if (parentUser != null && parentUser.parent_id.HasValue)
                    {
                        user.pparent_id = parentUser.parent_id;
                    }
                }
            }
            user.mobile   = mobile;
            user.avatar   = authenticationUser.avatar;
            user.nickname = authenticationUser.nickname;
            if (BLLUser.PostUser(user) > 0)
            {
                BLLAuthentication.LoginAuthenticationTicket(user);
                return(JsonResult(APIErrCode.Success, "提交成功"));
            }
            return(JsonResult(APIErrCode.CheckCodeErr, "提交失败"));
        }