コード例 #1
0
        public void ValidDataConversion()
        {
            var address  = new Address("1653 La Golondrina Ave", "Alhambra", "CA", "91803");
            var location = address.getLocation().Replace(' ', '+');

            Assert.Equal(location, "1653+La+Golondrina+Ave,+Alhambra,+CA");
            MapWebAPIComm network    = new MapWebAPIComm();
            var           mappedData = new WebAPIGeocode();
            var           requestDTO = new NetworkLocationDTO()
            {
                Location = location
            };
            var    test     = Task.Run(async() => { return(await network.Request(requestDTO)); }).Result;
            string response = test.Response;
            var    data     = JObject.Parse(response);

            Assert.Equal(data["status"], ("OK"));
            JArray convertedData           = (JArray)data["results"][0]["address_components"];
            int    addressComponentsLength = convertedData.Count;

            Assert.Equal(addressComponentsLength, 8);

            for (int i = 0; i < convertedData.Count; i++)
            {
                if (data["results"][0]["address_components"][i]["types"][0].ToString().Equals("administrative_area_level_2"))
                {
                    Assert.Equal(data["results"][0]["address_components"][i]["long_name"].ToString(), "Los Angeles County");
                }
            }
            Assert.Equal(data["results"][0]["geometry"]["location"]["lat"].ToString(), "34.0740499");
            Assert.Equal(data["results"][0]["geometry"]["location"]["lng"].ToString(), "-118.1531137");
        }
コード例 #2
0
        public Outcome Execute()
        {
            MapWebAPIComm network    = new MapWebAPIComm();
            var           requestDTO = new NetworkLocationDTO()
            {
                Location = RequestedLocation
            };

            // Waits for the request to finish
            // TODO: I need to fix this Task.Run issue
            var test = Task.Run(async() => { return(await network.Request(requestDTO)); }).Result;

            // Converts the data from the web api
            MapDataAdapter dataMapper = new MapDataAdapter();
            var            mappedData = dataMapper.Convert(test.Response);

            ValidatedLocation = mappedData;

            // Validating County based on the scope
            if (ValidatedLocation.County != null && (ValidatedLocation.County.Equals("Los Angeles County") || ValidatedLocation.County.Equals("Orange County")))
            {
                ValidatedLocation.IsValid = true;
            }
            else
            {
                ValidatedLocation.IsValid = false;
            }

            return(new Outcome()
            {
                Result = ValidatedLocation
            });
        }
コード例 #3
0
        /// <summary>
        /// Validates Registration Information
        /// </summary>
        /// <param name="creds"> Registration Information </param>
        /// <returns> status of the validation </returns>
        public bool ValidateCredentials(RegInfo creds)
        {
            var validator = new RegInfoValidator();

            // validates Register info
            Response     = validator.Validate(creds);
            UserLocation = validator.ValidatedLocation;
            return(Response.isSuccessful);
        }
コード例 #4
0
        /// <summary>
        /// Checks if the address is in the scope of Whatfits by sending a request to Google Maps Web API
        /// </summary>
        /// <param name="address"> location based on users input </param>
        /// <returns> status of the validation of the location </returns>
        public bool CheckAddress(string address)
        {
            var           location   = address.Replace(' ', '+');
            MapWebAPIComm network    = new MapWebAPIComm();
            var           requestDTO = new NetworkLocationDTO()
            {
                Location = location
            };

            // Waits for the request to finish
            var test = Task.Run(async() => { return(await network.Request(requestDTO)); }).Result;

            // Converts the data from the web api
            MapDataAdapter dataMapper = new MapDataAdapter();
            var            mappedData = dataMapper.Convert(test.Response);

            // Validating County based on the scope
            if (mappedData.County != null && (mappedData.County.Equals("Los Angeles County") || mappedData.County.Equals("Orange County")))
            {
                ValidatedLocation = mappedData;
                return(true);
            }
            return(false);
        }
コード例 #5
0
        /// <summary>
        /// Creates dto based on validated information
        /// </summary>
        /// <param name="user"> Validated registeration information </param>
        /// <param name="geoCoordinates"> Validated Geocoordinates based on the location of registration information </param>
        /// <returns> The gateway DTO needed to create the user in the database </returns>
        public RegGatewayDTO CreateGatewayDTO(RegInfo user, WebAPIGeocode geoCoordinates)
        {
            var hmac = new HMAC256();
            var salt = hmac.GenerateSalt();

            // Returns null if salt was not generated (empty string)
            if (salt.Equals(""))
            {
                return(null);
            }

            var hashDTO = new HashDTO()
            {
                Original = user.UserCredInfo.Password + salt
            };

            var hashPassword = hmac.Hash(hashDTO);

            // Return null if hash was not generated (empty string)
            if (hashPassword.Equals(""))
            {
                return(null);
            }

            var questions = new List <string>();
            var answers   = new List <string>();

            foreach (SecurityQuestion QandA in user.SecurityQandAs)
            {
                questions.Add(QandA.Question);

                // hashes the answer to the security question
                var hmacDTO = new HashDTO()
                {
                    Original = QandA.Answer
                };
                var hashAnswer = hmac.Hash(hmacDTO);

                // returns null if hash was not generated
                if (hashAnswer.Equals(""))
                {
                    return(null);
                }

                answers.Add(hashAnswer);
            }

            // Maps data to the dto for the gateway
            var mappedDTO = new RegGatewayDTO()
            {
                UserName   = user.UserCredInfo.Username,
                Password   = hashPassword,
                FirstName  = user.UserProfile.FirstName,
                LastName   = user.UserProfile.LastName,
                Type       = user.UserProfile.UserType,
                Skill      = user.UserProfile.Skill,
                Address    = geoCoordinates.Street,
                City       = geoCoordinates.City,
                State      = geoCoordinates.State,
                Zipcode    = geoCoordinates.ZipCode,
                Longitude  = geoCoordinates.Longitude,
                Latitude   = geoCoordinates.Latitude,
                UserClaims = new SetDefaultClaims().GetDefaultClaims(),
                Salt       = salt,
                Questions  = questions,
                Answers    = answers
            };

            return(mappedDTO);
        }