public override IEnumerable <AuthenticationDescription> GetExternalAuthenticationSchemes() { //log.LogInformation("GetExternalAuthenticationSchemes called"); //https://github.com/aspnet/HttpAbstractions/blob/dev/src/Microsoft.AspNet.Http.Abstractions/Authentication/AuthenticationManager.cs //https://github.com/aspnet/HttpAbstractions/blob/dev/src/Microsoft.AspNet.Http/Authentication/DefaultAuthenticationManager.cs IEnumerable <AuthenticationDescription> all = context.Authentication.GetAuthenticationSchemes().Where(d => !string.IsNullOrEmpty(d.DisplayName)); if (multiTenantOptions.Mode != MultiTenantMode.None) { // here we need to filter the list to ones configured for the current tenant if (multiTenantOptions.Mode == MultiTenantMode.FolderName) { if (multiTenantOptions.UseRelatedSitesMode) { ISiteSettings site = siteRepo.FetchNonAsync(multiTenantOptions.RelatedSiteId); return(BuildFilteredAuthList(site, all)); } } return(BuildFilteredAuthList(SiteUserManager.Site, all)); } return(all); //return context.Authentication.GetAuthenticationSchemes(); }
/// <summary> /// tries to return a site with a matching folder, if not found returns the default site /// </summary> /// <param name="folderName"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <ISiteSettings> FetchByFolderName( string folderName, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); cancellationToken.ThrowIfCancellationRequested(); ISiteSettings site = null; if (!string.IsNullOrEmpty(folderName) && folderName != "root") { site = await dbContext.Sites .AsNoTracking() .FirstOrDefaultAsync(x => x.SiteFolderName == folderName , cancellationToken) .ConfigureAwait(false); } if (site == null) { //var query = from s in dbContext.Sites // where string.IsNullOrEmpty(s.SiteFolderName) // orderby s.CreatedUtc ascending // select s; site = await dbContext.Sites .AsNoTracking() .Where(x => string.IsNullOrEmpty(x.SiteFolderName)) .OrderBy(x => x.CreatedUtc) .FirstOrDefaultAsync(cancellationToken) .ConfigureAwait(false); } return(site); }
public async Task Update( ISiteSettings site, CancellationToken cancellationToken = default(CancellationToken)) { if (site == null) { throw new ArgumentException("site must not be null"); } if (site.Id == Guid.Empty) { throw new ArgumentException("site must have a non-empty Id"); } var siteSettings = SiteSettings.FromISiteSettings(site); bool tracking = dbContext.ChangeTracker.Entries <SiteSettings>().Any(x => x.Entity.Id == siteSettings.Id); if (!tracking) { dbContext.Sites.Update(siteSettings); } int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken) .ConfigureAwait(false); }
public async Task Update(ISiteSettings site) { await eventHandlers.HandleSitePreUpdate(site.Id).ConfigureAwait(false); dataProtector.Protect(site); if (site.Id == Guid.Empty) { site.Id = Guid.NewGuid(); await commands.Update(site, CancellationToken.None); } else { await commands.Update(site, CancellationToken.None); } if (multiTenantOptions.Mode == MultiTenantMode.FolderName) { if (string.IsNullOrEmpty(site.SiteFolderName)) { cacheHelper.ClearCache("root"); } else { cacheHelper.ClearCache(site.SiteFolderName); } } else { if (_context != null && !string.IsNullOrEmpty(_context.Request.Host.Value)) { cacheHelper.ClearCache(_context.Request.Host.Value); } } await eventHandlers.HandleSiteUpdated(site).ConfigureAwait(false); }
async Task <ISiteSettings> SiteSettingsUpdated(ISiteSettings settings) { if (settings == null) { return(settings); } var stepToUpdate = DefaultSteps.GeneralSettings;; // We need a step to update if (stepToUpdate == null) { return(settings); } // Update step var step = await _tourDescriptorStore.GetStepAsync(stepToUpdate.Id); if (step != null) { if (!step.CompletedDate.HasValue) { step.CompletedDate = DateTimeOffset.Now; await _tourDescriptorStore.UpdateStepAsync(step); } } // Return return(settings); }
public virtual async Task <SiteContext> ResolveSite( string hostName, string path, CancellationToken cancellationToken = default(CancellationToken) ) { var pathStartingSegment = path.StartingSegment(); ISiteSettings site = null; if (MultiTenantOptions.Mode == MultiTenantMode.FolderName) { if (string.IsNullOrWhiteSpace(pathStartingSegment)) { pathStartingSegment = "root"; } site = await SiteQueries.FetchByFolderName(pathStartingSegment, cancellationToken); } else { site = await SiteQueries.Fetch(hostName, cancellationToken); } if (site != null) { DataProtector.UnProtect(site); return(new SiteContext(site)); } return(null); }
public ISiteSettings FetchNonAsync(int siteId) { ISiteSettings site = siteRepo.FetchNonAsync(siteId); dataProtector.UnProtect(site); return(site); }
/// <summary> /// tries to return a site with a matching folder, if not found returns the default site /// </summary> /// <param name="folderName"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <ISiteSettings> FetchByFolderName( string folderName, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); cancellationToken.ThrowIfCancellationRequested(); ISiteSettings site = null; if (!string.IsNullOrEmpty(folderName) && folderName != "root") { site = await baseUnitOfWork.BaseWorkArea.SiteSettings.Query().AsNoTracking().FirstOrDefaultAsync( x => x.SiteFolderName == folderName , cancellationToken) .ConfigureAwait(false); } if (site == null) { var query = from s in baseUnitOfWork.BaseWorkArea.SiteSettings.Query() where string.IsNullOrEmpty(s.SiteFolderName) orderby s.CreatedUtc ascending select s; site = await query.Take(1) .AsNoTracking() .SingleOrDefaultAsync <SiteSettings>(cancellationToken) .ConfigureAwait(false); } return(site); }
//public int GetSiteIdByFolderNonAsync(string folderName) //{ // return siteRepo.GetSiteIdByFolderNonAsync(folderName); //} public async Task <ISiteSettings> Fetch(Guid siteGuid) { ISiteSettings site = await siteRepo.Fetch(siteGuid, CancellationToken); dataProtector.UnProtect(site); return(site); }
/// <summary> /// tries to return a site with a matching folder, if not found returns the default site /// </summary> /// <param name="folderName"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <ISiteSettings> FetchByFolderName( string folderName, CancellationToken cancellationToken = default(CancellationToken)) { ISiteSettings site = null; if (!string.IsNullOrEmpty(folderName) && folderName != "root") { site = await dbContext.Sites.AsNoTracking().FirstOrDefaultAsync( x => x.SiteFolderName == folderName , cancellationToken) .ConfigureAwait(false); } if (site == null) { var query = from s in dbContext.Sites where string.IsNullOrEmpty(s.SiteFolderName) orderby s.CreatedUtc ascending select s; site = await query.Take(1) .AsNoTracking() .SingleOrDefaultAsync <SiteSettings>(cancellationToken) .ConfigureAwait(false); } return(site); }
public async Task <bool> Delete(ISiteSettings site) { // we will need a provider model or something similar here to // allow other features and 3rd party features to delete // related data when a site is deleted // TODO: implement // will ProviderModel be available in Core Framework or will we have to use something else // a way to use dependency injection? // delete users bool resultStep = await userRepo.DeleteUsersBySite(site.SiteId, CancellationToken.None); // this also deletes userroles claims logins resultStep = await userRepo.DeleteRolesBySite(site.SiteId, CancellationToken.None); resultStep = await siteRepo.DeleteHostsBySite(site.SiteId, CancellationToken.None); //resultStep = await siteRepo.DeleteFoldersBySite(site.SiteGuid, CancellationToken.None); // the below method deletes a lot of things by siteid including the following tables // Exec mp_Sites_Delete // mp_UserRoles // mp_UserProperties // mp_UserLocation // mp_Users // mp_Roles // mp_SiteHosts // mp_SiteFolders // mp_SiteSettingsEx // mp_Sites return(await siteRepo.Delete(site.SiteId, CancellationToken.None)); }
protected virtual async Task <AuthenticationTicket> CreateTicketAsync( ClaimsIdentity identity, AuthenticationProperties properties, AccessToken token) { log.LogDebug("CreateTicketAsync called tokens.ScreenName was " + token.ScreenName); var context = new TwitterCreatingTicketContext(Context, token.UserId, token.ScreenName, token.Token, token.TokenSecret) { Principal = new ClaimsPrincipal(identity), Properties = properties }; await Options.Events.CreatingTicket(context); if (context.Principal?.Identity == null) { return(null); } ISiteSettings site = siteResolver.Resolve(); if (site != null) { Claim siteGuidClaim = new Claim("SiteGuid", site.SiteGuid.ToString()); if (!identity.HasClaim(siteGuidClaim.Type, siteGuidClaim.Value)) { identity.AddClaim(siteGuidClaim); } } //return new AuthenticationTicket(notification.Principal, notification.Properties, Options.AuthenticationScheme); return(new AuthenticationTicket(context.Principal, context.Properties, AuthenticationScheme.External)); }
private async Task <TenantContext <SiteSettings> > ResolveByFolderAsync(HttpContext context) { var siteFolderName = context.Request.Path.StartingSegment(); if (siteFolderName.Length == 0) { siteFolderName = "root"; } TenantContext <SiteSettings> tenantContext = null; CancellationToken cancellationToken = context?.RequestAborted ?? CancellationToken.None; ISiteSettings site = await siteRepo.FetchByFolderName(siteFolderName, cancellationToken); if (site != null) { dataProtector.UnProtect(site); tenantContext = new TenantContext <SiteSettings>((SiteSettings)site); } return(tenantContext); }
/// <summary> /// tries to return a site with a matching folder, if not found returns the default site /// </summary> /// <param name="folderName"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <ISiteSettings> FetchByFolderName( string folderName, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ISiteSettings site = null; using (var _db = _contextFactory.CreateContext()) { if (!string.IsNullOrEmpty(folderName) && folderName != "root") { site = await _db.Sites .AsNoTracking() .FirstOrDefaultAsync(x => x.SiteFolderName == folderName , cancellationToken) .ConfigureAwait(false); } if (site == null) { site = await _db.Sites .AsNoTracking() .Where(x => string.IsNullOrEmpty(x.SiteFolderName)) .OrderBy(x => x.CreatedUtc) .FirstOrDefaultAsync(cancellationToken) .ConfigureAwait(false); } return(site); } }
public async Task Update( ISiteSettings site, CancellationToken cancellationToken = default(CancellationToken)) { if (site == null) { throw new ArgumentException("site must not be null"); } if (site.Id == Guid.Empty) { throw new ArgumentException("site must have a non-empty Id"); } ThrowIfDisposed(); cancellationToken.ThrowIfCancellationRequested(); await EnsureProjectId().ConfigureAwait(false); var siteSettings = SiteSettings.FromISiteSettings(site); await commands.UpdateAsync(projectId, siteSettings.Id.ToString(), siteSettings, cancellationToken).ConfigureAwait(false); }
public async Task <bool> CreateNewSite(ISiteSettings newSite) { if (siteRepo == null) { throw new ArgumentNullException("you must pass in an instance of ISiteRepository"); } if (newSite == null) { throw new ArgumentNullException("you must pass in an instance of ISiteSettings"); } if (newSite.SiteGuid != Guid.Empty) { throw new ArgumentException("newSite should not already have a site guid"); } //string templateFolderPath = GetMessageTemplateFolder(); //string templateFolder = templateFolderPath; //SiteSettings newSite = new SiteSettings(); newSite.Layout = setupOptions.DefaultLayout; // TODO: more configurable options? bool result = await siteRepo.Save(newSite, CancellationToken.None); return(result); }
public EmailFriendController( ITextTranslator textTranslator, ISiteRootContext siteRootContext, IEmailFactory emailFactory, IEmailSender emailSender, IHtmlEmailTemplateFactory htmlEmailTemplateFactory, ISiteSettings siteSettings, ILog logger, IGlobalSitecoreService globalService, IArticleSearch articleSearch, IArticleService articleService, IRecaptchaService recaptchaService) { EmailSender = emailSender; HtmlEmailTemplateFactory = htmlEmailTemplateFactory; TextTranslator = textTranslator; SiteRootContext = siteRootContext; EmailFactory = emailFactory; SiteSettings = siteSettings; _logger = logger; GlobalService = globalService; ArticleSearch = articleSearch; ArticleService = articleService; RecaptchaService = recaptchaService; }
public async Task SendSecurityCodeEmailAsync( ISiteSettings siteSettings, string toAddress, string subject, string securityCode) { SmtpOptions smtpOptions = GetSmptOptions(siteSettings); string plainTextTemplate = templateService.GetPlainTextTemplate(MessagePurpose.SendSecurityCode, ""); string plainTextMessage = string.Format(plainTextTemplate, securityCode); string htmlTemplate = templateService.GetHtmlTemplate(MessagePurpose.SendSecurityCode, ""); string htmlMessage = string.Format(htmlTemplate, securityCode); EmailSender sender = new EmailSender(); await sender.SendEmailAsync( smtpOptions, toAddress, siteSettings.DefaultEmailFromAddress, subject, plainTextMessage, htmlMessage); }
public async Task <ISiteSettings> Fetch(string hostname) { ISiteSettings site = await siteRepo.Fetch(hostname, CancellationToken); dataProtector.UnProtect(site); return(site); }
//private string requiredSiteFolder; //public SiteFolderRouteConstraint(string folderParam) //{ // requiredSiteFolder = folderParam; //} public bool Match( HttpContext httpContext, IRouter route, string parameterName, IDictionary <string, object> values, RouteDirection routeDirection) { string requestFolder = RequestSiteResolver.GetFirstFolderSegment(httpContext.Request.Path); //return string.Equals(requiredSiteFolder, requestFolder, StringComparison.CurrentCultureIgnoreCase); ISiteResolver siteResolver = httpContext.ApplicationServices.GetService <ISiteResolver>(); if (siteResolver != null) { try { // exceptions expected here until db install scripts have run or if db connection error ISiteSettings site = siteResolver.Resolve(); if ((site != null) && (site.SiteFolderName == requestFolder)) { return(true); } } catch { // do we need to log this? } } return(false); }
public async Task<bool> Delete(ISiteSettings site) { // we will need a provider model or something similar here to // allow other features and 3rd party features to delete // related data when a site is deleted // TODO: implement // will ProviderModel be available in Core Framework or will we have to use something else // a way to use dependency injection? // delete users bool resultStep = await userRepo.DeleteClaimsBySite(site.SiteId); resultStep = await userRepo.DeleteLoginsBySite(site.SiteId); // the below method deletes a lot of things by siteid including the following tables // Exec mp_Sites_Delete // mp_UserRoles // mp_UserProperties // mp_UserLocation // mp_Users // mp_Roles // mp_SiteHosts // mp_SiteFolders // mp_RedirectList // mp_TaskQueue // mp_SiteSettingsEx // mp_Sites return await siteRepo.Delete(site.SiteId); }
public async Task Update(ISiteSettings site) { dataProtector.Protect(site); if (site.Id == 0) { await commands.Update(site, CancellationToken.None); } else { await commands.Update(site, CancellationToken.None); } if (multiTenantOptions.Mode == MultiTenantMode.FolderName) { if (string.IsNullOrEmpty(site.SiteFolderName)) { cacheHelper.ClearCache("root"); } else { cacheHelper.ClearCache(site.SiteFolderName); } } else { if (_context != null && !string.IsNullOrEmpty(_context.Request.Host.Value)) { cacheHelper.ClearCache(_context.Request.Host.Value); } } }
private TwilioSmsCredentials GetCredentials(ISiteSettings site) { if (site == null) { return(null); } if (string.IsNullOrEmpty(site.SmsClientId)) { return(null); } if (string.IsNullOrEmpty(site.SmsSecureToken)) { return(null); } if (string.IsNullOrEmpty(site.SmsFrom)) { return(null); } TwilioSmsCredentials creds = new TwilioSmsCredentials(); creds.AccountSid = site.SmsClientId; creds.AuthToken = site.SmsSecureToken; creds.FromNumber = site.SmsFrom; return(creds); }
public async Task Delete(ISiteSettings site) { await _eventHandlers.HandleSitePreDelete(site.Id).ConfigureAwait(false); // delete users await _userCommands.DeleteUsersBySite(site.Id, CancellationToken.None); // this also deletes userroles claims logins await _userCommands.DeleteRolesBySite(site.Id, CancellationToken.None); await _commands.DeleteHostsBySite(site.Id, CancellationToken.None); //resultStep = await siteRepo.DeleteFoldersBySite(site.SiteGuid, CancellationToken.None); // the below method deletes a lot of things by siteid including the following tables // Exec mp_Sites_Delete // mp_UserRoles // mp_UserProperties // mp_UserLocation // mp_Users // mp_Roles // mp_SiteHosts // mp_SiteFolders // mp_SiteSettingsEx // mp_Sites await _commands.Delete(site.Id, CancellationToken.None); _cacheHelper.ClearCache("folderList"); }
public async Task Delete(ISiteSettings site) { // delete users //await userCommands.DeleteUsersBySite(site.Id, CancellationToken.None); // this also deletes userroles claims logins //await userCommands.DeleteRolesBySite(site.Id, CancellationToken.None); await commands.DeleteHostsBySite(site.Id, CancellationToken.None); //resultStep = await siteRepo.DeleteFoldersBySite(site.Sitelong, CancellationToken.None); // the below method deletes a lot of things by siteid including the following tables // Exec mp_Sites_Delete // mp_UserRoles // mp_UserProperties // mp_UserLocation // mp_Users // mp_Roles // mp_SiteHosts // mp_SiteFolders // mp_SiteSettingsEx // mp_Sites await commands.Delete(site.Id, CancellationToken.None); cacheHelper.ClearCache("folderList"); }
// need custom NoDb logic for option to lookup across projects public async Task <ISiteSettings> FetchByFolderName( string folderName, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); //await EnsureProjectId().ConfigureAwait(false); var projectId = "default"; var allSites = await queries.GetAllAsync(projectId, cancellationToken).ConfigureAwait(false); ISiteSettings site = null; if (!string.IsNullOrEmpty(folderName) && folderName != "root") { site = allSites.Where( x => x.SiteFolderName == folderName ).SingleOrDefault(); } if (site == null) { var query = from s in allSites where string.IsNullOrEmpty(s.SiteFolderName) orderby s.CreatedUtc ascending select s; site = query.Take(1).SingleOrDefault(); } return(site); }
public async Task <ISiteSettings> SaveAsync(ISiteSettings siteSettings) { // Automatically generate an API key if one is not supplied if (String.IsNullOrWhiteSpace(siteSettings.ApiKey)) { siteSettings.ApiKey = _keyGenerator.GenerateKey(); } // Use default homepage route if a default route is not explicitly specified if (siteSettings.HomeRoute == null) { siteSettings.HomeRoute = new HomeRoute(); } // Update settings var settings = await _dictionaryStore.UpdateAsync <SiteSettings>(Key, siteSettings); if (settings != null) { if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation($"Settings for site '{settings.SiteName}' updated successfully"); } // Expire cache _cacheManager.CancelTokens(this.GetType(), Key); } return(settings); }
public async Task <ActionResult> SiteDelete(Guid siteGuid, int siteId, int returnPageNumber = 1) { bool result = false; ISiteSettings selectedSite = await siteManager.Fetch(siteGuid); if ( (selectedSite != null) && (selectedSite.SiteId == siteId) ) { if (selectedSite.IsServerAdminSite) { this.AlertWarning(string.Format( "The site <b>{0}</b> was not deleted because it is a server admin site.", selectedSite.SiteName) , true); return(RedirectToAction("SiteList", new { pageNumber = returnPageNumber })); } result = await siteManager.Delete(selectedSite); } if (result && (selectedSite != null)) { this.AlertWarning(string.Format( "The site <b>{0}</b> was successfully deleted.", selectedSite.SiteName) , true); } return(RedirectToAction("SiteList", new { pageNumber = returnPageNumber })); }
private async Task <ISiteSettings> GetSite() { if (multiTenantOptions.UseRelatedSitesMode) { if (multiTenantOptions.Mode == MultiTenantMode.FolderName) { CancellationToken cancellationToken = contextAccessor.HttpContext?.RequestAborted ?? CancellationToken.None; site = await siteRepo.Fetch(multiTenantOptions.RelatedSiteId, cancellationToken); return(site); } } TenantContext <SiteSettings> tenantContext = await siteResolver.ResolveAsync(contextAccessor.HttpContext); if (tenantContext != null && tenantContext.Tenant != null) { site = tenantContext.Tenant; } return(site); }
public ISiteSettings FetchNonAsync(string host) { ISiteSettings site = siteRepo.FetchNonAsync(host); dataProtector.UnProtect(site); return(site); }
public async Task <bool> CreateAdminUser(ISiteSettings site) { ISiteRole adminRole = await userRepo.FetchRole(site.SiteId, "Admins", CancellationToken); if (adminRole == null) { throw new InvalidOperationException("Admins role could nto be found so cannot create admin user"); } // if using related sites mode there is a problem if we already have user [email protected] // and we create another one in the child site with the same email and login so we need to make it different // we could just skip creating this user since in related sites mode all users come from the first site // but then if the config were changed to not related sites mode there would be no admin user // so in related sites mode we create one only as a backup in case settings are changed later int countOfSites = await siteRepo.GetCount(CancellationToken); string siteDifferentiator = string.Empty; if ( (countOfSites >= 1) && (multiTenantOptions.UseRelatedSitesMode) ) { if (site.SiteId > 1) { siteDifferentiator = site.SiteId.ToInvariantString(); } } SiteUser adminUser = new SiteUser(); adminUser.SiteId = site.SiteId; adminUser.SiteGuid = site.SiteGuid; adminUser.Email = "admin" + siteDifferentiator + "@admin.com"; adminUser.NormalizedEmail = adminUser.Email; adminUser.DisplayName = "Admin"; adminUser.UserName = "******" + siteDifferentiator; adminUser.EmailConfirmed = true; adminUser.AccountApproved = true; // clear text password will be hashed upon login // this format allows migrating from mojoportal adminUser.PasswordHash = "admin||0"; //pwd/salt/format bool result = await userRepo.Save(adminUser, CancellationToken.None); result = await userRepo.AddUserToRole( adminRole.RoleId, adminRole.RoleGuid, adminUser.UserId, adminUser.UserGuid, CancellationToken.None); return(result); }
public async Task <bool> EnsureRequiredRoles(ISiteSettings site) { bool result = true; bool exists = await userRepo.RoleExists(site.SiteId, "Admins", CancellationToken); if (!exists) { SiteRole adminRole = new SiteRole(); adminRole.DisplayName = "Admins"; //adminRole.DisplayName = "Administrators"; adminRole.SiteId = site.SiteId; adminRole.SiteGuid = site.SiteGuid; result = await userRepo.SaveRole(adminRole, CancellationToken.None); adminRole.DisplayName = "Administrators"; result = await userRepo.SaveRole(adminRole, CancellationToken.None); } exists = await userRepo.RoleExists(site.SiteId, "Role Admins", CancellationToken); if (!exists) { SiteRole roleAdminRole = new SiteRole(); roleAdminRole.DisplayName = "Role Admins"; roleAdminRole.SiteId = site.SiteId; roleAdminRole.SiteGuid = site.SiteGuid; result = await userRepo.SaveRole(roleAdminRole, CancellationToken.None); roleAdminRole.DisplayName = "Role Administrators"; result = await userRepo.SaveRole(roleAdminRole, CancellationToken.None); } exists = await userRepo.RoleExists(site.SiteId, "Content Administrators", CancellationToken); if (!exists) { SiteRole contentAdminRole = new SiteRole(); contentAdminRole.DisplayName = "Content Administrators"; contentAdminRole.SiteId = site.SiteId; contentAdminRole.SiteGuid = site.SiteGuid; result = await userRepo.SaveRole(contentAdminRole, CancellationToken.None); } exists = await userRepo.RoleExists(site.SiteId, "Authenticated Users", CancellationToken); if (!exists) { SiteRole authenticatedUserRole = new SiteRole(); authenticatedUserRole.DisplayName = "Authenticated Users"; authenticatedUserRole.SiteId = site.SiteId; authenticatedUserRole.SiteGuid = site.SiteGuid; result = await userRepo.SaveRole(authenticatedUserRole, CancellationToken.None); } return(result); }
public static RedirectResult RedirectToSiteRoot(this Controller controller, ISiteSettings site) { if(site.SiteFolderName.Length > 0) { return controller.Redirect("/" + site.SiteFolderName); } return controller.Redirect("/"); }
public async Task<bool> Save(ISiteSettings site) { if(site == null) { return false; } SiteSettings siteSettings = SiteSettings.FromISiteSettings(site); dbContext.Sites.Add(siteSettings); int rowsAffected = await dbContext.SaveChangesAsync(); return rowsAffected > 0; }
public MultiTenantTwitterOptionsResolver( TwitterOptions originalOptions, ISiteSettings currentSite, MultiTenantOptions multiTenantOptions) { this.originalOptions = originalOptions; //this.siteResolver = siteResolver; site = currentSite; this.multiTenantOptions = multiTenantOptions; //siteRepo = siteRepository; }
private SmtpOptions GetSmptOptions(ISiteSettings siteSettings) { SmtpOptions smtpOptions = new SmtpOptions(); smtpOptions.Password = siteSettings.SmtpPassword; smtpOptions.Port = siteSettings.SmtpPort; smtpOptions.PreferredEncoding = siteSettings.SmtpPreferredEncoding; smtpOptions.RequiresAuthentication = siteSettings.SmtpRequiresAuth; smtpOptions.Server = siteSettings.SmtpServer; smtpOptions.User = siteSettings.SmtpUser; smtpOptions.UseSsl = siteSettings.SmtpUseSsl; return smtpOptions; }
public MultiTenantGoogleOptionsResolver( GoogleOptions originalOptions, //ISiteResolver siteResolver, //ISiteRepository siteRepository, ISiteSettings currentSite, MultiTenantOptions multiTenantOptions) { this.originalOptions = originalOptions; //this.siteResolver = siteResolver; this.multiTenantOptions = multiTenantOptions; //siteRepo = siteRepository; site = currentSite; }
public async Task Create( ISiteSettings site, CancellationToken cancellationToken = default(CancellationToken)) { if (site == null) throw new ArgumentException("site must not be null"); if (site.Id == Guid.Empty) throw new ArgumentException("site must have a non-empty Id"); var siteSettings = SiteSettings.FromISiteSettings(site); dbContext.Sites.Add(siteSettings); int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken) .ConfigureAwait(false); }
public MultiTenantMicrosoftOptionsResolver( MicrosoftAccountOptions originalOptions, //ISiteResolver siteResolver, //ISiteRepository siteRepository, ISiteSettings currentSite, MultiTenantOptions multiTenantOptions) { this.originalOptions = originalOptions; //this.siteResolver = siteResolver; site = currentSite; this.multiTenantOptions = multiTenantOptions; //siteRepo = siteRepository; }
public static void RegisterLoggingSources(IEnumerable<EventSource> logSources, ISiteSettings settings) { var logListener = new ObservableEventListener(); foreach (var logSource in logSources) { logListener.EnableEvents( logSource, EventLevel.LogAlways, Keywords.All); } logListener.LogToFlatFile( fileName: settings.LogFilePath, formatter: new EventTextFormatter()); }
private TwilioSmsCredentials GetCredentials(ISiteSettings site) { if(site == null) { return null; } if(string.IsNullOrEmpty(site.SmsClientId)) { return null; } if (string.IsNullOrEmpty(site.SmsSecureToken)) { return null; } if (string.IsNullOrEmpty(site.SmsFrom)) { return null; } TwilioSmsCredentials creds = new TwilioSmsCredentials(); creds.AccountSid = site.SmsClientId; creds.AuthToken = site.SmsSecureToken; creds.FromNumber = site.SmsFrom; return creds; }
public MultiTenantFacebookOptionsResolver( FacebookOptions originalOptions, //ISiteResolver siteResolver, //IHttpContextAccessor contextAccessor, //ITenantResolver<SiteSettings> siteResolver, ISiteSettings currentSite, //ISiteRepository siteRepository, MultiTenantOptions multiTenantOptions) { this.originalOptions = originalOptions; //this.siteResolver = siteResolver; //this.contextAccessor = contextAccessor; this.multiTenantOptions = multiTenantOptions; //siteRepo = siteRepository; site = currentSite; }
public async Task Update( ISiteSettings site, CancellationToken cancellationToken = default(CancellationToken)) { if (site == null) throw new ArgumentException("site must not be null"); if (site.Id == Guid.Empty) throw new ArgumentException("site must have a non-empty Id"); var siteSettings = SiteSettings.FromISiteSettings(site); bool tracking = dbContext.ChangeTracker.Entries<SiteSettings>().Any(x => x.Entity.Id == siteSettings.Id); if (!tracking) { dbContext.Sites.Update(siteSettings); } int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken) .ConfigureAwait(false); }
public async Task Update( ISiteSettings site, CancellationToken cancellationToken = default(CancellationToken)) { if (site == null) throw new ArgumentException("site must not be null"); if (site.Id == Guid.Empty) throw new ArgumentException("site must have a non-empty Id"); ThrowIfDisposed(); cancellationToken.ThrowIfCancellationRequested(); //await EnsureProjectId().ConfigureAwait(false); var siteSettings = SiteSettings.FromISiteSettings(site); var projectId = siteSettings.Id.ToString(); await commands.UpdateAsync( projectId, siteSettings.Id.ToString(), siteSettings, cancellationToken).ConfigureAwait(false); }
public async Task<bool> Save( ISiteSettings site, CancellationToken cancellationToken = default(CancellationToken)) { if(site == null) { return false; } SiteSettings siteSettings = SiteSettings.FromISiteSettings(site); if (siteSettings.SiteId == -1) // a newly created item { siteSettings.SiteId = 0; //EF needs this to be 0 in order to generate it from the db identity if(siteSettings.SiteGuid == Guid.Empty) { siteSettings.SiteGuid = Guid.NewGuid(); } dbContext.Sites.Add(siteSettings); } else { bool tracking = dbContext.ChangeTracker.Entries<SiteSettings>().Any(x => x.Entity.SiteId == siteSettings.SiteId); if (!tracking) { dbContext.Sites.Update(siteSettings); } } int rowsAffected = await dbContext.SaveChangesAsync(cancellationToken) .ConfigureAwait(false); // update the original with the new keys after insert if((site.SiteId == -1)&&(siteSettings != null)) { site.SiteId = siteSettings.SiteId; site.SiteGuid = siteSettings.SiteGuid; } return rowsAffected > 0; }
public async Task SendPasswordResetEmailAsync( ISiteSettings siteSettings, string toAddress, string subject, string resetUrl) { SmtpOptions smtpOptions = GetSmptOptions(siteSettings); string plainTextTemplate = templateService.GetPlainTextTemplate(MessagePurpose.PasswordReset, CultureInfo.CurrentUICulture.Name); string plainTextMessage = string.Format(plainTextTemplate, resetUrl); string htmlTemplate = templateService.GetHtmlTemplate(MessagePurpose.PasswordReset, CultureInfo.CurrentUICulture.Name); string htmlMessage = string.Format(htmlTemplate, resetUrl); EmailSender sender = new EmailSender(); await sender.SendEmailAsync( smtpOptions, toAddress, siteSettings.DefaultEmailFromAddress, subject, plainTextMessage, htmlMessage); }
public async Task SendAccountConfirmationEmailAsync( ISiteSettings siteSettings, string toAddress, string subject, string confirmationUrl) { SmtpOptions smtpOptions = GetSmptOptions(siteSettings); if(smtpOptions == null) { var logMessage = $"failed to send account confirmation email because smtp settings are not populated for site {siteSettings.SiteName}"; log.LogError(logMessage); return; } string plainTextTemplate = templateService.GetPlainTextTemplate(MessagePurpose.ConfirmAccount, CultureInfo.CurrentUICulture.Name); string plainTextMessage = string.Format(plainTextTemplate, confirmationUrl); string htmlTemplate = templateService.GetHtmlTemplate(MessagePurpose.ConfirmAccount, CultureInfo.CurrentUICulture.Name); string htmlMessage = string.Format(htmlTemplate, confirmationUrl); EmailSender sender = new EmailSender(); try { await sender.SendEmailAsync( smtpOptions, toAddress, siteSettings.DefaultEmailFromAddress, subject, plainTextMessage, htmlMessage).ConfigureAwait(false); } catch (Exception ex) { log.LogError("error sending account confirmation email", ex); } }
public async Task SendSmsAsync( ISiteSettings site, string phoneNumber, string message) { if (string.IsNullOrEmpty(phoneNumber)) { throw new ArgumentException("toPhoneNumber was not provided"); } if (string.IsNullOrEmpty(message)) { throw new ArgumentException("message was not provided"); } var credentials = GetCredentials(site); if(credentials == null) { log.LogError("tried to send sms message with no credentials"); return; } TwilioSmsSender sender = new TwilioSmsSender(log); try { await sender.SendMessage( credentials, phoneNumber, message).ConfigureAwait(false); } catch (Exception ex) { log.LogError("error sending twilio message", ex); } }
public HomeController(IConferenceRepository conferenceRepository, IOptions<SiteSettings> siteSettingsAccessor) { _conferenceRepository = conferenceRepository; _settings = siteSettingsAccessor.Value; }
public async Task<bool> EnsureSiteFolder(ISiteSettings site) { bool folderExists = await siteRepo.FolderExists(site.SiteFolderName); if (!folderExists) { List<SiteFolder> siteFolders = await siteRepo.GetSiteFoldersBySite(site.SiteGuid); //delete any existing folders before creating a new one foreach (SiteFolder f in siteFolders) { bool deleted = await siteRepo.DeleteFolder(f.Guid); } //ensure the current folder mapping SiteFolder folder = new SiteFolder(); folder.FolderName = site.SiteFolderName; folder.SiteGuid = site.SiteGuid; folderExists = await siteRepo.Save(folder); } return folderExists; }
public async Task<bool> Save(ISiteSettings site) { return await siteRepo.Save(site); }
public async Task<bool> CreateAdminUser(ISiteSettings site) { ISiteRole adminRole = await userRepo.FetchRole(site.SiteId, "Admins"); if(adminRole == null) { throw new InvalidOperationException("Admins role could nto be found so cannot create admin user"); } // if using related sites mode there is a problem if we already have user [email protected] // and we create another one in the child site with the same email and login so we need to make it different // we could just skip creating this user since in related sites mode all users come from the first site // but then if the config were changed to not related sites mode there would be no admin user // so in related sites mode we create one only as a backup in case settings are changed later int countOfSites = await siteRepo.GetCount(); string siteDifferentiator = string.Empty; if ( (countOfSites >= 1) && (multiTenantOptions.UseRelatedSitesMode) ) { if (site.SiteId > 1) { siteDifferentiator = site.SiteId.ToInvariantString(); } } SiteUser adminUser = new SiteUser(); adminUser.SiteId = site.SiteId; adminUser.SiteGuid = site.SiteGuid; adminUser.Email = "admin" + siteDifferentiator + "@admin.com"; adminUser.DisplayName = "Admin"; adminUser.UserName = "******" + siteDifferentiator; adminUser.EmailConfirmed = true; adminUser.AccountApproved = true; // clear text password will be hashed upon login // this format allows migrating from mojoportal adminUser.PasswordHash = "admin||0"; //pwd/salt/format bool result = await userRepo.Save(adminUser); result = await userRepo.AddUserToRole( adminRole.RoleId, adminRole.RoleGuid, adminUser.UserId, adminUser.UserGuid); return result; }
public async Task<bool> EnsureRequiredRoles(ISiteSettings site) { bool result = true; bool exists = await userRepo.RoleExists(site.SiteId, "Admins"); if(!exists) { SiteRole adminRole = new SiteRole(); adminRole.DisplayName = "Admins"; //adminRole.DisplayName = "Administrators"; adminRole.SiteId = site.SiteId; adminRole.SiteGuid = site.SiteGuid; result = await userRepo.SaveRole(adminRole); adminRole.DisplayName = "Administrators"; result = await userRepo.SaveRole(adminRole); } exists = await userRepo.RoleExists(site.SiteId, "Role Admins"); if (!exists) { SiteRole roleAdminRole = new SiteRole(); roleAdminRole.DisplayName = "Role Admins"; roleAdminRole.SiteId = site.SiteId; roleAdminRole.SiteGuid = site.SiteGuid; result = await userRepo.SaveRole(roleAdminRole); roleAdminRole.DisplayName = "Role Administrators"; result = await userRepo.SaveRole(roleAdminRole); } exists = await userRepo.RoleExists(site.SiteId, "Content Administrators"); if (!exists) { SiteRole contentAdminRole = new SiteRole(); contentAdminRole.DisplayName = "Content Administrators"; contentAdminRole.SiteId = site.SiteId; contentAdminRole.SiteGuid = site.SiteGuid; result = await userRepo.SaveRole(contentAdminRole); } exists = await userRepo.RoleExists(site.SiteId, "Authenticated Users"); if (!exists) { SiteRole authenticatedUserRole = new SiteRole(); authenticatedUserRole.DisplayName = "Authenticated Users"; authenticatedUserRole.SiteId = site.SiteId; authenticatedUserRole.SiteGuid = site.SiteGuid; result = await userRepo.SaveRole(authenticatedUserRole); } return result; }
public async Task<bool> Save(ISiteSettings site) { int passedInSiteId = site.SiteId; bool result = false; if (site.SiteId == -1) // new site { site.SiteGuid = Guid.NewGuid(); site.SiteId = await dbSiteSettings.Create( site.SiteGuid, site.SiteName, site.Layout, site.Logo, site.Icon, site.AllowNewRegistration, site.AllowUserSkins, site.AllowPageSkins, site.AllowHideMenuOnPages, site.UseSecureRegistration, site.UseSslOnAllPages, string.Empty, // legacy defaultPageKeywords string.Empty, // legacy defaultPageDescription string.Empty, // legacy defaultPageEncoding string.Empty, // legacy defaultAdditionalMetaTag site.IsServerAdminSite, site.UseLdapAuth, site.AutoCreateLdapUserOnFirstLogin, site.SiteLdapSettings.Server, site.SiteLdapSettings.Port, site.SiteLdapSettings.Domain, site.SiteLdapSettings.RootDN, site.SiteLdapSettings.UserDNKey, site.AllowUserFullNameChange, site.UseEmailForLogin, site.ReallyDeleteUsers, string.Empty, // legacy site.EditorSkin, string.Empty, // legacy site.DefaultFriendlyUrlPatternEnum, false, // legacy site.EnableMyPageFeature, site.EditorProviderName, string.Empty, // legacy site.DatePickerProvider, site.CaptchaProvider, site.RecaptchaPrivateKey, site.RecaptchaPublicKey, site.WordpressApiKey, site.MicrosoftClientId, site.MicrosoftClientSecret, site.AllowOpenIdAuth, false, //legacy site.AllowWindowsLiveAuth, site.GmapApiKey, site.AddThisDotComUsername, //apiKeyExtra2 site.GoogleAnalyticsAccountCode, //apiKeyExtra2 string.Empty, //legacy apiKeyExtra3 site.SiteFolderName, // legacy apiKeyExtra4 site.PreferredHostName, // legacy apiKeyExtra5 site.DisableDbAuth); result = site.SiteId > -1; } else { result = await dbSiteSettings.Update( site.SiteId, site.SiteName, site.Layout, site.Logo, site.Icon, site.AllowNewRegistration, site.AllowUserSkins, site.AllowPageSkins, site.AllowHideMenuOnPages, site.UseSecureRegistration, site.UseSslOnAllPages, string.Empty, // legacy defaultPageKeywords string.Empty, // legacy defaultPageDescription string.Empty, // legacy defaultPageEncoding string.Empty, // legacy defaultAdditionalMetaTag site.IsServerAdminSite, site.UseLdapAuth, site.AutoCreateLdapUserOnFirstLogin, site.SiteLdapSettings.Server, site.SiteLdapSettings.Port, site.SiteLdapSettings.Domain, site.SiteLdapSettings.RootDN, site.SiteLdapSettings.UserDNKey, site.AllowUserFullNameChange, site.UseEmailForLogin, site.ReallyDeleteUsers, string.Empty, // legacy site.EditorSkin, string.Empty, // legacy site.DefaultFriendlyUrlPatternEnum, false, // legacy site.EnableMyPageFeature, site.EditorProviderName, string.Empty, // legacy site.DatePickerProvider, site.CaptchaProvider, site.RecaptchaPrivateKey, site.RecaptchaPublicKey, site.WordpressApiKey, site.MicrosoftClientId, site.MicrosoftClientSecret, site.AllowOpenIdAuth, false, //legacy site.AllowWindowsLiveAuth, site.GmapApiKey, site.AddThisDotComUsername, //apiKeyExtra2 site.GoogleAnalyticsAccountCode, //apiKeyExtra2 string.Empty, //legacy apiKeyExtra3 site.SiteFolderName, // legacy apiKeyExtra4 site.PreferredHostName, // legacy apiKeyExtra5 site.DisableDbAuth); } if (!result) { return result; } // settings below stored as key value pairs in mp_SiteSettingsEx bool nextResult = await dbSiteSettingsEx.EnsureSettings(); List<ExpandoSetting> expandoProperties = GetExpandoProperties(passedInSiteId); //-1 on new sites to get the default values // update a local data table of expando properties if the value changed and mark the row dirty site.SetExpandoSettings(expandoProperties); // finally update the database only with properties in the table marked as dirty SaveExpandoProperties(site.SiteId, site.SiteGuid, expandoProperties); return result; }
public async Task<bool> CreateNewSite( ISiteSettings newSite) { if (siteRepo == null) { throw new ArgumentNullException("you must pass in an instance of ISiteRepository"); } if (newSite == null) { throw new ArgumentNullException("you must pass in an instance of ISiteSettings"); } if (newSite.SiteGuid != Guid.Empty) { throw new ArgumentException("newSite should not already have a site guid"); } //string templateFolderPath = GetMessageTemplateFolder(); //string templateFolder = templateFolderPath; //SiteSettings newSite = new SiteSettings(); newSite.Layout = setupOptions.DefaultLayout; newSite.AllowNewRegistration = true; newSite.AllowUserFullNameChange = false; newSite.AutoCreateLdapUserOnFirstLogin = true; newSite.ReallyDeleteUsers = true; newSite.LdapPort = 389; newSite.LdapRootDN = String.Empty; newSite.LdapServer = String.Empty; newSite.UseEmailForLogin = true; newSite.UseLdapAuth = false; newSite.UseSecureRegistration = false; newSite.UseSslOnAllPages = setupOptions.SslIsRequiredByWebServer; //0 = clear, 1= hashed, 2= encrypted //newSite.PasswordFormat = 1; newSite.RequiresQuestionAndAnswer = true; newSite.MaxInvalidPasswordAttempts = 10; newSite.PasswordAttemptWindowMinutes = 5; newSite.MinReqNonAlphaChars = 0; newSite.MinRequiredPasswordLength = 7; bool result = await siteRepo.Save(newSite); return result; }
public async Task<bool> CreateNewSite( ISiteSettings newSite) { if (siteRepo == null) { throw new ArgumentNullException("you must pass in an instance of ISiteRepository"); } if (newSite == null) { throw new ArgumentNullException("you must pass in an instance of ISiteSettings"); } if (newSite.SiteGuid != Guid.Empty) { throw new ArgumentException("newSite should not already have a site guid"); } //string templateFolderPath = GetMessageTemplateFolder(); //string templateFolder = templateFolderPath; //SiteSettings newSite = new SiteSettings(); newSite.Skin = setupOptions.DefaultInitialSkin; //newSite.Logo = GetMessageTemplate(templateFolder, "InitialSiteLogoContent.config"); newSite.AllowHideMenuOnPages = false; newSite.AllowNewRegistration = true; newSite.AllowPageSkins = false; newSite.AllowUserFullNameChange = false; newSite.AllowUserSkins = false; newSite.AutoCreateLdapUserOnFirstLogin = true; //newSite.DefaultFriendlyUrlPattern = SiteSettings.FriendlyUrlPattern.PageNameWithDotASPX; //newSite.EditorSkin = SiteSettings.ContentEditorSkin.normal; //newSite.EncryptPasswords = false; newSite.Icon = String.Empty; newSite.ReallyDeleteUsers = true; newSite.SiteLdapSettings.Port = 389; newSite.SiteLdapSettings.RootDN = String.Empty; newSite.SiteLdapSettings.Server = String.Empty; newSite.UseEmailForLogin = true; newSite.UseLdapAuth = false; newSite.UseSecureRegistration = false; newSite.UseSslOnAllPages = setupOptions.SslIsRequiredByWebServer; //newSite.CreateInitialDataOnCreate = false; newSite.AllowPasswordReset = true; newSite.AllowPasswordRetrieval = true; //0 = clear, 1= hashed, 2= encrypted newSite.PasswordFormat = 1; newSite.RequiresQuestionAndAnswer = true; newSite.MaxInvalidPasswordAttempts = 10; newSite.PasswordAttemptWindowMinutes = 5; //newSite.RequiresUniqueEmail = true; newSite.MinRequiredNonAlphanumericCharacters = 0; newSite.MinRequiredPasswordLength = 7; newSite.PasswordStrengthRegularExpression = String.Empty; //newSite.DefaultEmailFromAddress = GetMessageTemplate(templateFolder, "InitialEmailFromContent.config"); bool result = await siteRepo.Save(newSite); return result; }
public async Task<bool> Save(ISiteSettings site, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); int passedInSiteId = site.SiteId; bool result = false; if (site.SiteId == -1) // new site { site.SiteGuid = Guid.NewGuid(); site.SiteId = dbSiteSettings.Create( site.SiteGuid, site.SiteName, site.Layout, site.AllowNewRegistration, site.RequireConfirmedEmail, site.IsServerAdminSite, site.UseLdapAuth, site.AutoCreateLdapUserOnFirstLogin, site.LdapServer, site.LdapPort, site.LdapDomain, site.LdapRootDN, site.LdapUserDNKey, site.UseEmailForLogin, site.ReallyDeleteUsers, site.RecaptchaPrivateKey, site.RecaptchaPublicKey, site.DisableDbAuth, site.RequiresQuestionAndAnswer, site.MaxInvalidPasswordAttempts, site.MinRequiredPasswordLength, site.DefaultEmailFromAddress, site.AllowDbFallbackWithLdap, site.EmailLdapDbFallback, site.AllowPersistentLogin, site.CaptchaOnLogin, site.CaptchaOnRegistration, site.SiteIsClosed, site.SiteIsClosedMessage, site.PrivacyPolicy, site.TimeZoneId, site.GoogleAnalyticsProfileId, site.CompanyName, site.CompanyStreetAddress, site.CompanyStreetAddress2, site.CompanyRegion, site.CompanyLocality, site.CompanyCountry, site.CompanyPostalCode, site.CompanyPublicEmail, site.CompanyPhone, site.CompanyFax, site.FacebookAppId, site.FacebookAppSecret, site.GoogleClientId, site.GoogleClientSecret, site.TwitterConsumerKey, site.TwitterConsumerSecret, site.MicrosoftClientId, site.MicrosoftClientSecret, site.PreferredHostName, site.SiteFolderName, site.AddThisDotComUsername, site.LoginInfoTop, site.LoginInfoBottom, site.RegistrationAgreement, site.RegistrationPreamble, site.SmtpServer, site.SmtpPort, site.SmtpUser, site.SmtpPassword, site.SmtpPreferredEncoding, site.SmtpRequiresAuth, site.SmtpUseSsl, site.RequireApprovalBeforeLogin, site.IsDataProtected, site.CreatedUtc, site.RequireConfirmedPhone, site.DefaultEmailFromAlias, site.AccountApprovalEmailCsv, site.DkimPublicKey, site.DkimPrivateKey, site.DkimDomain, site.DkimSelector, site.SignEmailWithDkim, site.OidConnectAppId, site.OidConnectAppSecret, site.SmsClientId, site.SmsSecureToken, site.SmsFrom ); result = site.SiteId > -1; } else { result = dbSiteSettings.Update( site.SiteId, site.SiteName, site.Layout, site.AllowNewRegistration, site.RequireConfirmedEmail, site.IsServerAdminSite, site.UseLdapAuth, site.AutoCreateLdapUserOnFirstLogin, site.LdapServer, site.LdapPort, site.LdapDomain, site.LdapRootDN, site.LdapUserDNKey, site.UseEmailForLogin, site.ReallyDeleteUsers, site.RecaptchaPrivateKey, site.RecaptchaPublicKey, site.DisableDbAuth, site.RequiresQuestionAndAnswer, site.MaxInvalidPasswordAttempts, site.MinRequiredPasswordLength, site.DefaultEmailFromAddress, site.AllowDbFallbackWithLdap, site.EmailLdapDbFallback, site.AllowPersistentLogin, site.CaptchaOnLogin, site.CaptchaOnRegistration, site.SiteIsClosed, site.SiteIsClosedMessage, site.PrivacyPolicy, site.TimeZoneId, site.GoogleAnalyticsProfileId, site.CompanyName, site.CompanyStreetAddress, site.CompanyStreetAddress2, site.CompanyRegion, site.CompanyLocality, site.CompanyCountry, site.CompanyPostalCode, site.CompanyPublicEmail, site.CompanyPhone, site.CompanyFax, site.FacebookAppId, site.FacebookAppSecret, site.GoogleClientId, site.GoogleClientSecret, site.TwitterConsumerKey, site.TwitterConsumerSecret, site.MicrosoftClientId, site.MicrosoftClientSecret, site.PreferredHostName, site.SiteFolderName, site.AddThisDotComUsername, site.LoginInfoTop, site.LoginInfoBottom, site.RegistrationAgreement, site.RegistrationPreamble, site.SmtpServer, site.SmtpPort, site.SmtpUser, site.SmtpPassword, site.SmtpPreferredEncoding, site.SmtpRequiresAuth, site.SmtpUseSsl, site.RequireApprovalBeforeLogin, site.IsDataProtected, site.RequireConfirmedPhone, site.DefaultEmailFromAlias, site.AccountApprovalEmailCsv, site.DkimPublicKey, site.DkimPrivateKey, site.DkimDomain, site.DkimSelector, site.SignEmailWithDkim, site.OidConnectAppId, site.OidConnectAppSecret, site.SmsClientId, site.SmsSecureToken, site.SmsFrom ); } if (!result) { return result; } // settings below stored as key value pairs in mp_SiteSettingsEx //dbSiteSettingsEx.EnsureSettings(); //List<ExpandoSetting> expandoProperties = GetExpandoProperties(passedInSiteId); //-1 on new sites to get the default values // update a local data table of expando properties if the value changed and mark the row dirty //site.SetExpandoSettings(expandoProperties); // finally update the database only with properties in the table marked as dirty //SaveExpandoProperties(site.SiteId, site.SiteGuid, expandoProperties); return result; }
public async Task<bool> Save(ISiteSettings site) { dataProtector.Protect(site); return await siteRepo.Save(site, CancellationToken.None); }
//public bool UseSslOnAllPages { get; set; } = false; //public int PasswordAttemptWindowMinutes { get; set; } = 5; //public int MinReqNonAlphaChars { get; set; } = 0; //public bool RequireEnterEmailTwiceOnRegistration { get; set; } = false; //public bool AllowUserFullNameChange { get; set; } = true; //private string apiKeyExtra1 = string.Empty; //public string ApiKeyExtra1 //{ // get { return apiKeyExtra1 ?? string.Empty; } // set { apiKeyExtra1 = value; } //} //private string apiKeyExtra2 = string.Empty; //public string ApiKeyExtra2 //{ // get { return apiKeyExtra2 ?? string.Empty; } // set { apiKeyExtra2 = value; } //} //private string apiKeyExtra3 = string.Empty; //public string ApiKeyExtra3 //{ // get { return apiKeyExtra3 ?? string.Empty; } // set { apiKeyExtra3 = value; } //} //private string apiKeyExtra4 = string.Empty; //public string ApiKeyExtra4 //{ // get { return apiKeyExtra4 ?? string.Empty; } // set { apiKeyExtra4 = value; } //} //private string apiKeyExtra5 = string.Empty; //public string ApiKeyExtra5 //{ // get { return apiKeyExtra5 ?? string.Empty; } // set { apiKeyExtra5 = value; } //} public static SiteSettings FromISiteSettings(ISiteSettings i) { if(i == null) { return null; } SiteSettings s = new SiteSettings(); s.ConcurrencyStamp = i.ConcurrencyStamp; s.AccountApprovalEmailCsv = i.AccountApprovalEmailCsv; s.AddThisDotComUsername = i.AddThisDotComUsername; s.AllowDbFallbackWithLdap = i.AllowDbFallbackWithLdap; s.AllowNewRegistration = i.AllowNewRegistration; s.AllowPersistentLogin = i.AllowPersistentLogin; s.AutoCreateLdapUserOnFirstLogin = i.AutoCreateLdapUserOnFirstLogin; s.CaptchaOnLogin = i.CaptchaOnLogin; s.CaptchaOnRegistration = i.CaptchaOnRegistration; s.CompanyCountry = i.CompanyCountry; s.CompanyFax = i.CompanyFax; s.CompanyLocality = i.CompanyLocality; s.CompanyName = i.CompanyName; s.CompanyPhone = i.CompanyPhone; s.CompanyPostalCode = i.CompanyPostalCode; s.CompanyPublicEmail = i.CompanyPublicEmail; s.CompanyRegion = i.CompanyRegion; s.CompanyStreetAddress = i.CompanyStreetAddress; s.CompanyStreetAddress2 = i.CompanyStreetAddress2; s.CreatedUtc = i.CreatedUtc; s.DefaultEmailFromAddress = i.DefaultEmailFromAddress; s.DefaultEmailFromAlias = i.DefaultEmailFromAlias; s.DisableDbAuth = i.DisableDbAuth; s.DkimPublicKey = i.DkimPublicKey; s.DkimPrivateKey = i.DkimPrivateKey; s.DkimDomain = i.DkimDomain; s.DkimSelector = i.DkimSelector; s.EmailLdapDbFallback = i.EmailLdapDbFallback; s.FacebookAppId = i.FacebookAppId; s.FacebookAppSecret = i.FacebookAppSecret; s.GoogleAnalyticsProfileId = i.GoogleAnalyticsProfileId; s.GoogleClientId = i.GoogleClientId; s.GoogleClientSecret = i.GoogleClientSecret; s.IsDataProtected = i.IsDataProtected; s.IsServerAdminSite = i.IsServerAdminSite; s.Theme = i.Theme; s.LdapDomain = i.LdapDomain; s.LdapPort = i.LdapPort; s.LdapRootDN = i.LdapRootDN; s.LdapServer = i.LdapServer; s.LdapUserDNKey = i.LdapUserDNKey; s.LoginInfoBottom = i.LoginInfoBottom; s.LoginInfoTop = i.LoginInfoTop; s.MaxInvalidPasswordAttempts = i.MaxInvalidPasswordAttempts; s.MicrosoftClientId = i.MicrosoftClientId; s.MicrosoftClientSecret = i.MicrosoftClientSecret; s.MinRequiredPasswordLength = i.MinRequiredPasswordLength; s.OidConnectAppId = i.OidConnectAppId; s.OidConnectAppSecret = i.OidConnectAppSecret; s.PreferredHostName = i.PreferredHostName; s.PrivacyPolicy = i.PrivacyPolicy; s.ReallyDeleteUsers = i.ReallyDeleteUsers; s.RecaptchaPrivateKey = i.RecaptchaPrivateKey; s.RecaptchaPublicKey = i.RecaptchaPublicKey; s.RegistrationAgreement = i.RegistrationAgreement; s.RegistrationPreamble = i.RegistrationPreamble; s.RequireApprovalBeforeLogin = i.RequireApprovalBeforeLogin; s.RequireConfirmedEmail = i.RequireConfirmedEmail; s.RequireConfirmedPhone = i.RequireConfirmedPhone; s.RequiresQuestionAndAnswer = i.RequiresQuestionAndAnswer; s.SignEmailWithDkim = i.SignEmailWithDkim; s.SiteFolderName = i.SiteFolderName; s.Id = i.Id; s.AliasId = i.AliasId; s.SiteIsClosed = i.SiteIsClosed; s.SiteIsClosedMessage = i.SiteIsClosedMessage; s.SiteName = i.SiteName; s.SmsClientId = i.SmsClientId; s.SmsSecureToken = i.SmsSecureToken; s.SmsFrom = i.SmsFrom; s.SmtpPassword = i.SmtpPassword; s.SmtpPort = i.SmtpPort; s.SmtpPreferredEncoding = i.SmtpPreferredEncoding; s.SmtpRequiresAuth = i.SmtpRequiresAuth; s.SmtpServer = i.SmtpServer; s.SmtpUser = i.SmtpUser; s.SmtpUseSsl = i.SmtpUseSsl; s.TimeZoneId = i.TimeZoneId; s.TwitterConsumerKey = i.TwitterConsumerKey; s.TwitterConsumerSecret = i.TwitterConsumerSecret; s.UseEmailForLogin = i.UseEmailForLogin; s.UseLdapAuth = i.UseLdapAuth; return s; }
public async Task<bool> Save(ISiteSettings site) { int passedInSiteId = site.SiteId; bool result = false; if (site.SiteId == -1) // new site { site.SiteGuid = Guid.NewGuid(); site.SiteId = await dbSiteSettings.Create( site.SiteGuid, site.SiteName, site.Layout, site.AllowNewRegistration, site.UseSecureRegistration, site.UseSslOnAllPages, site.IsServerAdminSite, site.UseLdapAuth, site.AutoCreateLdapUserOnFirstLogin, site.LdapServer, site.LdapPort, site.LdapDomain, site.LdapRootDN, site.LdapUserDNKey, site.AllowUserFullNameChange, site.UseEmailForLogin, site.ReallyDeleteUsers, site.RecaptchaPrivateKey, site.RecaptchaPublicKey, site.ApiKeyExtra1, site.ApiKeyExtra2, site.ApiKeyExtra3, site.ApiKeyExtra4, site.ApiKeyExtra5, site.DisableDbAuth, site.RequiresQuestionAndAnswer, site.MaxInvalidPasswordAttempts, site.PasswordAttemptWindowMinutes, site.MinRequiredPasswordLength, site.MinReqNonAlphaChars, site.DefaultEmailFromAddress, site.AllowDbFallbackWithLdap, site.EmailLdapDbFallback, site.AllowPersistentLogin, site.CaptchaOnLogin, site.CaptchaOnRegistration, site.SiteIsClosed, site.SiteIsClosedMessage, site.PrivacyPolicy, site.TimeZoneId, site.GoogleAnalyticsProfileId, site.CompanyName, site.CompanyStreetAddress, site.CompanyStreetAddress2, site.CompanyRegion, site.CompanyLocality, site.CompanyCountry, site.CompanyPostalCode, site.CompanyPublicEmail, site.CompanyPhone, site.CompanyFax, site.FacebookAppId, site.FacebookAppSecret, site.GoogleClientId, site.GoogleClientSecret, site.TwitterConsumerKey, site.TwitterConsumerSecret, site.MicrosoftClientId, site.MicrosoftClientSecret, site.PreferredHostName, site.SiteFolderName, site.AddThisDotComUsername, site.LoginInfoTop, site.LoginInfoBottom, site.RegistrationAgreement, site.RegistrationPreamble, site.SmtpServer, site.SmtpPort, site.SmtpUser, site.SmtpPassword, site.SmtpPreferredEncoding, site.SmtpRequiresAuth, site.SmtpUseSsl, site.RequireApprovalBeforeLogin ); result = site.SiteId > -1; } else { result = await dbSiteSettings.Update( site.SiteId, site.SiteName, site.Layout, site.AllowNewRegistration, site.UseSecureRegistration, site.UseSslOnAllPages, site.IsServerAdminSite, site.UseLdapAuth, site.AutoCreateLdapUserOnFirstLogin, site.LdapServer, site.LdapPort, site.LdapDomain, site.LdapRootDN, site.LdapUserDNKey, site.AllowUserFullNameChange, site.UseEmailForLogin, site.ReallyDeleteUsers, site.RecaptchaPrivateKey, site.RecaptchaPublicKey, site.ApiKeyExtra1, site.ApiKeyExtra2, site.ApiKeyExtra3, site.ApiKeyExtra4, site.ApiKeyExtra5, site.DisableDbAuth, site.RequiresQuestionAndAnswer, site.MaxInvalidPasswordAttempts, site.PasswordAttemptWindowMinutes, site.MinRequiredPasswordLength, site.MinReqNonAlphaChars, site.DefaultEmailFromAddress, site.AllowDbFallbackWithLdap, site.EmailLdapDbFallback, site.AllowPersistentLogin, site.CaptchaOnLogin, site.CaptchaOnRegistration, site.SiteIsClosed, site.SiteIsClosedMessage, site.PrivacyPolicy, site.TimeZoneId, site.GoogleAnalyticsProfileId, site.CompanyName, site.CompanyStreetAddress, site.CompanyStreetAddress2, site.CompanyRegion, site.CompanyLocality, site.CompanyCountry, site.CompanyPostalCode, site.CompanyPublicEmail, site.CompanyPhone, site.CompanyFax, site.FacebookAppId, site.FacebookAppSecret, site.GoogleClientId, site.GoogleClientSecret, site.TwitterConsumerKey, site.TwitterConsumerSecret, site.MicrosoftClientId, site.MicrosoftClientSecret, site.PreferredHostName, site.SiteFolderName, site.AddThisDotComUsername, site.LoginInfoTop, site.LoginInfoBottom, site.RegistrationAgreement, site.RegistrationPreamble, site.SmtpServer, site.SmtpPort, site.SmtpUser, site.SmtpPassword, site.SmtpPreferredEncoding, site.SmtpRequiresAuth, site.SmtpUseSsl, site.RequireApprovalBeforeLogin ); } if (!result) { return result; } // settings below stored as key value pairs in mp_SiteSettingsEx bool nextResult = await dbSiteSettingsEx.EnsureSettings(); List<ExpandoSetting> expandoProperties = GetExpandoProperties(passedInSiteId); //-1 on new sites to get the default values // update a local data table of expando properties if the value changed and mark the row dirty site.SetExpandoSettings(expandoProperties); // finally update the database only with properties in the table marked as dirty SaveExpandoProperties(site.SiteId, site.SiteGuid, expandoProperties); return result; }