예제 #1
0
        /// <summary>
        ///     Create a new instagram account
        /// </summary>
        /// <param name="username">Username</param>
        /// <param name="password">Password</param>
        /// <param name="email">Email</param>
        /// <param name="firstName">First name (optional)</param>
        /// <returns></returns>
        public async Task <IResult <CreationResponse> > CreateNewAccount(string username, string password, string email, string firstName)
        {
            CreationResponse createResponse = new CreationResponse();

            try
            {
                var postData = new Dictionary <string, string>
                {
                    { "email", email },
                    { "username", username },
                    { "password", password },
                    { "device_id", ApiRequestMessage.GenerateDeviceId() },
                    { "guid", _deviceInfo.DeviceGuid.ToString() },
                    { "first_name", firstName }
                };

                var instaUri = UriCreator.GetCreateAccountUri();
                var request  = HttpHelper.GetSignedRequest(HttpMethod.Post, instaUri, _deviceInfo, postData);
                var response = await _httpRequestProcessor.SendAsync(request);

                var result = await response.Content.ReadAsStringAsync();

                return(Result.Success(JsonConvert.DeserializeObject <CreationResponse>(result)));
            }
            catch (Exception exception)
            {
                _logger?.LogException(exception);
                return(Result.Fail <CreationResponse>(exception));
            }
        }
예제 #2
0
    void callback(CreationResponse c)
    {
        switch (c.status)
        {
        case "SUCCESS":
        {
            //Account is created
            //Login the user with the credentials
            login(NewEmailInput.text, NewPasswordInput.text);
            break;
        }

        case "EXISTING":
        {
            //Alert the user email is already registered
            //use login to login
            Alert("Email Already Exists. Please Login.");
            break;
        }

        default:
        {
            //Navigate to Main Menu
            //Alert the user Try connecting to server again
            LoginMenu.SetActive(false);
            Mainmenu.SetActive(true);
            break;
        }
        }
    }
예제 #3
0
        public BrokerResult CreateEventChannel(IEvent theEvent, IUser eventCreator)
        {
            string tableName = ConvertEventToTableName(theEvent);
            string data      = RTStringBuilder.MakeCreateString(tableName);

            try
            {
                var              CreateUrl = Properties.Settings.Default.RTFCreateURL;
                string           response  = MessageConnect.SendRequest(CreateUrl, data);
                CreationResponse creation  = JsonConvert.DeserializeObject <CreationResponse>(response);
                try
                {
                    if (tableName.Equals(creation.data.table))
                    {
                        return(BrokerResult.newSuccess());
                    }
                    throw new Exception("RTF returned table name " + creation.data.table);
                }
                catch (NullReferenceException e)
                {
                    throw new Exception("RTF returned an error Message during table creation: " + creation.error.code + creation.error.message);
                }
            }
            catch (WebException e)
            {
                return(new BrokerResult {
                    type = ResultType.createError, reason = ErrorReason.remoteCreateFailure, Message = e.Message
                });
            }
        }
예제 #4
0
        public static async Task Worker(string login, string password, string mail, string proxy, string name)
        {
            HttpClientHandler handler = new HttpClientHandler
            {
                Proxy    = new WebProxy(proxy),
                UseProxy = true
            };

            var userSession = new UserSessionData
            {
                UserName = SessionLog,
                Password = SessionPwd
            };

            HttpClient cl = new HttpClient(handler);


            cl.DefaultRequestHeaders.Add("User-Agent",
                                         "Mozilla/5.0 (Linux; U; Android 2.2) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1");

            IInstaApi instaApi = InstaApiBuilder.CreateBuilder()
                                 .SetUser(userSession)
                                 .UseHttpClientHandler(handler)
                                 .UseHttpClient(cl)
                                 .Build();


            try
            {
                var nd = await instaApi.CreateNewAccount(login, password, mail,
                                                         name);


                switch (nd.Info.Message)
                {
                case "feedback_required":
                    Console.WriteLine("Ban account!");
                    break;

                case "No errors detected":
                    CreationResponse ni1 = nd.Value;
                    Console.WriteLine("Created: " + ni1.AccountCreated);
                    break;

                default:
                    Console.WriteLine(nd.Info.Message);
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #5
0
        //Does not authenticate or wait. Leave to facade.
        public string CreateUserChannel(IUser user)
        {
            string           tableName = ConvertUserToTableName(user);
            string           data      = RTStringBuilder.MakeCreateString(tableName);
            string           createUrl = Properties.Settings.Default.RTFCreateURL;
            string           response  = MessageConnect.SendRequest(createUrl, data);
            CreationResponse creation  = JsonConvert.DeserializeObject <CreationResponse>(response);

            try
            {
                if (tableName.Equals(creation.data.table))
                {
                    return(tableName);
                }
                throw new Exception("RTF returned table name " + creation.data.table);
            }
            catch (NullReferenceException e)
            {
                throw new Exception("RTF returned an error Message during table creation: " + creation.error.code + creation.error.message);
            }
        }
예제 #6
0
        private static async Task CreateNewGameAsync()
        {
            Console.Write("\nLoading...");
            ScenarioResponse modeList = null;

            try
            {
                modeList = await API.GetScenarioAsync(AIDungeon.AllScenarios);
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine($"\nAn error occurred: {e.Message}");
            }
            if (!IsValidResponse(modeList))
            {
                return;
            }

            SortedList <string, uint> modes = new SortedList <string, uint>();

            foreach (var mode in modeList.Data.Content.Options)
            {
                modes.Add(mode.Title, uint.Parse(mode.Id.Substring(9), CultureInfo.InvariantCulture)); // "scenario:xxxxxx"
            }

            var tempModes = new List <string>(modes.Keys)
            {
                "Exit to menu"
            };
            int modeOption = OptionSelection("Select a setting...", tempModes);

            if (modeOption == tempModes.Count)
            {
                // Exit
                return;
            }
            modeOption--;

            List <History> historyList;
            uint           id;

            if (modes.Keys[modeOption] != "custom")
            {
                ScenarioResponse characterList = null;
                try
                {
                    characterList = await API.GetScenarioAsync(modes.Values[modeOption]);
                }
                catch (HttpRequestException e)
                {
                    Console.WriteLine($"An error occurred: {e.Message}");
                }
                if (!IsValidResponse(characterList))
                {
                    return;
                }

                SortedList <string, uint> characters = new SortedList <string, uint>();
                foreach (var character in characterList.Data.Content.Options)
                {
                    characters.Add(character.Title, uint.Parse(character.Id.Substring(9), CultureInfo.InvariantCulture)); // "scenario:xxxxxx"
                }

                var tempCharacters = new List <string>(characters.Keys)
                {
                    "Exit to menu"
                };
                int characterOption = OptionSelection("Select a character...", tempCharacters);
                if (characterOption == tempCharacters.Count)
                {
                    // Exit
                    return;
                }

                characterOption--;

                string name;
                while (true)
                {
                    Console.Write("\n\nEnter the character name: ");
                    name = Console.ReadLine();
                    if (!string.IsNullOrWhiteSpace(name))
                    {
                        break;
                    }
                    Console.WriteLine("You must specify a name.");
                }

                Console.WriteLine($"Creating a new adventure with the mode: {modes.Keys[modeOption]}, and the character: {characters.Keys[characterOption]}...");

                ScenarioResponse scenario = null;
                try
                {
                    scenario = await API.GetScenarioAsync(characters.Values[characterOption]);
                }
                catch (HttpRequestException e)
                {
                    Console.WriteLine($"An error occurred: {e.Message}");
                }
                if (!IsValidResponse(scenario))
                {
                    return;
                }

                CreationResponse response = null;
                try
                {
                    response = await API.CreateAdventureAsync(characters.Values[characterOption], scenario.Data.Content.Prompt.Replace("${character.name}", name));
                }
                catch (HttpRequestException e)
                {
                    Console.WriteLine($"An error occurred: {e.Message}");
                }
                if (!IsValidResponse(response))
                {
                    return;
                }
                if (response.Data.AdventureInfo == null)
                {
                    Console.Write("Seems that the access token is invalid.\nPlease edit the token in the menu/Edit config, or try logging out and logging in.\n");
                    Console.Write("\nPress any key to continue...");
                    Console.ReadKey();
                    return;
                }

                id          = uint.Parse(response.Data.AdventureInfo.ContentId, CultureInfo.InvariantCulture); // "adventure:xxxxxxx"
                historyList = response.Data.AdventureInfo.HistoryList;                                         // result.Data.AdventureInfo.HistoryList.Count - 1
            }
            else
            {
                string customText;
                Console.WriteLine($"\n{CustomPrompt}\n");
                while (true)
                {
                    Console.Write("Prompt: ");
                    customText = Console.ReadLine();
                    if (string.IsNullOrWhiteSpace(customText))
                    {
                        Console.WriteLine("You must enter a text.");
                    }
                    else if (customText.Length > 140)
                    {
                        Console.WriteLine($"Text length must be lower than 140. (Current: {customText.Length})");
                    }
                    else
                    {
                        break;
                    }
                }
                Console.WriteLine("Creating a new adventure with the custom prompt...");

                CreationResponse adventure = null;
                try
                {
                    adventure = await API.CreateAdventureAsync(modes.Values[modeOption]);
                }
                catch (HttpRequestException e)
                {
                    Console.WriteLine($"An error occurred: {e.Message}");
                }
                if (!IsValidResponse(adventure))
                {
                    return;
                }

                WebSocketActionResponse response = null;
                try
                {
                    response = await API.RunWebSocketActionAsync(uint.Parse(adventure.Data.AdventureInfo.ContentId, CultureInfo.InvariantCulture), ActionType.Story, customText);
                }
                catch (IOException e)
                {
                    Console.WriteLine($"An error occurred: {e.Message}");
                }
                catch (JsonSerializationException e)
                {
                    Console.WriteLine($"An error occurred: {e.Message}");
                }
                catch (TimeoutException e)
                {
                    Console.WriteLine($"An error occurred: {e.Message}");
                }
                if (!IsValidResponse(response))
                {
                    return;
                }
                var content = response.Payload.Data.SubscribeContent;

                id          = uint.Parse(content.Id.Substring(10), CultureInfo.InvariantCulture); // "adventure:xxxxxxx"
                historyList = content.HistoryList;
            }

            await ProcessAdventureAsync(id, historyList);
        }
예제 #7
0
        // POST: <BaseAddress>/<ControllerName>
        public async Task <CreationResponse <TIndexType> > Post([FromBody] TRecordExchangeType value)
        {
            if (value == null)
            {
                RaiseErrorMessage(HttpStatusCode.BadRequest, InvalidParametersErrorMsg, LogSeverity.DebugInfo);
                return(null);
            }
            if (value.IsValidForCreation() == false)
            {
                RaiseErrorMessage(HttpStatusCode.BadRequest, InvalidParametersErrorMsg, LogSeverity.DebugInfo);
            }

            try
            {
                await CustomCreationValidityCheck(value);
            }
            catch (SystemException exception)
            {
                RaiseErrorMessage(HttpStatusCode.InternalServerError, InternalServerErrorMsg, LogSeverity.FatalError, exception);
            }

            var recordFromValue = new TRecordType();

            value.UpdateModel(recordFromValue);

            //If the key is not autogenerated, check if an entity with same ID is in database. If so, throw bad request error.
            if (recordFromValue.KeyIsAutogenerated() == false)
            {
                var sameIdAlreadyInUse = true;

                try
                {
                    await Get(recordFromValue.GetKey());
                }
                catch (HttpResponseException exception)
                {
                    if (exception.Response.StatusCode != HttpStatusCode.NotFound)
                    {
                        throw;
                    }
                    sameIdAlreadyInUse = false;
                }

                if (sameIdAlreadyInUse)
                {
                    RaiseErrorMessage(HttpStatusCode.BadRequest, IdAlreadyInUseErrorMsg, LogSeverity.DebugInfo);
                }
            }

            TIndexType recordKey = default(TIndexType);

            try
            {
                recordKey = await DataAccess.CreateAsync(recordFromValue);
            }
            catch (SystemException exception)
            {
                RaiseErrorMessage(HttpStatusCode.InternalServerError, InternalServerErrorMsg, LogSeverity.FatalError, exception);
            }

            recordFromValue.SetKey(recordKey);
            var output = new CreationResponse <TIndexType>(recordKey);

            return(output);
        }