Exemplo n.º 1
0
        public static async Task <IEnumerable <InviteTemplate> > InitializeDefaultTemplate(string templateAuthor)
        {
            var template = new InviteTemplate
            {
                LastUpdated     = DateTime.UtcNow,
                TemplateAuthor  = templateAuthor,
                TemplateName    = "Default",
                TemplateVersion = 1
            };

            template.SubjectTemplate = MailSender.GetTemplateContents(Settings.DefaultSubjectTemplateName);
            template.TemplateContent = MailSender.GetTemplateContents(Settings.DefaultBodyTemplateName);

            template = (await DocDBRepo.DB <InviteTemplate> .CreateItemAsync(template));
            var res = new List <InviteTemplate>
            {
                template
            };

            return(res);
        }
Exemplo n.º 2
0
        protected void Application_Start()
        {
            try
            {
                //DocDB config
                DocDBRepo.Settings.DocDBUri        = ConfigurationManager.AppSettings["DocDBUri"];
                DocDBRepo.Settings.DocDBAuthKey    = ConfigurationManager.AppSettings["DocDBAuthKey"];
                DocDBRepo.Settings.DocDBName       = ConfigurationManager.AppSettings["DocDBName"];
                DocDBRepo.Settings.DocDBCollection = ConfigurationManager.AppSettings["DocDBCollection"];

                var client = DocDBRepo.Initialize().Result;
                var s      = client.AuthKey;

                ControllerBuilder.Current.DefaultNamespaces.Add("B2BPortal.Controllers");
                AreaRegistration.RegisterAllAreas();
                GlobalConfiguration.Configure(WebApiConfig.Register);
                FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
                RouteConfig.RegisterRoutes(RouteTable.Routes);
                BundleConfig.RegisterBundles(BundleTable.Bundles);
                AntiForgeryConfig.UniqueClaimTypeIdentifier = "http://schemas.microsoft.com/identity/claims/objectidentifier";

                //Settings
                bool isConfig = false;
                var  task     = Task.Run(async() => {
                    isConfig = await SiteConfigRules.LoadCurrSiteConfig();
                });
                task.Wait();

                if (isConfig)
                {
                    //if new site, no config but invites are disabled until config is complete
                    MailSender.MailFrom = Settings.CurrSiteConfig.SiteRedemptionSettings.InviterResponseEmailAddr;
                }

                Settings.AADInstanceLocal = ConfigurationManager.AppSettings["ida:AADInstanceLocal"];
                Settings.AADInstanceMulti = ConfigurationManager.AppSettings["ida:AADInstanceMulti"];
                Settings.TenantID         = ConfigurationManager.AppSettings["ida:TenantId"];
                Settings.Tenant           = ConfigurationManager.AppSettings["ida:Tenant"];
                Settings.AppRootPath      = HttpRuntime.AppDomainAppPath;

                Settings.AppClientId_Admin     = ConfigurationManager.AppSettings["ida:ClientId_Admin"];
                Settings.AppClientSecret_Admin = ConfigurationManager.AppSettings["ida:ClientSecret_Admin"];
                //using same client password for token cache encryption
                AESEncryption.Password = Settings.AppClientSecret_Admin;

                Settings.AppClientId_Preauth     = ConfigurationManager.AppSettings["ida:ClientId_PreAuth"];
                Settings.AppClientSecret_Preauth = ConfigurationManager.AppSettings["ida:ClientSecret_PreAuth"];

                Settings.GraphApiVersion = ConfigurationManager.AppSettings["GraphApiVersion"];

                Settings.DefaultSubjectTemplateName = ConfigurationManager.AppSettings["DefaultSubjectTemplateName"];
                Settings.DefaultBodyTemplateName    = ConfigurationManager.AppSettings["DefaultBodyTemplateName"];
                Settings.InviterRoleNames           = (ConfigurationManager.AppSettings["InviterRoleNames"] as string).Split(',');
                Settings.AssignedInviterRole        = ConfigurationManager.AppSettings["AssignedInviterRole"];

                //SMTP config
                MailSender.MailEnabled    = (ConfigurationManager.AppSettings["MailEnabled"] == "1");
                MailSender.MailTemplate   = MailSender.GetTemplateContents(ConfigurationManager.AppSettings["MailTemplateName"]);
                MailSender.MailServer     = ConfigurationManager.AppSettings["MailServer"];
                MailSender.MailServerPort = Convert.ToInt32(ConfigurationManager.AppSettings["SMTPPort"]);
                MailSender.SMTPLogin      = ConfigurationManager.AppSettings["SMTPLogin"];
                MailSender.SMTPPassword   = ConfigurationManager.AppSettings["SMTPPassword"];

                Settings.UseSMTP = (!string.IsNullOrEmpty(MailSender.MailServer));
                StorageRepo.StorageConnectionString = ConfigurationManager.AppSettings["StorageConnectionString"];

                /*
                 * TODO: Prefetching the app token here because initializing this library during admin
                 * authentication is timing out/failing.
                 * don't know if this is due to the api call or spinning up this code
                 * see AdalUtil.CallGraph...
                 */
                AdalUtil.AuthenticateApp();

                AdalUtil.GetTenantBranding();
                if (Settings.Branding.TileLogo.Image == null)
                {
                    //assign default logo
                    var imgPath = Path.Combine(Settings.AppRootPath, "Content\\Images\\AADB2BTile.png");
                    var img     = File.ReadAllBytes(imgPath);
                    Settings.Branding.TileLogo.Image = img;
                }
                MailSender.Logo = Settings.Branding.TileLogo.Image;
            }
            catch (Exception ex)
            {
                Logging.WriteToAppLog("Error during site initialization", System.Diagnostics.EventLogEntryType.Error, ex);
                throw;
            }
        }
Exemplo n.º 3
0
        private static void Setup()
        {
            try
            {
                //DocDB config
                DocDBRepo.Settings.DocDBUri        = ConfigurationManager.AppSettings["DocDBUri"];
                DocDBRepo.Settings.DocDBAuthKey    = ConfigurationManager.AppSettings["DocDBAuthKey"];
                DocDBRepo.Settings.DocDBName       = ConfigurationManager.AppSettings["DocDBName"];
                DocDBRepo.Settings.DocDBCollection = ConfigurationManager.AppSettings["DocDBCollection"];

                var client = DocDBRepo.Initialize().Result;
                var s      = client.AuthKey;

                bool isConfig = false;
                var  task     = Task.Run(async() => {
                    isConfig = await SiteConfigRules.LoadCurrSiteConfig();
                });
                task.Wait();

                if (isConfig)
                {
                    //if new site, no config but invites are disabled until config is complete
                    Settings.CurrSiteConfig.SiteRedemptionSettings = Settings.CurrSiteConfig.SiteRedemptionSettings;
                    Settings.CurrSiteConfig.InvitingOrg            = Settings.CurrSiteConfig.InvitingOrg;
                    MailSender.MailFrom = Settings.CurrSiteConfig.SiteRedemptionSettings.InviterResponseEmailAddr;
                }

                Settings.AppRootPath = Environment.CurrentDirectory;

                Settings.AADInstanceLocal = ConfigurationManager.AppSettings["ida:AADInstanceLocal"];
                Settings.AADInstanceMulti = ConfigurationManager.AppSettings["ida:AADInstanceMulti"];
                Settings.TenantID         = ConfigurationManager.AppSettings["ida:TenantId"];
                Settings.Tenant           = ConfigurationManager.AppSettings["ida:Tenant"];

                Settings.AppClientId_Admin     = ConfigurationManager.AppSettings["ida:ClientId_Admin"];
                Settings.AppClientSecret_Admin = ConfigurationManager.AppSettings["ida:ClientSecret_Admin"];
                //using same client password for token cache encryption
                AESEncryption.Password = Settings.AppClientSecret_Admin;

                Settings.AppClientId_Preauth     = ConfigurationManager.AppSettings["ida:ClientId_PreAuth"];
                Settings.AppClientSecret_Preauth = ConfigurationManager.AppSettings["ida:ClientSecret_PreAuth"];

                Settings.GraphApiVersion = ConfigurationManager.AppSettings["GraphApiVersion"];

                Settings.InviterRoleNames    = (ConfigurationManager.AppSettings["InviterRoleNames"] as string).Split(',');
                Settings.AssignedInviterRole = ConfigurationManager.AppSettings["AssignedInviterRole"];

                //these are the mail content templates
                Settings.DefaultSubjectTemplateName = ConfigurationManager.AppSettings["DefaultSubjectTemplateName"];
                Settings.DefaultBodyTemplateName    = ConfigurationManager.AppSettings["DefaultBodyTemplateName"];

                //SMTP config
                MailSender.MailEnabled = (ConfigurationManager.AppSettings["MailEnabled"] == "1");
                //this is the mail formatting template - subject and body are injected into this
                MailSender.MailTemplate   = MailSender.GetTemplateContents(ConfigurationManager.AppSettings["MailTemplateName"]);
                MailSender.MailServer     = ConfigurationManager.AppSettings["MailServer"];
                MailSender.MailServerPort = Convert.ToInt32(ConfigurationManager.AppSettings["SMTPPort"]);
                MailSender.SMTPLogin      = ConfigurationManager.AppSettings["SMTPLogin"];
                MailSender.SMTPPassword   = ConfigurationManager.AppSettings["SMTPPassword"];

                StorageRepo.StorageConnectionString = ConfigurationManager.AppSettings["StorageConnectionString"];
                Settings.UseSMTP = (!string.IsNullOrEmpty(MailSender.MailServer));

                /*
                 * TODO: Prefetching the app token here because initializing this library during admin
                 * authentication is timing out/failing.
                 * don't know if this is due to the api call or spinning up this code
                 * see AdalUtil.CallGraph...
                 */
                AdalUtil.AuthenticateApp();
                AdalUtil.GetTenantBranding();

                if (Settings.Branding.TileLogo.Image == null)
                {
                    //assign default logo
                    var imgPath = Path.Combine(Settings.AppRootPath, "Content\\Images\\AADB2BTile.png");
                    var img     = File.ReadAllBytes(imgPath);
                    Settings.Branding.TileLogo.Image = img;
                }
                MailSender.Logo = Settings.Branding.TileLogo.Image;
            }
            catch (Exception ex)
            {
                Logging.WriteToAppLog("Error during site initialization", System.Diagnostics.EventLogEntryType.Error, ex);
                throw;
            }
        }