Beispiel #1
0
        /// <summary>
        ///     Get all person IDs that match a certain login token.
        /// </summary>
        /// <param name="loginToken">The login token to look for.</param>
        /// <returns>An array of person IDs.</returns>
        private static People GetPeopleByLoginToken(string loginToken)
        {
            People result = new People();

            SwarmDb database = SwarmDb.GetDatabaseForReading();

            // First, is the login token numeric? If so, add it as is and is a valid person.

            if (LogicServices.IsNumber(loginToken))
            {
                try
                {
                    int    personId = Int32.Parse(loginToken);
                    Person person   = Person.FromIdentity(personId);

                    // If we get here without exception, the login token is a valid person Id

                    result.Add(person);
                }
                catch (Exception)
                {
                    // Do nothing. In particular, do not add the person Id as a candidate.
                }
            }

            // Second, is the login token ten digits? If so, look for the person with this personal number.
            // This is specific to the Swedish PP.

            string cleanedNumber = LogicServices.CleanNumber(loginToken);

            if (cleanedNumber.Length == 10)
            {
                int[] personIds = database.GetObjectsByOptionalData(ObjectType.Person,
                                                                    ObjectOptionalDataType.PersonalNumber,
                                                                    cleanedNumber);

                foreach (int personId in personIds)
                {
                    result.Add(Person.FromIdentity(personId));
                }
            }

            // Third, look for a matching name. Expand the login token so that "R Falkv" will match "Rickard Falkvinge".
            // Only do this if the login token, excessive whitespace removed, is five characters or more.

            result = People.LogicalOr(result, People.FromNamePattern(loginToken));

            // Fourth, look for a matching email. Only do an exact match here.

            if (loginToken.Contains("@"))
            {
                result = People.LogicalOr(result, People.FromEmailPattern(loginToken));
            }

            return(result);
        }