Esempio n. 1
0
    public Profile GetProfile(int id)
    {
        var profile = GetProfileQuery <Profile> .Execute(new { Id = id });

        Connector connector = new Connector(credentialManager.PublicKey, credentialManager.PrivateKey);

        profile.Hash = connector.Call("getProfileHash", id);

        return(profile);
    }
Esempio n. 2
0
        public void GivenProfileDoesNotExist_ThrowsNotFoundException()
        {
            var query = new GetProfileQuery
            {
                Username = "******",
            };

            async Task Handler() => await SendAsync(query);

            Assert.ThrowsAsync(typeof(NotFoundException), Handler);
        }
        public async Task <IActionResult> GetProfile(string username)
        {
            var query = new GetProfileQuery
            {
                Username = username,
            };

            var response = await Mediator.Send(query);

            return(Ok(response));
        }
Esempio n. 4
0
        public async Task <ResultWrapper <GetProfileOutput> > Handle(GetProfileQuery request, CancellationToken cancellationToken)
        {
            ResultWrapper <GetProfileOutput> result = new ResultWrapper <GetProfileOutput>();

            TUser tUser = await _dbContext.TUser
                          .Include(x => x.TBodyType)
                          .Include(x => x.TRegionCity).ThenInclude(x => x.TRegionState)
                          .Include(x => x.TActivityLevel)
                          .Include(x => x.TWeeklyGoal)
                          .FirstOrDefaultAsync(x => x.FireBaseId == request.firebaseId);

            result.Status = true;
            result.Result = new GetProfileOutput()
            {
                Email           = tUser.Email,
                FireBaseId      = tUser.FireBaseId,
                Enabled         = tUser.Enabled,
                FirstName       = tUser.FirstName,
                LastName        = tUser.LastName,
                BirthYear       = tUser.BirthYear,
                Phone           = tUser.Phone,
                Address         = tUser.Address,
                PostalCode      = tUser.PostalCode,
                RegionCityId    = tUser.TRegionCityId.toInt(0),
                RegionStateId   = tUser.TRegionCity?.TRegionStateId.toInt(0) ?? 0,
                RegionCountryId = tUser.TRegionCity?.TRegionState?.TRegionCountryId.toInt(0) ?? 0,
                Weight          = tUser.Weight,
                Height          = tUser.Height,
                Waist           = tUser.Waist,
                Hips            = tUser.Hips,
                Forearms        = tUser.Forearms,
                Fat             = tUser.Fat,
                BodyType        = tUser.TBodyType == null ? new BodyTypeOutput() : new BodyTypeOutput()
                {
                    Id    = tUser.TBodyType.Id,
                    Title = tUser.TBodyType.Title,
                    Image = tUser.TBodyType.Image
                },
                ActivityLevelPalForMale   = tUser.TActivityLevel?.PALForMale ?? 0,
                ActivityLevelPalForFemale = tUser.TActivityLevel?.PALForFeMale ?? 0,
                ActivityLevelCarb         = tUser.TActivityLevel?.Carb ?? 0,
                ActivityLevelProtein      = tUser.TActivityLevel?.Protein ?? 0,
                Gender                  = tUser.Gender,
                TargetWeight            = tUser.TargetWeight,
                WeeklyGoalId            = tUser.TWeeklyGoalId ?? 0,
                WeeklyGoalCaloryPercent = tUser.TWeeklyGoal?.CaloryRequirePercent ?? 0,
                GoalId                  = tUser.TWeeklyGoal?.TGoalId ?? 0,
                ActivityLevelId         = tUser.TActivityLevelId ?? 0
            };
            result.Result.BodyType.Image = result.Result.BodyType.Image.JoinWithCDNAddress();
            return(result);
        }
Esempio n. 5
0
        public async Task <IActionResult> Get()
        {
            FirebaseUser    user  = HttpContext.GetFirebaseUser();
            GetProfileQuery model = new GetProfileQuery()
            {
                firebaseId = user.UserId
            };
            ResultWrapper <GetProfileOutput> result = new ResultWrapper <GetProfileOutput>();

            result = await _mediator.Send(model);

            return(Ok(result));
        }
        public async Task GivenValidRequest_WhenTheUserDoesNotExist_ThrowsApiExceptionForNotFound()
        {
            // Arrange
            var getProfileRequest = new GetProfileQuery("aUserThatDoesNotExist");

            // Act
            var request = new GetProfileQueryQueryHandler(Mapper, Context, CurrentUserContext);

            await Should.ThrowAsync <ConduitApiException>(async() =>
            {
                await request.Handle(getProfileRequest, CancellationToken.None);
            });
        }
        public async Task GivenValidRequest_WhenTheUserExists_ReturnsProfileViewModel()
        {
            // Arrange
            var getProfileRequest = new GetProfileQuery("joey.mckenzie");

            // Act
            var request  = new GetProfileQueryQueryHandler(Mapper, Context, CurrentUserContext);
            var response = await request.Handle(getProfileRequest, CancellationToken.None);

            // Assert
            response.ShouldNotBeNull();
            response.ShouldBeOfType <ProfileViewModel>();
            response.Profile.ShouldNotBeNull();
            response.Profile.ShouldBeOfType <ProfileDto>();
            response.Profile.Username.ShouldBe("joey.mckenzie");
            response.Profile.Following.ShouldBe(true);
        }
Esempio n. 8
0
        public async Task <IActionResult> GetFoods()
        {
            FirebaseUser    user         = HttpContext.GetFirebaseUser();
            GetProfileQuery profileModel = new GetProfileQuery()
            {
                firebaseId = user.UserId
            };
            ResultWrapper <GetProfileOutput> profile = await _mediator.Send(profileModel);

            int requiredCalorie          = Decimal.ToInt32(profile.Result.RequireCaloriesForLaunch);
            GetSuggestedFoodsQuery model = new GetSuggestedFoodsQuery()
            {
                firebaseId      = user.UserId,
                RequiredCalorie = requiredCalorie
            };
            ResultWrapper <GetSuggestedFoodsOutput> result = new ResultWrapper <GetSuggestedFoodsOutput>();

            result = await _mediator.Send(model);

            return(Ok(result));
        }
Esempio n. 9
0
 public Profile GetProfile(int id)
 {
     return(GetProfileQuery <Profile> .Execute(new { Id = id }));
 }
Esempio n. 10
0
 public Task <ProfileViewModel> GetProfile(GetProfileQuery query)
 {
     return(Mediator.Send(query));
 }
Esempio n. 11
0
        /// <summary>
        /// This method is called when the client requests for the Account profile
        /// </summary>
        public static void SendProfile(GPCMClient client, Dictionary <string, string> recv)
        {
            //TODO

            // \getprofile\\sesskey\19150\profileid\2\id\2\final\
            //profileid is

            if (!recv.ContainsKey("profileid"))
            {
                GameSpyUtils.SendGPError(client, GPErrorCode.Parse, "There was an error parsing an incoming request.");
                return;
            }

            uint targetPID, messID, sesskey;

            if (!uint.TryParse(recv["profileid"], out targetPID))
            {
                GameSpyUtils.SendGPError(client, GPErrorCode.Parse, "There was an error parsing an incoming request.");
                return;
            }

            if (!uint.TryParse(recv["id"], out messID))
            {
                GameSpyUtils.SendGPError(client, GPErrorCode.Parse, "There was an error parsing an incoming request.");
                return;
            }
            if (!uint.TryParse(recv["sesskey"], out sesskey))
            {
                GameSpyUtils.SendGPError(client, GPErrorCode.Parse, "There was an error parsing an incoming request.");
                return;
            }

            string datatoSend = @"\pi\profileid\" + targetPID + @"\mp\4";

            // If the client want to access the public information
            // of another client
            if (targetPID != client.PlayerInfo.PlayerId)
            {
                GPCMPlayerInfo playerInfo = GetProfileQuery.GetProfileInfo(targetPID);
                if (playerInfo == null)
                {
                    GameSpyUtils.SendGPError(client, 4, "Unable to get profile information.");
                    return;
                }

                datatoSend = string.Format(datatoSend + @"\nick\{0}\uniquenick\{1}\id\{2}", playerInfo.PlayerNick, playerInfo.PlayerUniqueNick, messID);

                if (playerInfo.PlayerEmail.Length > 0)
                {
                    datatoSend += @"\email\" + playerInfo.PlayerEmail;
                }

                if (playerInfo.PlayerLastName.Length > 0)
                {
                    datatoSend += @"\lastname\" + playerInfo.PlayerLastName;
                }

                if (playerInfo.PlayerFirstName.Length > 0)
                {
                    datatoSend += @"\firstname\" + playerInfo.PlayerFirstName;
                }

                if (playerInfo.PlayerICQ != 0)
                {
                    datatoSend += @"\icquin\" + playerInfo.PlayerICQ;
                }

                if (playerInfo.PlayerHomepage.Length > 0)
                {
                    datatoSend += @"\homepage\" + playerInfo.PlayerHomepage;
                }

                if (playerInfo.PlayerPicture != 0)
                {
                    datatoSend += @"\pic\" + playerInfo.PlayerPicture;
                }

                if (playerInfo.PlayerAim.Length > 0)
                {
                    datatoSend += @"\aim\" + playerInfo.PlayerAim;
                }

                if (playerInfo.PlayerOccupation != 0)
                {
                    datatoSend += @"\occ\" + playerInfo.PlayerOccupation;
                }

                if (playerInfo.PlayerZIPCode.Length > 0)
                {
                    datatoSend += @"\zipcode\" + playerInfo.PlayerZIPCode;
                }

                if (playerInfo.PlayerCountryCode.Length > 0)
                {
                    datatoSend += @"\countrycode\" + playerInfo.PlayerCountryCode;
                }

                if (playerInfo.PlayerBirthday > 0 && playerInfo.PlayerBirthmonth > 0 && playerInfo.PlayerBirthyear > 0)
                {
                    datatoSend += @"\birthday\" + (uint)((playerInfo.PlayerBirthday << 24) | (playerInfo.PlayerBirthmonth << 16) | playerInfo.PlayerBirthyear);
                }

                if (playerInfo.PlayerLocation.Length > 0)
                {
                    datatoSend += @"\loc\" + playerInfo.PlayerLocation;
                }

                if (playerInfo.PlayerSex != PlayerSexType.PAT)
                {
                    if (playerInfo.PlayerSex == PlayerSexType.FEMALE)
                    {
                        datatoSend += @"\sex\1";
                    }
                    else if (playerInfo.PlayerSex == PlayerSexType.MALE)
                    {
                        datatoSend += @"\sex\0";
                    }
                }

                if (playerInfo.PlayerLatitude != 0.0f)
                {
                    datatoSend += @"\lat\" + playerInfo.PlayerLatitude;
                }

                if (playerInfo.PlayerLongitude != 0.0f)
                {
                    datatoSend += @"\lon\" + playerInfo.PlayerLongitude;
                }

                if (playerInfo.PlayerIncomeID != 0)
                {
                    datatoSend += @"\inc\" + playerInfo.PlayerIncomeID;
                }

                if (playerInfo.PlayerIndustryID != 0)
                {
                    datatoSend += @"\ind\" + playerInfo.PlayerIndustryID;
                }

                if (playerInfo.PlayerMarried != 0)
                {
                    datatoSend += @"\mar\" + playerInfo.PlayerMarried;
                }

                if (playerInfo.PlayerChildCount != 0)
                {
                    datatoSend += @"\chc\" + playerInfo.PlayerChildCount;
                }

                if (playerInfo.PlayerInterests != 0)
                {
                    datatoSend += @"\i1\" + playerInfo.PlayerInterests;
                }

                if (playerInfo.PlayerOwnership != 0)
                {
                    datatoSend += @"\o1\" + playerInfo.PlayerOwnership;
                }

                if (playerInfo.PlayerConnectionType != 0)
                {
                    datatoSend += @"\conn\" + playerInfo.PlayerConnectionType;
                }

                // SUPER NOTE: Please check the Signature of the PID, otherwise when it will be compared with other peers, it will break everything (See gpiPeer.c @ peerSig)
                datatoSend += @"\sig\" + GameSpyLib.Common.Random.GenerateRandomString(33, GameSpyLib.Common.Random.StringType.Hex) + @"\final\";
            }
            else
            {
                // Since this is our profile, we have to see ALL informations that we can edit. This means that we don't need to check the public masks for sending
                // the data

                datatoSend = string.Format(datatoSend + @"\nick\{0}\uniquenick\{1}\email\{2}\id\{3}\pmask\{4}",
                                           client.PlayerInfo.PlayerNick,
                                           client.PlayerInfo.PlayerUniqueNick,
                                           client.PlayerInfo.PlayerEmail,
                                           /*(ProfileSent ? "5" : "2")*/ messID,
                                           client.PlayerInfo.PlayerPublicMask
                                           );

                if (client.PlayerInfo.PlayerLastName.Length > 0)
                {
                    datatoSend += @"\lastname\" + client.PlayerInfo.PlayerLastName;
                }

                if (client.PlayerInfo.PlayerFirstName.Length > 0)
                {
                    datatoSend += @"\firstname\" + client.PlayerInfo.PlayerFirstName;
                }

                if (client.PlayerInfo.PlayerICQ != 0)
                {
                    datatoSend += @"\icquin\" + client.PlayerInfo.PlayerICQ;
                }

                if (client.PlayerInfo.PlayerHomepage.Length > 0)
                {
                    datatoSend += @"\homepage\" + client.PlayerInfo.PlayerHomepage;
                }

                if (client.PlayerInfo.PlayerPicture != 0)
                {
                    datatoSend += @"\pic\" + client.PlayerInfo.PlayerPicture;
                }

                if (client.PlayerInfo.PlayerAim.Length > 0)
                {
                    datatoSend += @"\aim\" + client.PlayerInfo.PlayerAim;
                }

                if (client.PlayerInfo.PlayerOccupation != 0)
                {
                    datatoSend += @"\occ\" + client.PlayerInfo.PlayerOccupation;
                }

                if (client.PlayerInfo.PlayerZIPCode.Length > 0)
                {
                    datatoSend += @"\zipcode\" + client.PlayerInfo.PlayerZIPCode;
                }

                if (client.PlayerInfo.PlayerCountryCode.Length > 0)
                {
                    datatoSend += @"\countrycode\" + client.PlayerInfo.PlayerCountryCode;
                }

                if (client.PlayerInfo.PlayerBirthday > 0 && client.PlayerInfo.PlayerBirthmonth > 0 && client.PlayerInfo.PlayerBirthyear > 0)
                {
                    datatoSend += @"\birthday\" + (uint)((client.PlayerInfo.PlayerBirthday << 24) | (client.PlayerInfo.PlayerBirthmonth << 16) | client.PlayerInfo.PlayerBirthyear);
                }

                if (client.PlayerInfo.PlayerLocation.Length > 0)
                {
                    datatoSend += @"\loc\" + client.PlayerInfo.PlayerLocation;
                }

                if (client.PlayerInfo.PlayerSex == PlayerSexType.FEMALE)
                {
                    datatoSend += @"\sex\1";
                }
                else if (client.PlayerInfo.PlayerSex == PlayerSexType.MALE)
                {
                    datatoSend += @"\sex\0";
                }

                if (client.PlayerInfo.PlayerLatitude != 0.0f)
                {
                    datatoSend += @"\lat\" + client.PlayerInfo.PlayerLatitude;
                }

                if (client.PlayerInfo.PlayerLongitude != 0.0f)
                {
                    datatoSend += @"\lon\" + client.PlayerInfo.PlayerLongitude;
                }

                if (client.PlayerInfo.PlayerIncomeID != 0)
                {
                    datatoSend += @"\inc\" + client.PlayerInfo.PlayerIncomeID;
                }

                if (client.PlayerInfo.PlayerIndustryID != 0)
                {
                    datatoSend += @"\ind\" + client.PlayerInfo.PlayerIndustryID;
                }

                if (client.PlayerInfo.PlayerMarried != 0)
                {
                    datatoSend += @"\mar\" + client.PlayerInfo.PlayerMarried;
                }

                if (client.PlayerInfo.PlayerChildCount != 0)
                {
                    datatoSend += @"\chc\" + client.PlayerInfo.PlayerChildCount;
                }

                if (client.PlayerInfo.PlayerInterests != 0)
                {
                    datatoSend += @"\i1\" + client.PlayerInfo.PlayerInterests;
                }

                if (client.PlayerInfo.PlayerOwnership != 0)
                {
                    datatoSend += @"\o1\" + client.PlayerInfo.PlayerOwnership;
                }

                if (client.PlayerInfo.PlayerConnectionType != 0)
                {
                    datatoSend += @"\conn\" + client.PlayerInfo.PlayerConnectionType;
                }

                // SUPER NOTE: Please check the Signature of the PID, otherwise when it will be compared with other peers, it will break everything (See gpiPeer.c @ peerSig)
                datatoSend += @"\sig\" + GameSpyLib.Common.Random.GenerateRandomString(33, GameSpyLib.Common.Random.StringType.Hex) + @"\final\";

                // Set that we send the profile initially
                if (!client.ProfileSent)
                {
                    client.ProfileSent = true;
                }
            }

            client.Send(datatoSend);
        }