public async Task Email_Prompt() { var conversationState = new ConversationState(new MemoryStorage()); var dialogState = conversationState.CreateProperty <DialogState>("dialogState"); var adapter = new TestAdapter() .Use(new AutoSaveStateMiddleware(conversationState)); // Create new DialogSet. var dialogs = new DialogSet(dialogState); // Create and add number prompt to DialogSet. var emailPrompt = new EmailPrompt(nameof(EmailPrompt), defaultLocale: Culture.English); dialogs.Add(emailPrompt); await new TestFlow(adapter, async(turnContext, cancellationToken) => { var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken); var results = await dc.ContinueDialogAsync(cancellationToken); if (!turnContext.Responded && results.Status == DialogTurnStatus.Empty && results.Status != DialogTurnStatus.Complete) { var options = new PromptOptions { Prompt = new Activity { Type = ActivityTypes.Message, Text = "Kindly send your Email Id" } }; await dc.PromptAsync(nameof(EmailPrompt), options, cancellationToken); } else if (results.Status == DialogTurnStatus.Complete) { var emailPromptResult = (string)results.Result; if (emailPromptResult != null) { await turnContext.SendActivityAsync(MessageFactory.Text($"Bot received email: {emailPromptResult}"), cancellationToken); } else { await turnContext.SendActivityAsync(MessageFactory.Text($"Nothing recognized"), cancellationToken); } } }) .Send("hello") .AssertReply("Kindly send your Email Id") .Send("hey my email id is [email protected]") .AssertReply("Bot received email: [email protected]") .StartTestAsync(); }
public async Task StartEmailValidation(string emailToValidate, User user, App app, PlatformDataClaim?platformDataClaim, string acceptUrl, string declineUrl, IAsyncDocumentSession session, string platformId = "None", CancellationToken cancellationToken = default) { emailToValidate = emailToValidate.ToLowerInvariant(); var existingUserEmail = user.UserEmails.SingleOrDefault(ue => ue.Email == emailToValidate); if (existingUserEmail == null) { user.UserEmails.Add(new UserEmail(emailToValidate, UserEmailState.AwaitingVerification)); } var existingPromptsForEmail = await session.Query <EmailPrompt>() .Where(ep => ep.EmailAddress == emailToValidate, true).ToListAsync(cancellationToken); if (existingPromptsForEmail.Any()) { var unexpiredPrompt = existingPromptsForEmail.SingleOrDefault(p => !p.HasExpired()); if (unexpiredPrompt != null) { if (!unexpiredPrompt.PlatformIdToAppId.ContainsKey(platformId)) { unexpiredPrompt.PlatformIdToAppId.Add(platformId, new List <string>()); } if (unexpiredPrompt.PlatformIdToAppId[platformId].All(appId => appId != app.Id)) { unexpiredPrompt.PlatformIdToAppId[platformId].Add(app.Id); } } } var promptId = Guid.NewGuid(); var expiresAt = DateTimeOffset.UtcNow.AddHours(48).ToUnixTimeSeconds(); acceptUrl = acceptUrl.Replace("{promptId}", promptId.ToString()); declineUrl = declineUrl.Replace("{promptId}", promptId.ToString()); await _mailManager.SendConfirmEmailAddressMail(emailToValidate, acceptUrl, declineUrl, cancellationToken); var createdPrompt = new EmailPrompt(promptId, user.Id, emailToValidate, expiresAt, app.Id, platformId, platformDataClaim); await session.StoreAsync(createdPrompt, cancellationToken); }
private void RegsiterPromptButton_Click(object sender, RoutedEventArgs e) { PasswordTEXT.Password = null; PasswordRepeatTEXT.Password = null; LoginButtonBackground.IsEnabled = true; RegisterPromptButton.Visibility = Visibility.Hidden; PasswordBackground.Margin = new Thickness(0, -190, 0, 0); PasswordPrompt.Margin = new Thickness(-160, -250, 0, 0); EmailBackground.Visibility = Visibility.Hidden; EmailPrompt.Visibility = Visibility.Hidden; PasswordRepeatBackground.Visibility = Visibility.Hidden; PasswordRepeatPrompt.Visibility = Visibility.Hidden; DoubleAnimation LoginOpacityAnimation = new DoubleAnimation(); LoginOpacityAnimation.From = LoginButtonBackground.Opacity; LoginOpacityAnimation.To = 1; LoginOpacityAnimation.Duration = TimeSpan.FromSeconds(0.3); DoubleAnimation RegisterPromptOpacityAnimation = new DoubleAnimation(); RegisterPromptOpacityAnimation.From = RegisterPrompt.Opacity; RegisterPromptOpacityAnimation.To = 0; RegisterPromptOpacityAnimation.Duration = TimeSpan.FromSeconds(0.3); DoubleAnimation DecorationsOpacityAnimation = new DoubleAnimation(); DecorationsOpacityAnimation.From = Decorations.Opacity; DecorationsOpacityAnimation.To = 1; DecorationsOpacityAnimation.Duration = TimeSpan.FromSeconds(0.3); DoubleAnimation PasswordRepeatBackgroundOpacityAnimation = new DoubleAnimation(); PasswordRepeatBackgroundOpacityAnimation.From = PasswordRepeatBackground.Opacity; PasswordRepeatBackgroundOpacityAnimation.To = 0; PasswordRepeatBackgroundOpacityAnimation.Duration = TimeSpan.FromSeconds(0.3); DoubleAnimation PasswordRepeatPromptOpacityAnimation = new DoubleAnimation(); PasswordRepeatPromptOpacityAnimation.From = PasswordRepeatPrompt.Opacity; PasswordRepeatPromptOpacityAnimation.To = 0; PasswordRepeatPromptOpacityAnimation.Duration = TimeSpan.FromSeconds(0.3); DoubleAnimation EmailBackgroundOpacityAnimation = new DoubleAnimation(); EmailBackgroundOpacityAnimation.From = EmailBackground.Opacity; EmailBackgroundOpacityAnimation.To = 0; EmailBackgroundOpacityAnimation.Duration = TimeSpan.FromSeconds(0.3); DoubleAnimation EmailPromptOpacityAnimation = new DoubleAnimation(); EmailPromptOpacityAnimation.From = EmailPrompt.Opacity; EmailPromptOpacityAnimation.To = 0; EmailPromptOpacityAnimation.Duration = TimeSpan.FromSeconds(0.3); LoginButtonBackground.BeginAnimation(Border.OpacityProperty, LoginOpacityAnimation); RegisterPrompt.BeginAnimation(Border.OpacityProperty, RegisterPromptOpacityAnimation); Decorations.BeginAnimation(Border.OpacityProperty, LoginOpacityAnimation); PasswordRepeatBackground.BeginAnimation(Border.OpacityProperty, PasswordRepeatBackgroundOpacityAnimation); PasswordRepeatPrompt.BeginAnimation(TextBlock.OpacityProperty, PasswordRepeatPromptOpacityAnimation); EmailBackground.BeginAnimation(Border.OpacityProperty, EmailBackgroundOpacityAnimation); EmailPrompt.BeginAnimation(TextBlock.OpacityProperty, EmailPromptOpacityAnimation); }
private async void RegisterButton_Click(object sender, RoutedEventArgs e) { if (LoginButtonBackground.Opacity == 1) { PasswordTEXT.Password = null; PasswordRepeatTEXT.Password = null; LoginButtonBackground.IsEnabled = false; RegisterPromptButton.Visibility = Visibility.Visible; PasswordBackground.Margin = new Thickness(0, -60, 0, 0); PasswordPrompt.Margin = new Thickness(-160, -120, 0, 0); EmailBackground.Visibility = Visibility.Visible; EmailPrompt.Visibility = Visibility.Visible; PasswordRepeatBackground.Visibility = Visibility.Visible; PasswordRepeatPrompt.Visibility = Visibility.Visible; DoubleAnimation LoginOpacityAnimation = new DoubleAnimation(); LoginOpacityAnimation.From = LoginButtonBackground.Opacity; LoginOpacityAnimation.To = 0; LoginOpacityAnimation.Duration = TimeSpan.FromSeconds(0.3); DoubleAnimation RegisterPromptOpacityAnimation = new DoubleAnimation(); RegisterPromptOpacityAnimation.From = RegisterPrompt.Opacity; RegisterPromptOpacityAnimation.To = 1; RegisterPromptOpacityAnimation.Duration = TimeSpan.FromSeconds(0.3); DoubleAnimation DecorationsOpacityAnimation = new DoubleAnimation(); DecorationsOpacityAnimation.From = Decorations.Opacity; DecorationsOpacityAnimation.To = 0; DecorationsOpacityAnimation.Duration = TimeSpan.FromSeconds(0.3); DoubleAnimation PasswordRepeatBackgroundOpacityAnimation = new DoubleAnimation(); PasswordRepeatBackgroundOpacityAnimation.From = PasswordRepeatBackground.Opacity; PasswordRepeatBackgroundOpacityAnimation.To = 1; PasswordRepeatBackgroundOpacityAnimation.Duration = TimeSpan.FromSeconds(0.3); DoubleAnimation PasswordRepeatPromptOpacityAnimation = new DoubleAnimation(); PasswordRepeatPromptOpacityAnimation.From = PasswordRepeatPrompt.Opacity; PasswordRepeatPromptOpacityAnimation.To = 1; PasswordRepeatPromptOpacityAnimation.Duration = TimeSpan.FromSeconds(0.3); DoubleAnimation EmailBackgroundOpacityAnimation = new DoubleAnimation(); EmailBackgroundOpacityAnimation.From = EmailBackground.Opacity; EmailBackgroundOpacityAnimation.To = 1; EmailBackgroundOpacityAnimation.Duration = TimeSpan.FromSeconds(0.3); DoubleAnimation EmailPromptOpacityAnimation = new DoubleAnimation(); EmailPromptOpacityAnimation.From = EmailPrompt.Opacity; EmailPromptOpacityAnimation.To = 1; EmailPromptOpacityAnimation.Duration = TimeSpan.FromSeconds(0.3); LoginButtonBackground.BeginAnimation(Border.OpacityProperty, LoginOpacityAnimation); RegisterPrompt.BeginAnimation(Border.OpacityProperty, RegisterPromptOpacityAnimation); Decorations.BeginAnimation(Border.OpacityProperty, LoginOpacityAnimation); PasswordRepeatBackground.BeginAnimation(Border.OpacityProperty, PasswordRepeatBackgroundOpacityAnimation); PasswordRepeatPrompt.BeginAnimation(TextBlock.OpacityProperty, PasswordRepeatPromptOpacityAnimation); EmailBackground.BeginAnimation(Border.OpacityProperty, EmailBackgroundOpacityAnimation); EmailPrompt.BeginAnimation(TextBlock.OpacityProperty, EmailPromptOpacityAnimation); } else { RegisterButtonBackground.IsEnabled = false; if (PasswordTEXT.Password != PasswordRepeatTEXT.Password) { ErrorWindow ErrorWindow = new ErrorWindow(); ErrorWindow.Owner = this; ErrorWindow.ErrorText.Text = "Пароли не совпадают!"; BlurEffect EffectBlur = new BlurEffect(); EffectBlur.Radius = 10; this.Effect = EffectBlur; ErrorWindow.ShowDialog(); } else if (PasswordTEXT.Password.Equals("") || PasswordRepeatTEXT.Password.Equals("")) { ErrorWindow ErrorWindow = new ErrorWindow(); ErrorWindow.Owner = this; ErrorWindow.ErrorText.Text = "Введите пароль!"; BlurEffect EffectBlur = new BlurEffect(); EffectBlur.Radius = 10; this.Effect = EffectBlur; ErrorWindow.ShowDialog(); } else if (LoginTEXT.Text.Equals("")) { ErrorWindow ErrorWindow = new ErrorWindow(); ErrorWindow.Owner = this; ErrorWindow.ErrorText.Text = "Введите логин!"; BlurEffect EffectBlur = new BlurEffect(); EffectBlur.Radius = 10; this.Effect = EffectBlur; ErrorWindow.ShowDialog(); } else if (LoginTEXT.Text.Length <= 2) { ErrorWindow ErrorWindow = new ErrorWindow(); ErrorWindow.Owner = this; ErrorWindow.ErrorText.Text = "Логин слишком короткий!"; BlurEffect EffectBlur = new BlurEffect(); EffectBlur.Radius = 10; this.Effect = EffectBlur; ErrorWindow.ShowDialog(); } else if (EmailTEXT.Text.Equals("") || !(EmailTEXT.Text.Contains("@"))) { ErrorWindow ErrorWindow = new ErrorWindow(); ErrorWindow.Owner = this; ErrorWindow.ErrorText.Text = "Введите Email!"; BlurEffect EffectBlur = new BlurEffect(); EffectBlur.Radius = 10; this.Effect = EffectBlur; ErrorWindow.ShowDialog(); } else if (PasswordTEXT.Password == PasswordRepeatTEXT.Password && PasswordTEXT.Password != null) { string Password = "******"; try { using (SftpClient Client = new SftpClient("bedrock-project.ru", "root", Password.Replace("password", "singularity"))) { Client.Connect(); using (Stream fileStream = File.Create(Environment.CurrentDirectory + @"/Storage/Users/" + LoginTEXT.Text.ToString().Trim())) { Client.DownloadFile("/storage/nicknames/" + LoginTEXT.Text.ToString().Trim(), fileStream); } Client.Disconnect(); } ErrorWindow ErrorWindow = new ErrorWindow(); ErrorWindow.Owner = this; ErrorWindow.ErrorText.Text = "Такой логин уже \n существует! "; BlurEffect EffectBlur = new BlurEffect(); EffectBlur.Radius = 10; this.Effect = EffectBlur; ErrorWindow.ShowDialog(); } catch { try { using (SftpClient Client = new SftpClient("bedrock-project.ru", "root", Password.Replace("password", "singularity"))) { Client.Connect(); using (Stream fileStream = File.Create(Environment.CurrentDirectory + @"/Storage/Users/" + LoginTEXT.Text.ToString().Trim() + "_" + PasswordRepeatTEXT.Password.ToString().Trim())) { Client.UploadFile(fileStream, "/storage/accounts/" + LoginTEXT.Text.ToString().Trim() + "_" + PasswordRepeatTEXT.Password.ToString().Trim()); } Client.Disconnect(); } using (SftpClient Client = new SftpClient("bedrock-project.ru", "root", Password.Replace("password", "singularity"))) { Client.Connect(); using (Stream fileStream = File.Create(Environment.CurrentDirectory + @"/Storage/Users/" + LoginTEXT.Text.ToString().Trim() + "_" + PasswordRepeatTEXT.Password.ToString().Trim())) { Client.UploadFile(fileStream, "/storage/nicknames/" + LoginTEXT.Text.ToString().Trim()); } Client.Disconnect(); } try { File.Delete(Environment.CurrentDirectory + @"/Storage/Users/" + LoginTEXT.Text.ToString().Trim() + "_" + PasswordRepeatTEXT.Password.ToString().Trim()); File.Create(Environment.CurrentDirectory + @"/Storage/Users/" + LoginTEXT.Text.ToString().Trim()); } catch { } Verification = true; DoubleAnimation OpacityAnimation = new DoubleAnimation(); OpacityAnimation.From = this.Opacity; OpacityAnimation.To = 0; OpacityAnimation.Duration = TimeSpan.FromSeconds(0.5); this.BeginAnimation(Window.OpacityProperty, OpacityAnimation); await Task.Delay(500); this.Close(); } catch { ErrorWindow ErrorWindow = new ErrorWindow(); ErrorWindow.Owner = this; ErrorWindow.ErrorText.Text = "Что-то пошло не так!"; BlurEffect EffectBlur = new BlurEffect(); EffectBlur.Radius = 10; this.Effect = EffectBlur; ErrorWindow.ShowDialog(); } } } RegisterButtonBackground.IsEnabled = true; } }