private static string GetJSFileName()
        {
            string url  = VersionManager.GetAddOnPackageUrl(AreaRegistration.CurrentPackage.AreaName);
            string path = Utility.UrlToPhysical(url);

            return(Path.Combine(path, JSFile));
        }
예제 #2
0
        public async Task <ActionResult> Login(string name, string pswd, string v, bool closeOnLogin = false, bool __f = false)
        {
            // add popup support for possible 2fa
            await YetaWFCoreRendering.Render.AddPopupsAddOnsAsync();

            LoginConfigData config = await LoginConfigDataProvider.GetConfigAsync();

            bool isPersistent = config.PersistentLogin;

            LoginModel model = new LoginModel {
                AllowNewUser     = config.AllowUserRegistration,
                RegistrationType = config.RegistrationType,
                UserName         = name,
                Email            = name,
                Password         = pswd,
                VerificationCode = v,
                Captcha          = new RecaptchaV2Data(),
                RememberMe       = isPersistent,
                CloseOnLogin     = closeOnLogin,
                ShowVerification = !string.IsNullOrWhiteSpace(v),
                ShowCaptcha      = config.Captcha && string.IsNullOrWhiteSpace(v) && !Manager.IsLocalHost,
            };

            if (Manager.HaveReturnToUrl)
            {
                model.ReturnUrl = Manager.ReturnToUrl;
            }

            using (LoginConfigDataProvider logConfigDP = new LoginConfigDataProvider()) {
                List <LoginConfigDataProvider.LoginProviderDescription> loginProviders = await logConfigDP.GetActiveExternalLoginProvidersAsync();

                if (loginProviders.Count > 0 && Manager.IsInPopup)
                {
                    throw new InternalError("When using external login providers, the Login module cannot be used in a popup window");
                }
                foreach (LoginConfigDataProvider.LoginProviderDescription provider in loginProviders)
                {
                    model.ExternalProviders.Add(new FormButton()
                    {
                        ButtonType = ButtonTypeEnum.Submit,
                        Name       = "provider",
                        Text       = provider.InternalName,
                        Title      = this.__ResStr("logAccountTitle", "Log in using your {0} account", provider.DisplayName),
                        CssClass   = "t_" + provider.InternalName.ToLower(),
                    });
                    YetaWF.Core.Packages.Package package = AreaRegistration.CurrentPackage;
                    string url = VersionManager.GetAddOnPackageUrl(package.AreaName);
                    model.Images.Add(Manager.GetCDNUrl(string.Format("{0}Icons/LoginProviders/{1}.png", url, provider.InternalName)));
                }
            }
            if (__f)
            {
                Manager.CurrentResponse.StatusCode = 401;
            }

            await model.UpdateAsync();

            return(View(model));
        }
예제 #3
0
        /// <summary>
        /// Loads the propertylist definitions for a propertylist based on its model type.
        /// </summary>
        /// <param name="model">The model type for which propertylist definitions is to be loaded.</param>
        /// <returns>Returns an object describing the propertylist.</returns>
        /// <remarks>This method is not used by applications. It is reserved for component implementation.</remarks>
        public static async Task <PropertyListSetup> LoadPropertyListDefinitionsAsync(Type model)
        {
            string controller;
            string objClass;

            if (model.FullName.Contains("+"))
            {
                string   className = model.FullName.Split(new char[] { '.' }).Last();
                string[] s         = className.Split(new char[] { '+' });
                int      len       = s.Length;
                if (len != 2)
                {
                    throw new InternalError($"Unexpected class {className} in propertylist model {model.FullName}");
                }
                controller = s[0];
                objClass   = s[1];
            }
            else
            {
                string[] s   = model.FullName.Split(new char[] { '.' });
                int      len = s.Length;
                if (len < 2)
                {
                    throw new InternalError($"Unexpected class {model.FullName} as propertylist model");
                }
                controller = s[len - 2];
                objClass   = s[len - 1];
            }
            string file = controller + "." + objClass;

            Package           package     = Package.GetPackageFromType(model);
            string            predefUrl   = VersionManager.GetAddOnPackageUrl(package.AreaName) + "PropertyLists/" + file;
            string            customUrl   = VersionManager.GetCustomUrlFromUrl(predefUrl);
            PropertyListSetup setup       = null;
            PropertyListSetup predefSetup = await ReadPropertyListSetupAsync(package, model, Utility.UrlToPhysical(predefUrl));

            if (predefSetup.ExplicitDefinitions)
            {
                setup = predefSetup;
            }
            PropertyListSetup customInfo = await ReadPropertyListSetupAsync(package, model, Utility.UrlToPhysical(customUrl));

            if (customInfo.ExplicitDefinitions)
            {
                setup = customInfo;
            }
            if (setup == null)
            {
                setup = new PropertyListSetup();
            }
            return(setup);
        }
예제 #4
0
        public async Task <ActionResult> Register(bool closeOnLogin = false)
        {
            LoginConfigData config = await LoginConfigDataProvider.GetConfigAsync();

            if (!config.AllowUserRegistration)
            {
                throw new Error(this.__ResStr("cantRegister", "This site does not allow new user registration"));
            }

            using (LoginConfigDataProvider logConfigDP = new LoginConfigDataProvider()) {
                RegisterModel model = new RegisterModel {
                    RegistrationType = config.RegistrationType,
                    ShowCaptcha      = config.Captcha && !Manager.IsLocalHost,
                    Captcha          = new RecaptchaV2Data(),
                    CloseOnLogin     = closeOnLogin,
                    QueryString      = Manager.RequestQueryString.ToQueryString(),
                    PasswordRules    = Module.ShowPasswordRules ? logConfigDP.PasswordRules : null,
                };

                List <LoginConfigDataProvider.LoginProviderDescription> loginProviders = await logConfigDP.GetActiveExternalLoginProvidersAsync();

                if (loginProviders.Count > 0 && Manager.IsInPopup)
                {
                    throw new InternalError("When using external login providers, the Register module cannot be used in a popup window");
                }
                foreach (LoginConfigDataProvider.LoginProviderDescription provider in loginProviders)
                {
                    model.ExternalProviders.Add(new FormButton()
                    {
                        ButtonType = ButtonTypeEnum.Submit,
                        Name       = "provider",
                        Text       = provider.InternalName,
                        Title      = this.__ResStr("logAccountTitle", "Log in using your {0} account", provider.DisplayName),
                        CssClass   = "t_" + provider.InternalName.ToLower(),
                    });
                    YetaWF.Core.Packages.Package package = AreaRegistration.CurrentPackage;
                    string url = VersionManager.GetAddOnPackageUrl(package.AreaName);
                    model.Images.Add(Manager.GetCDNUrl(string.Format("{0}Icons/LoginProviders/{1}.png", url, provider.InternalName)));
                }
                if (Manager.HaveReturnToUrl)
                {
                    model.ReturnUrl = Manager.ReturnToUrl;
                }

                await model.UpdateAsync();

                return(View(model));
            }
        }
예제 #5
0
        public ActionResult TemplateScroller()
        {
            Model model     = new Model {
            };
            string addonUrl = VersionManager.GetAddOnPackageUrl(AreaRegistration.CurrentPackage.AreaName);

            // generate some random data for the scroller items
            for (int index = 0; index < 12; ++index)
            {
                model.Items.Add(new ScrollerItem {
                    Image   = Manager.GetCDNUrl(string.Format("{0}Images/image{1}.png", addonUrl, index)),
                    Title   = string.Format("Item {0}", index),
                    Summary = string.Format("Summary for item {0} - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ", index),
                });
            }
            return(View(model));
        }
예제 #6
0
        public async Task <ActionResult> Show()
        {
            string url  = VersionManager.GetAddOnPackageUrl(AreaRegistration.CurrentPackage.AreaName);
            string path = Utility.UrlToPhysical(url);

            string file;

            if (SiteDefinition.INITIAL_INSTALL_ENDED)
            {
                file = "StartupDone.html";
            }
            else
            {
                file = "StartupPage.html";
            }

            string content = await FileSystem.FileSystemProvider.ReadAllTextAsync(Path.Combine(path, "HTML", file));

            return(Content(content, "text/html"));
        }
예제 #7
0
        private async Task <string> GetHelpFileContentsAsync(HelpInfoDefinition model)
        {
            string urlBase       = $"{VersionManager.GetAddOnPackageUrl(model.Package.AreaName)}Help";
            string urlCustomBase = VersionManager.GetCustomUrlFromUrl(urlBase);
            string file          = $"{model.Name}.html";
            string lang          = MultiString.ActiveLanguage;

            // try custom language specific
            HelpFileInfo helpCustomLang = await TryHelpFileAsync($"{urlCustomBase}/{lang}/{file}", model.UseCache);

            if (helpCustomLang.Exists)
            {
                return(helpCustomLang.Contents);
            }

            // try custom
            HelpFileInfo helpCustom = await TryHelpFileAsync($"{urlCustomBase}/{file}", model.UseCache);

            if (helpCustom.Exists)
            {
                return(helpCustom.Contents);
            }

            // try fallback language specific
            HelpFileInfo helpLang = await TryHelpFileAsync($"{urlBase}/{lang}/{file}", model.UseCache);

            if (helpLang.Exists)
            {
                return(helpLang.Contents);
            }

            // try fallback
            HelpFileInfo help = await TryHelpFileAsync($"{urlBase}/{file}", model.UseCache);

            if (help.Exists)
            {
                return(help.Contents);
            }

            return(null);
        }
예제 #8
0
        public async Task <ActionResult> TinyVisitors()
        {
            using (VisitorEntryDataProvider visitorDP = new VisitorEntryDataProvider()) {
                if (visitorDP.Usable)
                {
                    string addonUrl = VersionManager.GetAddOnPackageUrl(AreaRegistration.CurrentPackage.AreaName);
                    VisitorEntryDataProvider.Info info = await visitorDP.GetStatsAsync();

                    DisplayModel model = new DisplayModel {
                    };
                    model.TodaysAnonymous     = info.TodaysAnonymous;
                    model.TodaysUsers         = info.TodaysUsers;
                    model.YesterdaysAnonymous = info.YesterdaysAnonymous;
                    model.YesterdaysUsers     = info.YesterdaysUsers;
                    model.Tooltip             = this.__ResStr("tooltip", "Today: {0} Users, {1} Anonymous - Yesterday: {2}/{3}", model.TodaysUsers, model.TodaysAnonymous, model.YesterdaysUsers, model.YesterdaysAnonymous);
                    model.ImageUrl            = addonUrl + "Icons/People.png";
                    model.VisitorsUrl         = Module.VisitorsUrl;
                    return(View(model));
                }
                return(new EmptyResult());
            }
        }
예제 #9
0
        /// <summary>
        /// Loads the grid column definitions for a grid.
        /// </summary>
        /// <param name="recordType">The record type for which grid column definitions are to be loaded.</param>
        /// <returns>A GridDictionaryInfo.ReadGridDictionaryInfo object describing the grid.</returns>
        /// <remarks>This method is not used by applications. It is reserved for component implementation.</remarks>
        private static async Task <GridDictionaryInfo.ReadGridDictionaryInfo> LoadGridColumnDefinitionsAsync(Type recordType)
        {
            Dictionary <string, GridColumnInfo> dict = new Dictionary <string, GridColumnInfo>();
            string className = recordType.FullName.Split(new char[] { '.' }).Last();

            string[] s   = className.Split(new char[] { '+' });
            int      len = s.Length;

            if (len != 2)
            {
                throw new InternalError("Unexpected class {0} in record type {1}", className, recordType.FullName);
            }
            string  controller = s[0];
            string  model      = s[1];
            string  file       = controller + "." + model;
            Package package    = Package.GetPackageFromType(recordType);
            string  predefUrl  = VersionManager.GetAddOnPackageUrl(package.AreaName) + "Grids/" + file;
            string  customUrl  = VersionManager.GetCustomUrlFromUrl(predefUrl);

            GridDictionaryInfo.ReadGridDictionaryInfo info;
            GridDictionaryInfo.ReadGridDictionaryInfo predefInfo = await GridDictionaryInfo.ReadGridDictionaryAsync(package, recordType, Utility.UrlToPhysical(predefUrl));

            if (!predefInfo.Success)
            {
                throw new InternalError("No grid definition exists for {0}", file);
            }
            info = predefInfo;
            GridDictionaryInfo.ReadGridDictionaryInfo customInfo = await GridDictionaryInfo.ReadGridDictionaryAsync(package, recordType, Utility.UrlToPhysical(customUrl));

            if (customInfo.Success)
            {
                info = customInfo;
            }
            if (info.ColumnInfo.Count == 0)
            {
                throw new InternalError("No grid definition exists for {0}", file);
            }
            return(info);
        }
예제 #10
0
        public Task <string> RenderViewAsync(AlertDisplayModule module, AlertDisplayModuleController.DisplayModel model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            string rootUrl  = VersionManager.GetAddOnPackageUrl(Package.AreaName);
            string closeUrl = Manager.GetCDNUrl(System.IO.Path.Combine(rootUrl, "Icons", "Close.png"));

            if (model.MessageHandling == DataProvider.AlertConfig.MessageHandlingEnum.DisplayUntilOff)
            {
                string ajaxUrl = Utility.UrlFor(typeof(AlertDisplayModuleController), nameof(AlertDisplayModuleController.Off), new { __ModuleGuid = module.ModuleGuid });

                hb.Append($@"
    <div class='t_close' data-ajaxurl='{Utility.HtmlAttributeEncode(ajaxUrl)}'>
        <img src='{Utility.HtmlAttributeEncode(closeUrl)}' alt='{HAE(this.__ResStr("clsButtonAlt", "Close Button"))}' title='{HAE(this.__ResStr("clsButtonTT", "Click to close alert"))}' />
    </div>");
            }
            hb.Append($@"
<div class='t_message'>
    {model.Message}
</div>");

            return(Task.FromResult(hb.ToString()));
        }
예제 #11
0
        private async Task <ScriptData> ReadScriptAsync(string phoneNumber)
        {
            // find the file
            string addonUrl   = VersionManager.GetAddOnPackageUrl(Softelvdm.Modules.IVR.Controllers.AreaRegistration.CurrentPackage.AreaName);
            string scriptPath = Path.Combine(Utility.UrlToPhysical(VersionManager.GetCustomUrlFromUrl(addonUrl)), "Scripts", $"TWIML{phoneNumber}.txt");

            Logging.AddLog($"Trying script at {scriptPath}");
            if (!await FileSystem.FileSystemProvider.FileExistsAsync(scriptPath))
            {
                Logging.AddLog($"Script at {scriptPath} not found");
                addonUrl   = VersionManager.GetAddOnPackageUrl(Softelvdm.Modules.IVR.Controllers.AreaRegistration.CurrentPackage.AreaName);
                scriptPath = Path.Combine(Utility.UrlToPhysical(addonUrl), "Scripts", $"TWIML{phoneNumber}.txt");
                Logging.AddLog($"Trying script at {scriptPath}");
                if (!await FileSystem.FileSystemProvider.FileExistsAsync(scriptPath))
                {
                    Logging.AddLog($"Script at {scriptPath} not found");
                    return(null);
                }
            }

            ScriptData script = new ScriptData();

            using (ExtensionEntryDataProvider extensionDP = new ExtensionEntryDataProvider()) {
                DataProviderGetRecords <ExtensionEntry> data = await extensionDP.GetItemsAsync(0, 0, null, null);

                foreach (ExtensionEntry extension in data.Data)
                {
                    Extension ext = new Extension {
                        Digits  = extension.Extension,
                        Name    = extension.Description,
                        Numbers = new List <ExtensionNumber>(),
                    };
                    foreach (ExtensionPhoneNumber extPhone in extension.PhoneNumbers)
                    {
                        ext.Numbers.Add(new ExtensionNumber {
                            Number           = extPhone.PhoneNumber,
                            SendSMSVoiceMail = extPhone.SendSMS,
                        });
                    }
                    script.Extensions.Add(ext);
                }
            }

            // load the contents
            List <string> lines = await FileSystem.FileSystemProvider.ReadAllLinesAsync(scriptPath);

            int total = lines.Count;

            // TWIML Snippets
            int lineIx = 0;

            for ( ; lineIx < total; ++lineIx)
            {
                string l = lines[lineIx].Trim();
                if (l.Length > 0 && !l.StartsWith("##"))
                {
                    // tag and parms
                    List <ScriptEntry> entries = new List <ScriptEntry>();
                    for ( ; ;)
                    {
                        if (l.StartsWith(" "))
                        {
                            if (entries.Count > 0)
                            {
                                break;
                            }
                            throw new InternalError($"Tag name expected on line {lineIx + 1} in {scriptPath}");
                        }
                        ScriptEntry entry  = new ScriptEntry();
                        string[]    tokens = l.Split(new char[] { ' ' });
                        if (tokens.Length < 1 || (tokens.Length % 2) != 1)
                        {
                            throw new InternalError($"Unexpected number of arguments on line {lineIx + 1} in {scriptPath}");
                        }
                        entry.Tag = tokens[0].ToLower();
                        for (int tokIx = 1; tokIx < tokens.Length; tokIx += 2)
                        {
                            entry.Parms.Add(new ScriptParm {
                                Name  = tokens[tokIx],
                                Value = tokens[tokIx + 1],
                            });
                        }
                        ++lineIx;
                        l = lines[lineIx];
                        entries.Add(entry);
                    }

                    // text
                    string text = "";
                    for ( ; lineIx < total; ++lineIx)
                    {
                        l = lines[lineIx];
                        if (l.Length == 0)
                        {
                            break;
                        }
                        if (!l.StartsWith(" "))
                        {
                            throw new InternalError($"Unexpected content (not indented) on line {lineIx + 1} in {scriptPath}");
                        }
                        l     = l.Trim();
                        text += l + "\r\n";
                    }
                    foreach (ScriptEntry entry in entries)
                    {
                        entry.Text = text;
                    }

                    script.Scripts.AddRange(entries);
                }
            }
            return(script);
        }