public ActionResult Settings() { var akismetUrl = string.IsNullOrEmpty(SettingsRepository.BlogAkismetUrl) ? GetRootUrl().TrimEnd('/') : SettingsRepository.BlogAkismetUrl; var adminSettings = new AdminSettingsViewModel { BlogName = SettingsRepository.BlogName, BlogCaption = SettingsRepository.BlogCaption, BlogTheme = SettingsRepository.BlogTheme, BlogThemes = GetAvailableThemes(SettingsRepository.BlogTheme), BlogSocialSharing = SettingsRepository.BlogSocialSharing, BlogSyntaxHighlighting = SettingsRepository.BlogSyntaxHighlighting, PostsPerPage = SettingsRepository.BlogPostsPerPage, AkismetEnabled = SettingsRepository.BlogAkismetEnabled, AkismetDeleteSpam = SettingsRepository.BlogAkismetDeleteSpam, AkismetKey = SettingsRepository.BlogAkismetKey, AkismetUrl = akismetUrl, AdminEmailAddress = SettingsRepository.BlogAdminEmailAddress, BlogSmtpAddress = SettingsRepository.BlogSmtpAddress, ManageItemsPerPage = SettingsRepository.ManageItemsPerPage, BlogErrorAction = SettingsRepository.BlogSiteErrorEmailAction, Title = SettingsRepository.BlogName, DisqusEnabled = SettingsRepository.DisqusEnabled, DisqusShortName = SettingsRepository.BlogDisqusShortName }; return(View(adminSettings)); }
public ActionResult Settings(AdminSettingsViewModel adminSettingsViewModel) { adminSettingsViewModel.BlogThemes = GetAvailableThemes(adminSettingsViewModel.BlogTheme); if (ModelState.IsValid && ValidateAkismetSettings(adminSettingsViewModel)) { SettingsRepository.BlogName = adminSettingsViewModel.BlogName; SettingsRepository.BlogCaption = adminSettingsViewModel.BlogCaption; SettingsRepository.BlogTheme = adminSettingsViewModel.BlogTheme; SettingsRepository.BlogSocialSharing = adminSettingsViewModel.BlogSocialSharing; SettingsRepository.BlogSyntaxHighlighting = adminSettingsViewModel.BlogSyntaxHighlighting; SettingsRepository.BlogPostsPerPage = adminSettingsViewModel.PostsPerPage; SettingsRepository.BlogAkismetEnabled = adminSettingsViewModel.AkismetEnabled; SettingsRepository.BlogAkismetDeleteSpam = adminSettingsViewModel.AkismetDeleteSpam; SettingsRepository.BlogAkismetKey = adminSettingsViewModel.AkismetKey; SettingsRepository.BlogAkismetUrl = adminSettingsViewModel.AkismetUrl; SettingsRepository.BlogAdminEmailAddress = adminSettingsViewModel.AdminEmailAddress; SettingsRepository.BlogSmtpAddress = adminSettingsViewModel.BlogSmtpAddress; if (!string.IsNullOrEmpty(adminSettingsViewModel.BlogSmtpPassword)) { SettingsRepository.BlogSmtpPassword = TripleDES.EncryptString(adminSettingsViewModel.BlogSmtpPassword); } SettingsRepository.ManageItemsPerPage = adminSettingsViewModel.ManageItemsPerPage; SettingsRepository.BlogSiteErrorEmailAction = adminSettingsViewModel.BlogErrorAction; SettingsRepository.DisqusEnabled = adminSettingsViewModel.DisqusEnabled; SettingsRepository.BlogDisqusShortName = adminSettingsViewModel.DisqusShortName; } adminSettingsViewModel.UpdateStatus = true; adminSettingsViewModel.Title = SettingsRepository.BlogName; return(View(adminSettingsViewModel)); }
public IActionResult Settings() { var model = new AdminSettingsViewModel { RadarrAPIKey = _apikeys.Radarr, RadarrUrl = _path.Radarr, TmdbApiKey = _apikeys.TMDB, BaseUrl = _path.BaseURL }; return(View(model)); }
public IActionResult Email( AdminSettingsViewModel settings, [FromServices] IFarmMasterSettingsAccessor dbSettings, [FromServices] ITemplatedEmailSender email ) { if (!this.ModelState.IsValid) { return(this.RedirectToAction("Settings")); } var mutableSettings = dbSettings.Settings; mutableSettings.SmtpServer = settings.Email.Smtp.Server; mutableSettings.SmtpPort = settings.Email.Smtp.Port; mutableSettings.SmtpUsername = settings.Email.Smtp.Username; mutableSettings.SmtpPassword = settings.Email.Smtp.Password; dbSettings.Settings = mutableSettings; /** * Just so the flow of email is documented: * * - ConfigureEmailOptions will update IOptions, IOptionsSnapshot, and IOptionsMonitor with values * from the database. * * - ITemplatedEmailSender doesn't recieve the new values automatically because ASP and its conflicting/open-ended documentation, * so we need a way to notify it of changes to the config. * * - Since this is the only place where the config can be changed, after updating the database with new settings (code above), * we construct an IOptionSnapshot for the *first time for this request*, causing it to contain up-to-date info via ConfigureEmailOptions. * * - After that, we call ReloadAsync on the ITemplatedEmailSender so it can update its connection. * */ // This will cause all IConfigureOptions to be ran on the new values. var upToDateConfig = this.HttpContext.RequestServices.GetRequiredService <IOptionsSnapshot <EmailSenderConfig> >().Value; try { email.ReloadAsync(upToDateConfig).Wait(); } catch (Exception ex) { settings.EmailError = ex.Message; return(this.View(VIEW_SETTINGS, settings)); } return(this.RedirectToAction("Settings")); }
public ActionResult SaveSettings() { List <AdminSettingsViewModel> savedSettings = new List <AdminSettingsViewModel>(); AdminSettingsViewModel techInterview1 = new AdminSettingsViewModel(); techInterview1.Id = 1; techInterview1.EmailTimer = int.Parse(Request.Form["EmailTimer1"]); techInterview1.FeedbackMessage = Request.Form["FeedbackMessage1"]; techInterview1.ReminderMessage = Request.Form["ReminderMessage1"]; if (Request.Form["ReminderCheck1"] != null) { techInterview1.EnableReminder = int.Parse(Request.Form["Reminder1"]); } else { techInterview1.EnableReminder = 0; } savedSettings.Add(techInterview1); AdminSettingsViewModel techInterview2 = new AdminSettingsViewModel(); techInterview2.Id = 2; techInterview2.EmailTimer = int.Parse(Request.Form["EmailTimer2"]); techInterview2.FeedbackMessage = Request.Form["FeedbackMessage2"]; techInterview2.ReminderMessage = Request.Form["ReminderMessage2"]; if (Request.Form["ReminderCheck2"] != null) { techInterview2.EnableReminder = int.Parse(Request.Form["Reminder2"]); } else { techInterview2.EnableReminder = 0; } savedSettings.Add(techInterview2); if (EvaluationAdmin.SetAdminSettings(savedSettings)) { MessageViewModel success = new MessageViewModel(); success.Type = MessageType.Success; success.Content = "Settings Saved Sucessfully"; success.Title = "Success"; TempData["Message"] = success; } return(RedirectToAction("Admin")); }
public override async Task <IDisplayResult> UpdateAsync(AdminSettings settings, BuildEditorContext context) { var user = _httpContextAccessor.HttpContext?.User; if (!await _authorizationService.AuthorizeAsync(user, PermissionsAdminSettings.ManageAdminSettings)) { return(null); } if (context.GroupId == GroupId) { var model = new AdminSettingsViewModel(); await context.Updater.TryUpdateModelAsync(model, Prefix); settings.DisplayMenuFilter = model.DisplayMenuFilter; } return(await EditAsync(settings, context)); }
private bool ValidateAkismetSettings(AdminSettingsViewModel adminSettingsViewModel) { if (!adminSettingsViewModel.AkismetEnabled) { return(true); } Uri url; if (string.IsNullOrEmpty(adminSettingsViewModel.AkismetUrl) || !Uri.TryCreate(adminSettingsViewModel.AkismetUrl, UriKind.Absolute, out url)) { ModelState.AddModelError("Akismet_Url", "Akismet url entered is invalid"); return(false); } if (string.IsNullOrEmpty(adminSettingsViewModel.AkismetKey)) { ModelState.AddModelError("Akismet_Key", "Akismet key entered is invalid"); return(false); } return(true); }
public static List <AdminSettingsViewModel> GetAdminSettings() { List <AdminSettingsViewModel> result = new List <AdminSettingsViewModel>(); using (var dbContext = new AARPDbContext()) { var settings = dbContext.AdminSettings.ToList(); if (settings.Count == 0) { var techSettings1 = new AdminSettingsViewModel { Id = 1, }; result.Add(techSettings1); var techSettings2 = new AdminSettingsViewModel { Id = 2, }; result.Add(techSettings2); } else { var techSettings1 = settings.Where(x => x.Id == 1).FirstOrDefault(); if (techSettings1 != null) { var techSettings1VM = new AdminSettingsViewModel() { Id = 1, EmailTimer = techSettings1.EmailTimer, FeedbackMessage = techSettings1.FeedbackMessage, EnableReminder = techSettings1.ReminderID, ReminderMessage = techSettings1.ReminderMessage }; result.Add(techSettings1VM); } else { var techSettings1VM = new AdminSettingsViewModel() { Id = 1, }; result.Add(techSettings1VM); } var techSettings2 = settings.Where(x => x.Id == 2).FirstOrDefault(); if (techSettings2 != null) { var techSettings2VM = new AdminSettingsViewModel() { Id = 2, EmailTimer = techSettings2.EmailTimer, FeedbackMessage = techSettings2.FeedbackMessage, EnableReminder = techSettings2.ReminderID, ReminderMessage = techSettings2.ReminderMessage }; result.Add(techSettings2VM); } else { var techSettings2VM = new AdminSettingsViewModel() { Id = 2, }; result.Add(techSettings2VM); } } } return(result); }