Наследование: SiteInfo, ISiteSettings
 public FolderTenantNodeUrlPrefixProvider(
     SiteSettings currentSite,
     IOptions<MultiTenantOptions> multiTenantOptions)
 {
     site = currentSite;
     options = multiTenantOptions.Value;
 }
Пример #2
0
 public CoreDataController(
     SiteSettings currentSite,
     GeoDataManager geoDataManager,
     IOptions<UIOptions> uiOptionsAccessor
     )
 {
     Site = currentSite; 
     dataManager = geoDataManager;
     uiOptions = uiOptionsAccessor.Value;
 }
 public MultiTenantCookieOptionsResolver(
     //ISiteResolver siteResolver,
     SiteSettings currentSite,
     IOptions<MultiTenantOptions> multiTenantOptions,
     ILoggerFactory loggerFactory)
 {
     site = currentSite;
     //this.siteResolver = siteResolver;
     this.multiTenantOptions = multiTenantOptions.Value;
     log = loggerFactory.CreateLogger<MultiTenantCookieOptionsResolver>();
 }
 public MultiTenantCookieOptionsResolverFactory(
     //ISiteResolver siteResolver,
     SiteSettings currentSite,
     IOptions<MultiTenantOptions> multiTenantOptions,
     ILoggerFactory loggerFactory)
 {
     //this.siteResolver = siteResolver;
     this.currentSite = currentSite;
     this.multiTenantOptions = multiTenantOptions;
     this.loggerFactory = loggerFactory;
 }
Пример #5
0
 public CoreDataController(
     SiteSettings currentSite,
     GeoDataManager geoDataManager,
     IStringLocalizer<CloudscribeCore> localizer,
     IOptions<UIOptions> uiOptionsAccessor
     )
 {
     Site = currentSite; 
     dataManager = geoDataManager;
     uiOptions = uiOptionsAccessor.Value;
     sr = localizer;
 }
Пример #6
0
        public TenantLayoutSelector(
            IRazorViewEngine viewEngine,
            SiteSettings currentSite,
            IOptions<LayoutSelectorOptions> layoutOptionsAccesor,
            ILogger<TenantLayoutSelector> logger)
        {
            if (viewEngine == null) { throw new ArgumentNullException(nameof(viewEngine)); }
            if (currentSite == null) { throw new ArgumentNullException(nameof(currentSite)); }
            if (logger == null) { throw new ArgumentNullException(nameof(logger)); }
            if (layoutOptionsAccesor == null) { throw new ArgumentNullException(nameof(layoutOptionsAccesor)); }

            this.viewEngine = viewEngine;
            site = currentSite;
            options = layoutOptionsAccesor.Value;
            log = logger;
        }
Пример #7
0
 public AccountController(
     SiteSettings currentSite,
     SiteUserManager<SiteUser> userManager,
     SiteSignInManager<SiteUser> signInManager,
     IpAddressTracker ipAddressTracker,
     ISiteMessageEmailSender emailSender,
     ISmsSender smsSender,
     ILogger<AccountController> logger)
 {
     Site = currentSite; 
     this.userManager = userManager;
     this.signInManager = signInManager;
     this.emailSender = emailSender;
     this.smsSender = smsSender;
     this.ipAddressTracker = ipAddressTracker;
     log = logger;
 }
Пример #8
0
 public ManageController(
     SiteSettings currentSite,
     SiteUserManager<SiteUser> userManager,
     SiteSignInManager<SiteUser> signInManager,
     ISmsSender smsSender,
     IStringLocalizer<CloudscribeCore> localizer,
     ITimeZoneIdResolver timeZoneIdResolver,
     ITimeZoneHelper timeZoneHelper
     )
 {
     Site = currentSite; 
     this.userManager = userManager;
     this.signInManager = signInManager;
    // this.emailSender = emailSender;
     this.smsSender = smsSender;
     sr = localizer;
     this.timeZoneIdResolver = timeZoneIdResolver;
     tzHelper = timeZoneHelper;
 }
Пример #9
0
        public static SiteSettings BuildInitialSite()
        {
            var newSite = new SiteSettings();
            newSite.SiteName = "Sample Site";
            newSite.AliasId = "s1";
            newSite.IsServerAdminSite = true;
            newSite.Theme = "default";
            newSite.AllowNewRegistration = true;
            newSite.AutoCreateLdapUserOnFirstLogin = true;
            newSite.ReallyDeleteUsers = true;
            newSite.LdapPort = 389;
            newSite.LdapRootDN = string.Empty;
            newSite.LdapServer = string.Empty;
            newSite.UseEmailForLogin = true;
            newSite.UseLdapAuth = false;
            newSite.RequireConfirmedEmail = false;
            newSite.RequiresQuestionAndAnswer = false;
            newSite.MaxInvalidPasswordAttempts = 10;
            newSite.MinRequiredPasswordLength = 7;

            return newSite;
        }
Пример #10
0
        public SiteManager(
            SiteSettings currentSite,
            ISiteRepository siteRepository,
            IUserRepository userRepository,
            SiteDataProtector dataProtector,
            IHttpContextAccessor contextAccessor,
            ILogger<SiteManager> logger,
            IOptions<MultiTenantOptions> multiTenantOptionsAccessor,
            IOptions<SiteConfigOptions> setupOptionsAccessor
            )
        {
            
            siteRepo = siteRepository;
            userRepo = userRepository;
            multiTenantOptions = multiTenantOptionsAccessor.Value;
            setupOptions = setupOptionsAccessor.Value;
            _context = contextAccessor?.HttpContext;
            this.dataProtector = dataProtector;
            log = logger;

            //resolver = siteResolver;
            siteSettings = currentSite;
        }
        public async Task<ISiteSettings> Fetch(string hostName, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            SiteSettings site = new SiteSettings();

            using (DbDataReader reader = dbSiteSettings.GetSite(hostName))
            {
                if (reader.Read())
                {
                    site.LoadFromReader(reader);
                }
            }

            if (site.SiteGuid == Guid.Empty) { return null; }//not found 

            //List<ExpandoSetting> expandoProperties = GetExpandoProperties(site.SiteId);
            //site.LoadExpandoSettings(expandoProperties);

            return site;
        }
Пример #12
0
        public async Task<ISiteSettings> Fetch(Guid siteGuid)
        {
            SiteSettings site = new SiteSettings();

            using (DbDataReader reader = await dbSiteSettings.GetSite(siteGuid))
            {
                if (reader.Read())
                {
                    site.LoadFromReader(reader);
                }

            }

            if (site.SiteGuid == Guid.Empty) { return null; }//not found 

            List<ExpandoSetting> expandoProperties = GetExpandoProperties(site.SiteId);
            site.LoadExpandoSettings(expandoProperties);

            return site;


        }
Пример #13
0
 public async Task CreateRequiredRolesAndAdminUser(SiteSettings site)
 {
     await EnsureRequiredRoles(site);
     await CreateAdminUser(site);
     
 }
Пример #14
0
        //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;
        }
Пример #15
0
        public async Task<ActionResult> NewSite(NewSiteViewModel model)
        {
            ViewData["Title"] = "Create New Site";

            if (!ModelState.IsValid)
            {
                return View(model);
            }
            
            bool addHostName = false;
            var newSite = new SiteSettings();
            newSite.Id = Guid.NewGuid();

            if (multiTenantOptions.Mode == MultiTenantMode.FolderName)
            {
                if (string.IsNullOrEmpty(model.SiteFolderName))
                {
                    model.AllTimeZones = tzHelper.GetTimeZoneList().Select(x =>
                               new SelectListItem
                               {
                                   Text = x,
                                   Value = x,
                                   Selected = model.TimeZoneId == x
                               });
                    ModelState.AddModelError("foldererror", sr["Folder name is required."]);
                    return View(model);
                }

                bool folderAvailable = await siteManager.FolderNameIsAvailable(newSite.Id, model.SiteFolderName);
                if (!folderAvailable)
                {
                    model.AllTimeZones = tzHelper.GetTimeZoneList().Select(x =>
                               new SelectListItem
                               {
                                   Text = x,
                                   Value = x,
                                   Selected = model.TimeZoneId == x
                               });
                    ModelState.AddModelError("foldererror", sr["The selected folder name is already in use on another site."]);
                    return View(model);
                }
            }
            else
            {
                ISiteHost host;
                if (!string.IsNullOrEmpty(model.HostName))
                {
                    model.HostName = model.HostName.Replace("https://", string.Empty).Replace("http://", string.Empty);
                    host = await siteManager.GetSiteHost(model.HostName);
                    if (host != null)
                    {
                        model.AllTimeZones = tzHelper.GetTimeZoneList().Select(x =>
                               new SelectListItem
                               {
                                   Text = x,
                                   Value = x,
                                   Selected = model.TimeZoneId == x
                               });
                        ModelState.AddModelError("hosterror", sr["The selected host/domain name is already in use on another site."]);
                        return View(model);
                    }
                    addHostName = true;
                }

            }
            
            // only the first site created by setup page should be a server admin site
            newSite.IsServerAdminSite = false;
            newSite.SiteName = model.SiteName;
            
            var siteNumber = 1 + await siteManager.CountOtherSites(Guid.Empty);
            newSite.AliasId = $"s{siteNumber}";
            

            if (multiTenantOptions.Mode == MultiTenantMode.FolderName)
            {
                newSite.SiteFolderName = model.SiteFolderName;
            }
            else if (addHostName)
            {
                newSite.PreferredHostName = model.HostName;
            }

            newSite.SiteIsClosed = model.IsClosed;
            newSite.SiteIsClosedMessage = model.ClosedMessage;
            
            await siteManager.CreateNewSite(newSite);
            await siteManager.CreateRequiredRolesAndAdminUser(
                newSite,
                model.Email,
                model.LoginName,
                model.DisplayName,
                model.Password
                );
            
            if (addHostName)
            {
                await siteManager.AddHost(newSite.Id, model.HostName);
            }
            
            this.AlertSuccess(string.Format(sr["Basic site settings for {0} were successfully created."],
                        newSite.SiteName), true);
            
            return RedirectToAction("SiteList", new { pageNumber = model.ReturnPageNumber });

        }
        public async Task<ISiteSettings> Fetch(
            string hostName, 
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            SiteSettings site = new SiteSettings();

            using (DbDataReader reader = await dbSiteSettings.GetSite(
                hostName,
                cancellationToken))
            {
                if (reader.Read())
                {
                    site.LoadFromReader(reader);
                }
            }

            if (site.SiteGuid == Guid.Empty) { return null; }//not found 

            //TODO: unless we also need a synchronous version of this method 
            // the below should be made async
            //List<ExpandoSetting> expandoProperties = GetExpandoProperties(site.SiteId);
            //site.LoadExpandoSettings(expandoProperties);

            return site;

        }
Пример #17
0
        public async Task<ISiteSettings> Fetch(Guid siteGuid)
        {
            SiteSettings site = new SiteSettings();

            using (DbDataReader reader = await dbSiteSettings.GetSite(siteGuid))
            {
                if (reader.Read())
                {
                    site.LoadFromReader(reader);
                }

            }

            if (site.SiteGuid == Guid.Empty) { return null; }//not found 
            //TODO: unless we also need a synchronous version of this method 
            // the below should be made async
            List<ExpandoSetting> expandoProperties = GetExpandoProperties(site.SiteId);
            site.LoadExpandoSettings(expandoProperties);

            return site;


        }
Пример #18
0
        public async Task<ActionResult> NewSite(SiteBasicSettingsViewModel model)
        {
            ViewData["Title"] = "Create New Site";

            if (!ModelState.IsValid)
            {
                return View(model);
            }
            
            bool addHostName = false;

            if (multiTenantOptions.Mode == MultiTenantMode.FolderName)
            {
                if (string.IsNullOrEmpty(model.SiteFolderName))
                {
                    ModelState.AddModelError("foldererror", "Folder name is required.");

                    return View(model);
                }

                SiteFolder folder = await siteManager.GetSiteFolder(model.SiteFolderName);
                if (folder != null)
                {
                    ModelState.AddModelError("foldererror", "The selected folder name is already in use on another site.");

                    return View(model);
                }

            }
            else
            {
                ISiteHost host;

                if (!string.IsNullOrEmpty(model.HostName))
                {
                    model.HostName = model.HostName.Replace("https://", string.Empty).Replace("http://", string.Empty);

                    host = await siteManager.GetSiteHost(model.HostName);

                    if (host != null)
                    {

                        ModelState.AddModelError("hosterror", "The selected host/domain name is already in use on another site.");

                        return View(model);

                    }

                    addHostName = true;
                }




            }

            SiteSettings newSite = new SiteSettings();

            // only the first site created by setup page should be a server admin site
            newSite.IsServerAdminSite = false;

            newSite.SiteName = model.SiteName;
            
            if (multiTenantOptions.Mode == MultiTenantMode.FolderName)
            {
                newSite.SiteFolderName = model.SiteFolderName;
            }
            else if (addHostName)
            {
                newSite.PreferredHostName = model.HostName;
            }

            newSite.SiteIsClosed = model.IsClosed;
            newSite.SiteIsClosedMessage = model.ClosedMessage;
            
            //Site.SiteRepository.Save(newSite);
            bool result = await siteManager.CreateNewSite(newSite);
            result = await siteManager.CreateRequiredRolesAndAdminUser(newSite);

            if ((result) && (multiTenantOptions.Mode == MultiTenantMode.FolderName))
            {
                bool folderResult = await siteManager.EnsureSiteFolder(newSite);

            // for folder sites we need routes that match the folder
            // which are normally created during app startup
            // can we add routes here? or do we need to force the app to recycle?
            // this seems to work, but we really do need to restart
            // so that the per folder authentication gets setup too
            //cloudscribe.Web.Routing.RouteRegistrar.AddDefaultRouteForNewSiteFolder(folder.FolderName);

            //startup.TriggerStartup();
            //http://stackoverflow.com/questions/31339896/replacement-httpruntime-unloadappdomain-in-asp-net-5

            }

            if (result && addHostName)
            {
                bool hostResult = await siteManager.AddHost(
                            newSite.SiteGuid,
                            newSite.SiteId,
                            model.HostName);
            }

            if (result)
            {
                this.AlertSuccess(string.Format("Basic site settings for <b>{0}</b> were successfully created.",
                           newSite.SiteName), true);

            }

            return RedirectToAction("SiteList", new { pageNumber = model.ReturnPageNumber });

        }
Пример #19
0
        private static async Task EnsureData(
            CoreDbContext db
            )
        {
            int rowsAffected = 0;


            int count = await db.Countries.CountAsync<GeoCountry>();
            if(count == 0)
            {
                foreach(GeoCountry c in cloudscribe.Core.Models.InitialData.BuildCountryList())
                {
                    db.Countries.Add(c);
                }

                rowsAffected = await db.SaveChangesAsync();
            }
            
            count = await db.States.CountAsync<GeoZone>();
            if (count == 0)
            {
                foreach (GeoZone c in cloudscribe.Core.Models.InitialData.BuildStateList())
                {
                    db.States.Add(c);
                }

                rowsAffected = await db.SaveChangesAsync();
            }

            

            count = await db.Languages.CountAsync<Language>();
            if (count == 0)
            {
                foreach (Language c in cloudscribe.Core.Models.InitialData.BuildLanguageList())
                {
                    db.Languages.Add(c);
                }

                rowsAffected = await db.SaveChangesAsync();
            }

            count = await db.Currencies.CountAsync<Currency>();
            if (count == 0)
            {
                foreach (Currency c in cloudscribe.Core.Models.InitialData.BuildCurrencyList())
                {
                    db.Currencies.Add(c);
                }

                rowsAffected = await db.SaveChangesAsync();
            }

                
            count = await db.Sites.CountAsync<SiteSettings>();
            if (count == 0)
            {
                // create first site
                SiteSettings newSite = new SiteSettings();
                newSite.SiteId = 0;
                newSite.SiteGuid = Guid.NewGuid();
                newSite.SiteName = "Sample Site";
                newSite.IsServerAdminSite = true;

                newSite.Layout = "Default_Layout.cshtml";

                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 = false;


                //0 = clear, 1= hashed, 2= encrypted
                //newSite.PasswordFormat = 1;

                newSite.RequiresQuestionAndAnswer = false;
                newSite.MaxInvalidPasswordAttempts = 10;
                newSite.PasswordAttemptWindowMinutes = 5;
                newSite.MinReqNonAlphaChars = 0;
                newSite.MinRequiredPasswordLength = 7;

                db.Sites.Add(newSite);
                
                rowsAffected = await db.SaveChangesAsync();
                   
            }

            // ensure roles
            count = await db.Roles.CountAsync<SiteRole>();
            if (count == 0)
            {
                SiteSettings site = await db.Sites.SingleOrDefaultAsync<SiteSettings>(
                    s => s.SiteId > 0 && s.IsServerAdminSite == true);

                if(site != null)
                {
                    SiteRole adminRole = new SiteRole();
                    adminRole.RoleId = 0;
                    adminRole.RoleGuid = Guid.NewGuid();
                    adminRole.RoleName = "Admins";
                    adminRole.DisplayName = "Administrators";
                    adminRole.SiteId = site.SiteId;
                    adminRole.SiteGuid = site.SiteGuid;
                    db.Roles.Add(adminRole);
                    //rowsAffected = await db.SaveChangesAsync();
                        
                    SiteRole roleAdminRole = new SiteRole();
                    roleAdminRole.RoleId = 0;
                    roleAdminRole.RoleGuid = Guid.NewGuid();
                    roleAdminRole.RoleName = "Role Admins";
                    roleAdminRole.DisplayName = "Role Administrators";
                    roleAdminRole.SiteId = site.SiteId;
                    roleAdminRole.SiteGuid = site.SiteGuid;
                    db.Roles.Add(roleAdminRole);
                    //rowsAffected = await db.SaveChangesAsync();
                    
                    SiteRole contentAdminRole = new SiteRole();
                    contentAdminRole.RoleId = 0;
                    contentAdminRole.RoleGuid = Guid.NewGuid();
                    contentAdminRole.RoleName = "Content Administrators";
                    contentAdminRole.DisplayName = "Content Administrators";
                    contentAdminRole.SiteId = site.SiteId;
                    contentAdminRole.SiteGuid = site.SiteGuid;
                    db.Roles.Add(contentAdminRole);

                    SiteRole authenticatedUserRole = new SiteRole();
                    authenticatedUserRole.RoleId = 0;
                    authenticatedUserRole.RoleGuid = Guid.NewGuid();
                    authenticatedUserRole.RoleName = "Authenticated Users";
                    authenticatedUserRole.DisplayName = "Authenticated Users";
                    authenticatedUserRole.SiteId = site.SiteId;
                    authenticatedUserRole.SiteGuid = site.SiteGuid;
                    db.Roles.Add(authenticatedUserRole);

                    
                    rowsAffected = await db.SaveChangesAsync();
                    
                   
                }

            }

            // ensure admin user
            count = await db.Users.CountAsync<SiteUser>();
            
            if (count == 0)
            {
                SiteSettings site = await db.Sites.SingleOrDefaultAsync<SiteSettings>(
                    s => s.SiteId > 0 && s.IsServerAdminSite == true);
                    
                if (site != null)
                {
                    SiteRole role
                        = await db.Roles.SingleOrDefaultAsync(
                            x => x.SiteId == site.SiteId && x.RoleName == "Admins");

                    if(role != null)
                    {
                        SiteUser adminUser = new SiteUser();
                        adminUser.SiteId = site.SiteId;
                        adminUser.SiteGuid = site.SiteGuid;
                        adminUser.Email = "*****@*****.**";
                        adminUser.LoweredEmail = adminUser.Email;
                        adminUser.DisplayName = "Admin";
                        adminUser.UserName = "******";
                        adminUser.UserId = 0;
                        adminUser.UserGuid = Guid.NewGuid();

                        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 

                        db.Users.Add(adminUser);
                        
                        rowsAffected = await db.SaveChangesAsync();
                        
                        if(rowsAffected > 0 && adminUser.UserId > -1)
                        {
                            UserRole ur = new UserRole();
                            ur.Id = 0;
                            ur.RoleGuid = role.RoleGuid;
                            ur.RoleId = role.RoleId;
                            ur.UserGuid = adminUser.UserGuid;
                            ur.UserId = adminUser.UserId;

                            db.UserRoles.Add(ur);
                            rowsAffected = await db.SaveChangesAsync();

                        }
                    }

                }

            }
            
        }
Пример #20
0
        public async Task<bool> CreateRequiredRolesAndAdminUser(SiteSettings site)
        {
            bool result = await EnsureRequiredRoles(site);
            result = await CreateAdminUser(site);

            return result;

        }
Пример #21
0
        public async Task CreateRequiredRolesAndAdminUser(
            SiteSettings site,
            string adminEmail,
            string adminLoginName,
            string adminDisplayName,
            string adminPassword
            )
        {
            await EnsureRequiredRoles(site);
            var adminRole = await userQueries.FetchRole(site.Id, "Administrators", CancellationToken);

            if (adminRole == null)
            {
                throw new InvalidOperationException("Administrators role could nto be found so cannot create admin user");
            }

            var adminUser = new SiteUser();
            adminUser.Id = Guid.NewGuid();
            adminUser.SiteId = site.Id;
            adminUser.Email = adminEmail;
            adminUser.NormalizedEmail = adminUser.Email.ToUpperInvariant();
            adminUser.DisplayName = adminDisplayName;
            adminUser.UserName = adminLoginName;
            adminUser.NormalizedUserName = adminUser.UserName.ToUpperInvariant();
            adminUser.EmailConfirmed = true;
            adminUser.AccountApproved = true;
           
            // clear text password will be hashed upon login
            adminUser.PasswordHash =  adminPassword +"||0"; //pwd/salt/format 
            adminUser.MustChangePwd = true; // TODO: implement logic to enforce this

            await userCommands.Create(adminUser, CancellationToken.None);

            await userCommands.AddUserToRole(
                site.Id,
                adminRole.Id,
                adminUser.Id,
                CancellationToken.None);

        }
Пример #22
0
        public async Task<bool> CreateRequiredRolesAndAdminUser(
            SiteSettings site)
        {



            //SiteRole adminRole = new SiteRole();
            //adminRole.DisplayName = "Admins";
            ////adminRole.DisplayName = "Administrators";
            //adminRole.SiteId = site.SiteId;
            //adminRole.SiteGuid = site.SiteGuid;
            //bool result = await userRepo.SaveRole(adminRole);
            //adminRole.DisplayName = "Administrators";
            //result = await userRepo.SaveRole(adminRole);

            //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);

            //SiteRole contentAdminRole = new SiteRole();
            //contentAdminRole.DisplayName = "Content Administrators";
            //contentAdminRole.SiteId = site.SiteId;
            //contentAdminRole.SiteGuid = site.SiteGuid;
            //result = await userRepo.SaveRole(contentAdminRole);

            //SiteRole authenticatedUserRole = new SiteRole();
            //authenticatedUserRole.DisplayName = "Authenticated Users";
            //authenticatedUserRole.SiteId = site.SiteId;
            //authenticatedUserRole.SiteGuid = site.SiteGuid;
            //result = await userRepo.SaveRole(authenticatedUserRole);

            //// 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 


            //result = await userRepo.Save(adminUser);




            //result = await userRepo.AddUserToRole(
            //    adminRole.RoleId,
            //    adminRole.RoleGuid,
            //    adminUser.UserId,
            //    adminUser.UserGuid);

            bool result = await EnsureRequiredRoles(site);
            result = await CreateAdminUser(site);

            return result;

        }
Пример #23
0
        public ISiteSettings FetchNonAsync(string hostName)
        {
            SiteSettings site = new SiteSettings();

            using (DbDataReader reader = dbSiteSettings.GetSiteNonAsync(hostName))
            {
                if (reader.Read())
                {
                    site.LoadFromReader(reader);
                }
            }

            if (site.SiteGuid == Guid.Empty) { return null; }//not found 

            List<ExpandoSetting> expandoProperties = GetExpandoProperties(site.SiteId);
            site.LoadExpandoSettings(expandoProperties);

            return site;

        }
Пример #24
0
        public static SiteSettings FromISiteSettings(ISiteSettings i)
        {
            if(i == null) { return null; }

            SiteSettings s = new SiteSettings();
            s.AddThisDotComUsername = i.AddThisDotComUsername;
            s.AllowDbFallbackWithLdap = i.AllowDbFallbackWithLdap;
            s.AllowNewRegistration = i.AllowNewRegistration;
            s.AllowPersistentLogin = i.AllowPersistentLogin;
            s.AllowUserFullNameChange = i.AllowUserFullNameChange;
            s.ApiKeyExtra1 = i.ApiKeyExtra1;
            s.ApiKeyExtra2 = i.ApiKeyExtra2;
            s.ApiKeyExtra3 = i.ApiKeyExtra3;
            s.ApiKeyExtra4 = i.ApiKeyExtra4;
            s.ApiKeyExtra5 = i.ApiKeyExtra5;
            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.DefaultEmailFromAddress = i.DefaultEmailFromAddress;
            s.DisableDbAuth = i.DisableDbAuth;
            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.IsServerAdminSite = i.IsServerAdminSite;
            s.Layout = i.Layout;
            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.MinReqNonAlphaChars = i.MinReqNonAlphaChars;
            s.MinRequiredPasswordLength = i.MinRequiredPasswordLength;
            s.PasswordAttemptWindowMinutes = i.PasswordAttemptWindowMinutes;
            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.RequiresQuestionAndAnswer = i.RequiresQuestionAndAnswer;
            s.SiteFolderName = i.SiteFolderName;
            s.SiteGuid = i.SiteGuid;
            s.SiteId = i.SiteId;
            s.SiteIsClosed = i.SiteIsClosed;
            s.SiteIsClosedMessage = i.SiteIsClosedMessage;
            s.SiteName = i.SiteName;
            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;
            s.UseSecureRegistration = i.UseSecureRegistration;
            s.UseSslOnAllPages = i.UseSslOnAllPages;
            


            return s;
        }
Пример #25
0
        //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.OidConnectAuthority        = i.OidConnectAuthority;
            s.OidConnectDisplayName      = i.OidConnectDisplayName;
            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.UseInvisibleRecaptcha = i.UseInvisibleRecaptcha;
            s.UseEmailForLogin      = i.UseEmailForLogin;
            s.UseLdapAuth           = i.UseLdapAuth;
            s.TermsUpdatedUtc       = i.TermsUpdatedUtc;

            return(s);
        }
Пример #26
0
        public async Task<SiteSettings> CreateNewSite(
            bool isServerAdminSite)
        {
            //string templateFolderPath = GetMessageTemplateFolder();
            //string templateFolder = templateFolderPath;

            SiteSettings newSite = new SiteSettings();
            newSite.SiteName = "Sample Site";
            newSite.IsServerAdminSite = isServerAdminSite;

            bool result = await CreateNewSite(newSite);

            return newSite;


        }
Пример #27
0
        public async Task<bool> CreateRequiredRolesAndAdminUser(
            SiteSettings site)
        {

            SiteRole adminRole = new SiteRole();
            adminRole.DisplayName = "Admins";
            //adminRole.DisplayName = "Administrators";
            adminRole.SiteId = site.SiteId;
            adminRole.SiteGuid = site.SiteGuid;
            bool result = await userRepo.SaveRole(adminRole);
            adminRole.DisplayName = "Administrators";
            result = await userRepo.SaveRole(adminRole);

            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);

            SiteRole contentAdminRole = new SiteRole();
            contentAdminRole.DisplayName = "Content Administrators";
            contentAdminRole.SiteId = site.SiteId;
            contentAdminRole.SiteGuid = site.SiteGuid;
            result = await userRepo.SaveRole(contentAdminRole);

            SiteRole authenticatedUserRole = new SiteRole();
            authenticatedUserRole.DisplayName = "Authenticated Users";
            authenticatedUserRole.SiteId = site.SiteId;
            authenticatedUserRole.SiteGuid = site.SiteGuid;
            result = await userRepo.SaveRole(authenticatedUserRole);

            //SiteRole newsletterAdminRole = new SiteRole();
            //newsletterAdminRole.DisplayName = "Newsletter Administrators";
            //newsletterAdminRole.SiteId = site.SiteId;
            //newsletterAdminRole.SiteGuid = site.SiteGuid;
            //userRepository.SaveRole(newsletterAdminRole);

            // 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();
                }
            }

            //mojoMembershipProvider membership = Membership.Provider as mojoMembershipProvider;
            //bool overridRelatedSiteMode = true;
            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.ApprovedForLogin = true;
            adminUser.Password = "******";
            adminUser.PasswordFormat = 0;

            //if (membership != null)
            //{
            //    adminUser.Password = membership.EncodePassword(site, adminUser, "admin");
            //}

            adminUser.PasswordQuestion = "What is your user name?";
            adminUser.PasswordAnswer = "admin";

            result = await userRepo.Save(adminUser);

            //siteUserManager.AddPassword(adminUser.UserGuid.ToString(), "admin");

            //siteUserManager.Create(adminUser, "admin");
            //var result = siteUserManager.CreateAsync(adminUser, "admin");
            //if (result.Succeeded)
            //{
            //}
            result = await userRepo.AddUserToRole(
                adminRole.RoleId,
                adminRole.RoleGuid,
                adminUser.UserId,
                adminUser.UserGuid);

            return result;

        }
Пример #28
0
        public ISiteSettings FetchNonAsync(string hostName)
        {
            SiteSettings site = new SiteSettings();

            using (DbDataReader reader = dbSiteSettings.GetSiteNonAsync(hostName))
            {
                if (reader.Read())
                {
                    site.LoadFromReader(reader);
                }
            }

            if (site.SiteGuid == Guid.Empty) { return null; }//not found 

            //TODO: unless we also need a synchronous version of this method 
            // the below should be made async
            //List<ExpandoSetting> expandoProperties = GetExpandoProperties(site.SiteId);
            //site.LoadExpandoSettings(expandoProperties);

            return site;

        }
Пример #29
0
        public async Task<SiteSettings> CreateNewSite(bool isServerAdminSite)
        {
            var newSite = new SiteSettings();
            newSite.Id = Guid.NewGuid();
            newSite.SiteName = "Sample Site";
            newSite.IsServerAdminSite = isServerAdminSite;
            var siteNumber = 1 + await queries.CountOtherSites(Guid.Empty);
            newSite.AliasId = $"s{siteNumber}";

            await CreateNewSite(newSite);
            
            return newSite;
        }