Esempio n. 1
0
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="request"></param>
        public ApiResult <LoginResDto> UserRegister(RegisterReqDto dto, HttpRequestMessage request)
        {
            string password = Tool.GetMD5(dto.Password);
            string ip       = Tool.GetIP();
            string regsql   = @"
  insert into UserInfo(UserName, Name, Password, Mobile, Coin, Money, Integral, SubTime, LastLoginTime, State,Pid,RegisterIP)
  values(@UserName, @Name, @Password, @Mobile, 0,0, 0, getdate(), getdate(), 0,@Pid,@RegisterIP);select @@identity ";

            SqlParameter[] regsp = new SqlParameter[]
            {
                new SqlParameter("@UserName", dto.Phone),
                new SqlParameter("@Name", dto.NickName),
                new SqlParameter("@Password", password),
                new SqlParameter("@Mobile", dto.Phone),
                new SqlParameter("@Pid", dto.InviteCode.HasValue ? dto.InviteCode.Value : 0),
                new SqlParameter("@RegisterIP", ip)
            };

            object obj = SqlHelper.ExecuteScalar(regsql, regsp);

            if (obj == null)
            {
                throw new ApiException(50000, "注册失败,请重试");
            }

            int userId = Convert.ToInt32(obj);

            var      couponModel = GetCoupon("A0001");
            DateTime beginTime   = DateTime.Now;
            DateTime endTime     = DateTime.Now.AddDays(couponModel.ExpiryDate);

            #region 注册时,添加一张查看卷
            UserCoupon uc = new UserCoupon();
            uc.UserId     = userId;
            uc.CouponCode = "A0001";
            uc.PlanId     = 0;
            uc.BeginTime  = beginTime;
            uc.EndTime    = endTime;
            uc.FromType   = 1;
            uc.State      = 1;
            AddUserCoupon(uc);
            #endregion

            //TODO:事务优化处理
            #region 发放邀请注册奖励
            if (dto.InviteCode.HasValue)
            {
                try
                {
                    var inviteUser = GetUserInfo(dto.InviteCode.Value);
                    if (inviteUser != null)
                    {
                        //受邀奖励
                        int myReward = GetRadomReward(3);
                        AddCoinReward(userId, inviteUser.Id.ToString(), 6, myReward, 1);
                        //邀请奖励
                        int upReward = GetRadomReward(1);
                        AddCoinReward((int)inviteUser.Id, userId.ToString(), 7, upReward, 1);
                        //添加邀请任务记录
                        AddUserTask((int)dto.InviteCode.Value, 105);

                        //上级的上级奖励
                        if (inviteUser.Pid.HasValue && inviteUser.Pid > 0)
                        {
                            var superUser = GetUserInfo(inviteUser.Pid.Value);

                            if (superUser != null)
                            {
                                int superReward = GetRadomReward(2);
                                AddCoinReward((int)superUser.Id, inviteUser.Id.ToString(), 7, superReward, userId);
                            }
                        }

                        #region 邀请注册时,邀请人添加一张查看卷
                        UserCoupon uc1 = new UserCoupon();
                        uc1.UserId     = (int)inviteUser.Id;
                        uc1.CouponCode = "A0001";
                        uc1.PlanId     = 0;
                        uc1.BeginTime  = beginTime;
                        uc1.EndTime    = endTime;
                        uc1.FromType   = 2;
                        uc1.State      = 1;
                        AddUserCoupon(uc1);
                        #endregion
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error("发放邀请注册奖励异常", ex);
                }
            }
            #endregion

            #region  发登录token
            string       webHost  = ConfigurationManager.AppSettings["webHost"];
            string       avater   = string.Format("{0}/images/default_avater.png", webHost);
            IdentityInfo authInfo = new IdentityInfo()
            {
                UserId      = userId,
                UserAccount = dto.Phone,
                UserStatus  = 0,
                UserName    = dto.NickName,
                IsTemp      = false,
                Avater      = avater
            };

            var tokenAuth = new QiuxunTokenAuthorizer(new ApiAuthContainer(request));
            tokenAuth.Authorize(authInfo);

            #endregion

            LoginResDto resDto = new LoginResDto()
            {
                Account  = dto.Phone,
                Avater   = avater,
                UserId   = userId,
                Mobile   = dto.Phone,
                NickName = dto.NickName
            };

            return(new ApiResult <LoginResDto>()
            {
                Data = resDto
            });
        }
Esempio n. 2
0
        public ApiResult <LoginResDto> Login(LoginReqDto reqDto, HttpRequestMessage request)
        {
            UserInfoService service     = new UserInfoService();
            UserInfo        accountInfo = service.GetFullUserInfoByMobile(reqDto.Account);

            if (accountInfo == null)
            {
                throw new ApiException(15023, "用户名不存在或密码错误");
            }

            if (accountInfo.Password.StartsWith("$2y"))
            {
                if (!Crypter.CheckPassword(reqDto.Password, accountInfo.Password))
                {
                    throw new ApiException(15023, "用户名不存在或密码错误");
                }
            }
            else
            {
                if (Tool.GetMD5(reqDto.Password) != accountInfo.Password)
                {
                    throw new ApiException(15023, "用户名不存在或密码错误");
                }
            }

            string webHost = ConfigurationManager.AppSettings["webHost"];
            string avater  = string.IsNullOrWhiteSpace(accountInfo.Avater)
                ? string.Format("{0}/images/default_avater.png", webHost)
                : accountInfo.Avater;

            LoginResDto resDto = new LoginResDto()
            {
                Account  = accountInfo.Mobile,
                Avater   = avater,
                UserId   = accountInfo.Id,
                Mobile   = accountInfo.Mobile,
                NickName = accountInfo.NickName
            };

            #region  发登录token

            IdentityInfo authInfo = new IdentityInfo()
            {
                UserId      = accountInfo.Id,
                UserAccount = accountInfo.Mobile,
                UserStatus  = (int)accountInfo.State,
                UserName    = accountInfo.NickName,
                IsTemp      = false,
                Avater      = avater
            };

            var tokenAuth = new QiuxunTokenAuthorizer(new ApiAuthContainer(request));
            tokenAuth.Authorize(authInfo);

            #endregion

            return(new ApiResult <LoginResDto>()
            {
                Data = resDto
            });
        }