Exemplo n.º 1
0
        private async Task <DialogTurnResult> AmountStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var orderLine = stepContext.GetValue <OrderLine>(ORDER);

            if (orderLine.ProductId == -1)
            {
                orderLine.ProductId = CardUtils.GetValueFromAction <int>((string)stepContext.Result);
            }

            var product = (await PrestashopApi.GetProductById(orderLine.ProductId)).First();

            var promptOptions = new PromptOptions
            {
                Prompt      = MessageFactory.Text($"How many {product.GetNameByLanguage(Languages.English)} do you want to buy?"),
                RetryPrompt = MessageFactory.Text("How many you want to buy? Just type a number!"),
            };

            if (orderLine.Amount == -1)
            {
                return(await stepContext.PromptAsync(nameof(NumberPrompt <int>), promptOptions, cancellationToken));
            }
            else
            {
                return(await stepContext.NextAsync(null, cancellationToken));
            }
        }
Exemplo n.º 2
0
        private async Task <DialogTurnResult> ProcessChoiceStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (stepContext.Result.GetType() == typeof(string))
            {
                int id = CardUtils.GetValueFromAction <int>((string)stepContext.Result);

                var cart = await PurchaseController.GetCartById(id);

                return(await stepContext.NextAsync(cart, cancellationToken));
            }

            return(await stepContext.NextAsync(stepContext.Result, cancellationToken));
        }
Exemplo n.º 3
0
        private async Task <bool> ValidatePasswordAsync(PromptValidatorContext <string> promptContext, CancellationToken cancellationToken)
        {
            var customer = (await PrestashopApi.GetCustomerByEmail(UserEmail)).First();

            string json = promptContext.Context.Activity.Text;

            try
            {
                CardUtils.GetValueFromAction <string>(json);
            }
            catch (JsonReaderException)
            {
                await promptContext.Context.SendActivityAsync("Please, type your Vitrosep Store password on the textbox or cancel the operation! (You can do so by type **cancel** or **quit**)");

                await promptContext.Context.SendActivityAsync(promptContext.Options.RetryPrompt);

                return(await Task.FromResult(false));
            }

            var  password = CardUtils.GetValueFromAction <string>(json);
            bool isValid;

            //BCrypt algorythm for newer generated passwords
            if (customer.Password.Length == 60)
            {
                isValid = BCrypt.Net.BCrypt.Verify(password, customer.Password);
            }
            //MD5 hashing for older generated passwords
            else
            {
                var    provider     = MD5.Create();
                string salt         = Configuration.GetSection("PrestashopSettings").GetSection("CookieKey").Value;
                byte[] bytes        = provider.ComputeHash(Encoding.ASCII.GetBytes(salt + password));
                string computedHash = BitConverter.ToString(bytes);

                isValid = computedHash == customer.Password;
            }

            if (!isValid)
            {
                await promptContext.Context.SendActivityAsync("Incorrect password, you must've got something wrong :(");

                await promptContext.Context.SendActivityAsync(promptContext.Options.RetryPrompt);
            }

            return(await Task.FromResult(isValid));
        }
Exemplo n.º 4
0
        private async Task <DialogTurnResult> SetPermissionStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            stepContext.Values["id"] = stepContext.Result.GetType() == typeof(int)
                ? (int)stepContext.Result
                : CardUtils.GetValueFromAction <int>((string)stepContext.Result);

            var permList    = Enum.GetValues(typeof(PermissionLevels)).Cast <PermissionLevels>().ToList();
            var permStrings = (from permission in permList select permission.GetDescription()).ToList();

            var promptOptions = new PromptOptions
            {
                Prompt      = MessageFactory.Text(permissionMsg),
                RetryPrompt = MessageFactory.Text("Choose a value from the list below (sorted from highest to lowest)"),
                Choices     = ChoiceFactory.ToChoices(permStrings)
            };

            return(await stepContext.PromptAsync(nameof(ChoicePrompt), promptOptions, cancellationToken));
        }
Exemplo n.º 5
0
        protected async Task <bool> CardJsonValidator(PromptValidatorContext <string> promptContext, CancellationToken cancellationToken)
        {
            string json = promptContext.Context.Activity.Text;

            try
            {
                CardUtils.GetValueFromAction <string>(json);
            }
            catch (JsonReaderException)
            {
                await promptContext.Context.SendActivityAsync("Please, type your Vitrosep Store password on the textbox or cancel the operation! (You can do so by type **cancel** or **quit**)");

                await promptContext.Context.SendActivityAsync(promptContext.Options.RetryPrompt);

                return(await Task.FromResult(false));
            }

            return(await Task.FromResult(true));
        }
Exemplo n.º 6
0
        private async Task <DialogTurnResult> ProcessValueStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var action = CardUtils.GetValueFromAction <string>((string)stepContext.Result);

            stepContext.Values[ACTION] = action;

            switch (action)
            {
            case "confirmOrder":
            case "cancelOrder":
                var msg = action.Replace("Order", "");

                return(await stepContext.PromptAsync(nameof(ConfirmPrompt),
                                                     new PromptOptions { Prompt = MessageFactory.Text("Are you sure you want to " + msg + " this order?") }, cancellationToken));

            default:
                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }
        }