Exemplo n.º 1
0
        async Task <User> FindUserAsync()
        {
            string key        = null;
            string email      = null;
            string vanityName = null;

            if (userKeyRegex.IsMatch(UserIdentifier))
            {
                key = UserIdentifier;
            }
            else if (UserIdentifier.IndexOf('@') > 0)
            {
                email = UserIdentifier;
            }
            else
            {
                vanityName = UserIdentifier;
            }

            User user = null;

            if (key != null)
            {
                user = await api.GetObjectAsync <User> (key);

                if (user == null)
                {
                    vanityName = key;
                }
            }

            if (user == null)
            {
                user = await api.FindUserAsync(email, vanityName);

                if (user == null)
                {
                    throw new UserNotFoundException(UserIdentifier);
                }
            }

            if (user.IsProtected)
            {
                throw new UserIsProtectedException(user);
            }

            return(user);
        }