Beispiel #1
0
        /// <summary>
        /// 判断邀请码是否存在,如果是新注册用户,userid为0
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static bool IsExsitRecommendCode(string code, int userid)
        {
            bool flag = false;

            if (!string.IsNullOrWhiteSpace(code))
            {
                string sourcechars    = ConfigurationManager.AppSettings["sourcechars"];
                string newsourcechars = ConfigurationManager.AppSettings["newsourcechars"];
                code = BaseConvertHelper.BaseConvert(code, newsourcechars, sourcechars);
                flag = new MemberDao().IsExsitRecommendCode(code, userid);
            }

            return(flag);
        }
Beispiel #2
0
        /// <summary>
        /// 获取邀请码
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public static string GetRecemmendCode(int userid)
        {
            // 判断是否有邀请码,没有就给与,有就用原来的
            int    code           = MemberHelper.GetRecommendCodeByUserId(userid);
            string sourcechars    = ConfigurationManager.AppSettings["sourcechars"];
            string newsourcechars = ConfigurationManager.AppSettings["newsourcechars"];

            ErrorLog.Write("code" + code);
            if (code < 50000) // 没有生成新的邀请码
            {
                string currcode = MemberHelper.AddRecommendCodeByUserId(userid);
                if (!string.IsNullOrWhiteSpace(currcode))
                {
                    return(BaseConvertHelper.BaseConvert(currcode, sourcechars, newsourcechars));
                }
            }
            else
            {
                return(BaseConvertHelper.BaseConvert(code.ToString(), sourcechars, newsourcechars));
            }
            return(string.Empty);
        }
Beispiel #3
0
        public IHttpActionResult Register(JObject request)
        {
            Logger.WriterLogger("Account.Register, Params: " + request.ToString(), LoggerType.Info);

            ParamRegister param = new ParamRegister();

            try
            {
                param = request.ToObject <ParamRegister>();
            }
            catch
            {
                //throw new CommonException(40100);
                return(base.JsonFaultResult(new CommonException(40100).GetMessage(), request.ToString()));
            }

            string accessToken   = param.accessToken;
            string sessionKey    = "";
            string sessionSecret = "";

            // 验证令牌
            int accessTookenCode = VerifyAccessToken(accessToken, out sessionKey, out sessionSecret);

            if (accessTookenCode > 0)
            {
                return(base.JsonFaultResult(new CommonException(accessTookenCode).GetMessage(), request.ToString()));
            }

            string username = param.username;
            string code     = param.code;

            string password    = param.password;
            int    accountType = param.accountType;

            int    channel  = param.channel;
            int    platform = param.platform;
            string ver      = param.ver;

            // 保存访问信息
            base.SaveVisitInfo("", channel, platform, ver);

            string decryptUsername = username;
            string decryptPassword = password;
            string decryptCode     = code;

            if ((platform == 3 && base.AndroidIsEncryption) || (platform == 2 && base.IOSIsEncryption) || (platform == 1 && base.PCIsEncryption))
            {
                decryptUsername = base.Decrypt(username, sessionKey, sessionSecret);      //TODO 解密
                decryptPassword = base.Decrypt(password, sessionKey, sessionSecret);

                //decryptCode = base.Decrypt(code, sessionKey, sessionSecret);
            }

            string email  = "";
            string mobile = "";

            switch (accountType)
            {
            case 1:
                break;

            case 2:
                mobile = decryptUsername;
                //email = decryptUsername + "@mail.haimylife.com";

                if (string.IsNullOrEmpty(decryptUsername))
                {
                    return(base.JsonFaultResult(new FaultInfo(40100, "手机号码为空"), request.ToString()));
                }
                if (!System.Text.RegularExpressions.Regex.IsMatch(decryptUsername, "^(13|14|15|17|18)\\d{9}$"))
                {
                    return(base.JsonFaultResult(new FaultInfo(40100, "请输入正确的手机号码"), request.ToString()));
                }
                if (UserHelper.IsExistCellPhoneAndUserName(decryptUsername) > 0)
                {
                    return(base.JsonFaultResult(new FaultInfo(40100, "已经存在相同的手机号码"), request.ToString()));
                }

                Verify verifyto = new TelVerifyDao().GetVerify(decryptUsername, 1);
                if (!(verifyto != null && verifyto.VerifyCode == decryptCode))
                {
                    return(base.JsonFaultResult(new CommonException(40205).GetMessage(), request.ToString()));
                }
                break;

            case 3:
                email = decryptUsername;
                break;
            }

            string msg = "";

            int provinceId = 0;
            int userId     = 0;

            string sessionId = Guid.NewGuid().ToString();

            if (string.IsNullOrEmpty(decryptUsername) || string.IsNullOrEmpty(decryptPassword))
            {
                return(base.JsonFaultResult(new FaultInfo(40200, "缺少必填参数"), request.ToString()));
            }

            //注册类型为3时检测邮箱
            if (accountType == 3)
            {
                if (string.IsNullOrEmpty(email.Trim()))
                {
                    return(base.JsonFaultResult(new FaultInfo(40200, "邮箱帐号不能为空"), request.ToString()));
                }
                if (email.Length > 256 || !System.Text.RegularExpressions.Regex.IsMatch(email, "([a-zA-Z\\.0-9_-])+@([a-zA-Z0-9_-])+((\\.[a-zA-Z0-9_-]{2,4}){1,2})"))
                {
                    return(base.JsonFaultResult(new FaultInfo(40200, "错误的邮箱帐号"), request.ToString()));
                }
            }

            //判断邀请码是否存在
            if (!string.IsNullOrWhiteSpace(param.recemmendCode))
            {
                if (!MemberHelper.IsExsitRecommendCode(param.recemmendCode.Trim(), 0))
                {
                    return(base.JsonFaultResult(new FaultInfo(40100, "邀请码错误,请填写正确的邀请码或者选择不填"), request.ToString()));
                }
            }

            Member member = new Member(UserRole.Member);

            member.GradeId   = MemberProcessor.GetDefaultMemberGrade();
            member.SessionId = Globals.GetGenerateId();
            member.Username  = decryptUsername;

            member.Password                 = decryptPassword;
            member.PasswordFormat           = System.Web.Security.MembershipPasswordFormat.Hashed;
            member.TradePasswordFormat      = System.Web.Security.MembershipPasswordFormat.Hashed;
            member.TradePassword            = decryptPassword;
            member.IsApproved               = true;
            member.RealName                 = string.Empty;
            member.Address                  = string.Empty;
            member.MembershipUser.SessionId = sessionId;
            member.CellPhone                = mobile;
            member.CreateDate               = DateTime.Now;

            //member.MembershipUser.MobilePIN = mobile;
            // 手机注册默认验证手机号码
            if (accountType == 2)
            {
                member.CellPhoneVerification = true;
            }

            if (accountType == 3)
            {
                member.Email = email;
            }

            member.UserType = this.CovertToUserType(param.platform);

            CreateUserStatus createUserStatus = MemberProcessor.CreateMember(member);

            if (createUserStatus == CreateUserStatus.DuplicateUsername || createUserStatus == CreateUserStatus.DisallowedUsername)
            {
                msg = "已经存在该用户名";
            }
            if (createUserStatus == CreateUserStatus.DuplicateEmailAddress)
            {
                msg = "已经存在相同的邮箱";
            }
            if (createUserStatus == CreateUserStatus.DuplicateCellphone)
            {
                msg = "已经存在相同的手机号码";
            }

            if (createUserStatus == CreateUserStatus.Created)
            {
                Messenger.UserRegister(member, decryptPassword);
                member.OnRegister(new UserEventArgs(member.Username, decryptPassword, null));

                long timestamp = long.Parse(DateTime.Now.AddSeconds(USER_CACHE_KEEP_TIME).ToString("yyyyMMddHHmmss"));

                string authenTicket = SecurityUtil.MD5Encrypt(sessionId + timestamp.ToString() + sessionSecret).ToLower();
                string authenUserId = sessionId.ToLowerGuid();

                CacheUserSet(authenUserId, authenTicket, timestamp, member.UserId);

                #region ==判断是否有优惠卷
                if (!MemberHelper.NewUserSendRegisterCoupon(member))
                {
                    msg = "注册优惠卷赠送失败";
                    return(base.JsonFaultResult(new FaultInfo(40200, msg), request.ToString()));
                }
                #endregion
                #region == 判断是否有邀请码
                string sourcechars    = ConfigurationManager.AppSettings["sourcechars"];
                string newsourcechars = ConfigurationManager.AppSettings["newsourcechars"];
                string rcode          = param.recemmendCode;
                if (!string.IsNullOrWhiteSpace(rcode))
                {
                    string currcode = BaseConvertHelper.BaseConvert(rcode, newsourcechars, sourcechars);
                    string useredId = MemberHelper.GetUserIdByRecommendCode(currcode);
                    if (!string.IsNullOrWhiteSpace(useredId) && !string.IsNullOrWhiteSpace(currcode))
                    {
                        // 插入到邀请码记录表
                        MemberHelper.AddRecommendCodeRecord(member.UserId, Convert.ToInt32(useredId), currcode, rcode);
                    }
                }
                #endregion
                StandardResult <RegisterOrLoginResult> okResult = new StandardResult <RegisterOrLoginResult>();
                okResult.code = 0;
                okResult.msg  = "注册成功,恭喜您,50元现金券已经打到您的海美账户了,现在就去购物吧!";
                okResult.data = new RegisterOrLoginResult()
                {
                    DisplayName  = decryptUsername,
                    AuthenTicket = authenTicket,
                    AuthenUserId = authenUserId,
                    Timestamp    = timestamp
                };

                return(base.JsonActionResult(okResult));
            }
            else
            {
                msg = "注册用户失败," + msg;
            }

            return(base.JsonFaultResult(new FaultInfo(40200, msg), request.ToString()));
        }
Beispiel #4
0
        public static bool UpdateUserNameCoupon(Member member, string recemmendCode, out bool IsSendCoupon)
        {
            IsSendCoupon = false;
            bool     flag     = false;
            Database database = DatabaseFactory.CreateDatabase();

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    // 判断是否有邀请码
                    if (!string.IsNullOrWhiteSpace(recemmendCode))
                    {
                        string sourcechars    = ConfigurationManager.AppSettings["sourcechars"];
                        string newsourcechars = ConfigurationManager.AppSettings["newsourcechars"];
                        if (!string.IsNullOrWhiteSpace(sourcechars) && !string.IsNullOrWhiteSpace(newsourcechars))
                        {
                            string currcode = BaseConvertHelper.BaseConvert(recemmendCode, newsourcechars, sourcechars);
                            string useredId = MemberHelper.GetUserIdByRecommendCode(currcode);
                            if (!string.IsNullOrWhiteSpace(useredId) && !string.IsNullOrWhiteSpace(currcode))
                            {
                                // 插入到邀请码记录表
                                if (!MemberHelper.AddRecommendCodeRecord(member.UserId, Convert.ToInt32(useredId), currcode, recemmendCode))
                                {
                                    dbTransaction.Rollback();
                                    flag = false;
                                    return(flag);
                                }
                            }
                        }
                    }
                    bool CouponFlag = true;
                    // 判断该手机号码是否有openid
                    if (!UserHelper.IsExistOpendByUserName(member.Username))
                    {
                        CouponFlag = false;
                    }
                    //if (Users.UpdateUser(member))
                    if (!UserHelper.UpdateUserUserNameByCellPhone(member.UserId, member.Username, member.CellPhone, member.Password, member.OpenId, 1, UserHelper.CreateSalt()))
                    {
                        dbTransaction.Rollback();
                        flag = false;
                        return(flag);
                    }
                    if (CouponFlag)
                    {
                        // 判断是否有优惠卷
                        int count = CouponHelper.GetCountCouponItemed(member.UserId, 5);
                        if (count == 0)
                        {
                            // 获取有效时间内注册赠劵的数量
                            IList <CouponInfo>     couponList     = CouponHelper.GetCouponsBySendType(5);
                            IList <CouponItemInfo> couponItemList = new List <CouponItemInfo>();
                            string claimCode = string.Empty;
                            if (couponList != null && couponList.Count > 0)
                            {
                                foreach (CouponInfo coupon in couponList)
                                {
                                    CouponItemInfo item = new CouponItemInfo();
                                    claimCode = System.Guid.NewGuid().ToString().Replace("-", "").Substring(0, 15);

                                    if (coupon.Validity > 0 && member.CreateDate >= coupon.StartTime)
                                    {
                                        coupon.StartTime   = member.CreateDate;
                                        coupon.ClosingTime = member.CreateDate.AddDays(coupon.Validity);
                                    }
                                    else if (coupon.Validity > 0 && member.CreateDate < coupon.StartTime)
                                    {
                                        coupon.StartTime   = DateTime.Now;
                                        coupon.ClosingTime = DateTime.Now.AddDays(coupon.Validity);
                                    }
                                    item = new CouponItemInfo(coupon.CouponId, claimCode, new int?(member.UserId), member.Username, member.Email, System.DateTime.Now, coupon.StartTime.Date, coupon.ClosingTime.Date.AddDays(1).AddSeconds(-1), coupon.Amount, coupon.DiscountValue);
                                    couponItemList.Add(item);
                                }
                            }
                            if (couponItemList.Count > 0)
                            {
                                // 发劵
                                if (!CouponHelper.SendClaimCodes(couponItemList))
                                {
                                    dbTransaction.Rollback();
                                    flag = false;
                                    return(flag);
                                }
                                else
                                {
                                    IsSendCoupon = true;
                                }
                            }
                        }
                    }
                    dbTransaction.Commit();
                    flag = true;
                }
                catch
                {
                    dbTransaction.Rollback();
                    flag = false;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(flag);
        }