예제 #1
0
        public AuthenticationDialog(string dialogId, IEnumerable <WaterfallStep> steps = null)
            : base(dialogId, steps)
        {
            AddStep(async(stepContext, cancellationToken) =>
            {
                var promptOptions = new PromptOptions
                {
                    Prompt = MessageFactory.Text("Please enter your SecretLogin.")
                };
                return(await stepContext.PromptAsync("secretLogin", promptOptions, cancellationToken));
            });

            AddStep(async(stepContext, cancellationToken) =>
            {
                if (!(stepContext.Result is string login) || login.Length < 8 || login.Length > 32)
                {
                    await stepContext.Context
                    .SendActivityAsync(MessageFactory.Text("Invalid login format! Try again."), cancellationToken);
                    return(await stepContext.BeginDialogAsync(Id));
                }

                var user = new User(login);
                if (await requestSender.CheckIfUserExists(user))
                {
                    await stepContext.Context
                    .SendActivityAsync(MessageFactory.Text("Welcome back!"), cancellationToken);

                    var channel = new Channel(user, stepContext.Context.Activity.ChannelId);
                    await requestSender.RegisterChannelIfNotExists(channel);

                    return(await stepContext.BeginDialogAsync(MainFunctioningDialog.Id));
                }
                else
                {
                    await stepContext.Context
                    .SendActivityAsync(MessageFactory.Text("This user does not exists."), cancellationToken);
                    return(await stepContext.BeginDialogAsync(InitialDialog.Id));
                }
            });
        }