Beispiel #1
0
        private string getListUsersDisplay()
        {
            StringBuilder html = new StringBuilder();

            WebPortalUserRole[] allRoles = getAllAvailableRoles();

            CmsPage currPage = CmsContext.currentPage;

            html.Append("<table cellpadding=\"2\">" + Environment.NewLine);
            foreach (WebPortalUserRole role in allRoles)
            {
                html.Append("<tr><td style=\"background-color: #CCC;\" colspan=\"2\"><strong>" + role.Description + " (" + role.Name + ")</strong></td></tr>" + Environment.NewLine);
                WebPortalUser[] users = WebPortalUser.FetchAll(role, CmsPortalApplication.GetInstance());
                if (users.Length == 0)
                {
                    html.Append("<tr><td><em>there are no users with this security level</em></td></tr>" + Environment.NewLine);
                }
                else
                {
                    foreach (WebPortalUser user in users)
                    {
                        string editUrl = getPageDisplayUrl(user, currPage, PageDisplayMode.EditSelectedUser);
                        html.Append("<tr><td>" + user.UserName + "</td><td><a href=\"" + editUrl + "\">edit</a></td></tr>" + Environment.NewLine);
                    } // foreach user
                }
            }         // foreach role

            html.Append("</table>");

            html.Append("(<a href=\"" + getPageDisplayUrl(new WebPortalUser(), currPage, PageDisplayMode.AddUser) + "\">add a new user</a>)");

            return(html.ToString());
        }
        /// <summary>
        /// Under edit mode, render the right hand side of the file details page as form (HTML INPUT or TEXTAREA, etc...)
        /// </summary>
        /// <param name="detailsPage"></param>
        /// <param name="identifier"></param>
        /// <param name="lang"></param>
        /// <param name="fileData"></param>
        /// <param name="controlId"></param>
        /// <returns></returns>
        protected string renderRightPaneForm(CmsPage detailsPage, int identifier, CmsLanguage lang, FileLibraryDetailsData fileData, string controlId, CmsUrlFormat fileUrlFormat)
        {
            string        fName = fileData.FileName;
            StringBuilder html  = new StringBuilder();

            html.Append("<div style=\"float: left;\" class=\"listing\">" + EOL);

            html.Append(renderDiv(getFileText(lang), FileLibraryDetailsData.getDownloadAnchorHtml(detailsPage, identifier, lang, fName, fileUrlFormat)));

            string cssClass                  = "fileLibrary_categoryId";
            string popupCategory             = FileLibraryCategoryData.getEditPopupAnchor(lang, cssClass, getEditText(lang));
            string htmlId                    = controlId + "categoryId";
            NameValueCollection categoryColl = new NameValueCollection();

            foreach (FileLibraryCategoryData c in categoryList)
            {
                categoryColl.Add(c.CategoryId.ToString(), c.CategoryName);
            }
            string selectCategory = getCategoryOption(lang, controlId, fileData.CategoryId);

            html.Append(renderDiv(getCategoryText(lang) + " " + popupCategory, selectCategory));

            htmlId = controlId + "author";
            html.Append(renderDiv(getAuthorText(lang), PageUtils.getInputTextHtml(htmlId, htmlId, fileData.Author, 30, 50)));

            htmlId = controlId + "description";
            html.Append(renderDiv(getDocumentAbstractText(lang), PageUtils.getTextAreaHtml(htmlId, htmlId, fileData.Description, 25, 5)));

            if (getFileTypeName(fileData).EndsWith("graphic", StringComparison.CurrentCultureIgnoreCase))
            {
                string imgPreviewUrl = CmsContext.UserInterface.ShowThumbnailPage.getThumbDisplayUrl(FileLibraryDetailsData.getDownloadUrl(detailsPage, identifier, lang, fName, fileUrlFormat), 200, -1);
                string imgTag        = "<img border=\"0\" src=\"" + imgPreviewUrl + "\"></a>";
                html.Append(renderDiv(getImagePreviewText(lang), FileLibraryDetailsData.getDownloadAnchorHtml(detailsPage, identifier, lang, fName, imgTag, "_blank", "", fileUrlFormat)));
            }

            bool eventRequired = FileLibraryCategoryData.isEventRequired(categoryList, fileData.CategoryId);

            if (eventRequired || fileData.EventPageId >= 0)
            {
                htmlId = controlId + "eventPageId";
                html.Append(renderDiv(getAttachedEventText(lang), getEventOption(lang, controlId, fileData.EventPageId, eventRequired)));
            }

            WebPortalUser u = WebPortalUser.FetchUser(fileData.CreatedBy, CmsPortalApplication.GetInstance());
            string        uploadPersonName = (u == null) ? fileData.CreatedBy : u.FullName;

            html.Append(renderDiv(getUploadedByText(lang), uploadPersonName));

            html.Append(renderDiv(getLastUpdatedText(lang), detailsPage.LastUpdatedDateTime.ToString("MMMM d yyyy h:mm tt")));

            html.Append("</div>" + EOL);
            return(html.ToString());
        }
        /// <summary>
        /// Render right hand side of the file details page (all details)
        /// </summary>
        /// <param name="detailsPage"></param>
        /// <param name="identifier"></param>
        /// <param name="lang"></param>
        /// <param name="fileData"></param>
        /// <returns></returns>
        protected string renderRightPane(CmsPage detailsPage, int identifier, CmsLanguage lang, FileLibraryDetailsData fileData, CmsUrlFormat fileUrlFormat)
        {
            string        fName = fileData.FileName;
            StringBuilder html  = new StringBuilder();

            html.Append("<div style=\"float: left;\" class=\"listing\">" + EOL);

            html.Append(renderDiv(getFileText(lang), FileLibraryDetailsData.getDownloadAnchorHtml(detailsPage, identifier, lang, fName, fileUrlFormat)));
            html.Append(renderDiv(getCategoryText(lang), fileData.getCategoryName(categoryList)));

            html.Append(renderDiv(getAuthorText(lang), fileData.Author));
            html.Append(renderDiv(getDocumentAbstractText(lang), StringUtils.nl2br(fileData.Description)));

            if (getFileTypeName(fileData).EndsWith("graphic", StringComparison.CurrentCultureIgnoreCase))
            {
                string imgPreviewUrl = CmsContext.UserInterface.ShowThumbnailPage.getThumbDisplayUrl(FileLibraryDetailsData.getDownloadUrl(detailsPage, identifier, lang, fName, fileUrlFormat), 200, -1);
                string imgTag        = "<img border=\"0\" src=\"" + imgPreviewUrl + "\"></a>";
                html.Append(renderDiv(getImagePreviewText(lang), FileLibraryDetailsData.getDownloadAnchorHtml(detailsPage, identifier, lang, fName, imgTag, "_blank", "", fileUrlFormat)));
            }

            bool eventRequired = FileLibraryCategoryData.isEventRequired(categoryList, fileData.CategoryId);

            if (eventRequired)
            {
                string eventHtml = "(n/a)";
                if (fileData.EventPageId > -1)
                {
                    CmsPage eventPage = CmsContext.getPageById(fileData.EventPageId);
                    eventHtml = "<a href=\"" + eventPage.getUrl(lang) + "\">" + eventPage.getTitle(lang) + "</a>" + EOL;
                }
                html.Append(renderDiv(getAttachedEventText(lang), eventHtml));
            }

            WebPortalUser u = WebPortalUser.FetchUser(fileData.CreatedBy, CmsPortalApplication.GetInstance());
            string        uploadPersonName = (u == null) ? fileData.CreatedBy : u.FullName;

            html.Append(renderDiv(getUploadedByText(lang), uploadPersonName));

            html.Append(renderDiv(getLastUpdatedText(lang), detailsPage.LastUpdatedDateTime.ToString("MMMM d yyyy h:mm tt")));

            html.Append("</div>" + EOL);
            return(html.ToString());
        }
Beispiel #4
0
        private string getEditUserDisplay(int userId, CmsPage page)
        {
            string _errorMessage   = "";
            string _successMessage = "";

            bool          isEditingExisting = false;
            WebPortalUser user = WebPortalUser.FetchUser(userId, CmsPortalApplication.GetInstance());

            if (user != null)
            {
                isEditingExisting = true;
            }
            else
            {
                user = new WebPortalUser();
            }

            string userRole = "";

            if (user.userRoles.Length > 0)
            {
                userRole = getBestMatchingUserRoleName(getAllAvailableRoles(), user.userRoles);
            }

            string formaction = PageUtils.getFromForm("formaction", "");

            if (string.Compare(formaction, "saveupdates", true) == 0)
            {
                string un = PageUtils.getFromForm("username", user.UserName);
                if (un.Trim() == "")
                {
                    _errorMessage = "Please specify a username";
                }

                if (_errorMessage == "" && !isEditingExisting && WebPortalUser.FetchUser(un, CmsPortalApplication.GetInstance()) != null)
                {
                    _errorMessage = "A user with the username '" + un + "' already exists. Please use another username.";
                }

                string pw = PageUtils.getFromForm("password", user.Password);
                if (_errorMessage == "" && pw.Trim() == "")
                {
                    _errorMessage = "Blank passwords are not allowed.";
                }

                /*
                 * if (pw1 != pw2)
                 * {
                 *  errorMessage = "Passwords do not match.";
                 *  return;
                 * }*/

                string selRole = PageUtils.getFromForm("roles", userRole);
                if (selRole.Trim() == "")
                {
                    _errorMessage = "Please select the user's access level";
                }

                if (_errorMessage == "" && WebPortalUserRole.Fetch(selRole) == null)
                {
                    _errorMessage = "Invalid security group '" + selRole + "' (does not exist)";
                }


                if (_errorMessage == "")
                {
                    user.UserName = un;
                    user.Password = pw;

                    bool b = false;

                    user.ClearAllUserRoles();
                    user.AddUserRole(WebPortalUserRole.Fetch(selRole));
                    b = user.SaveToDatabase();
                    if (!b)
                    {
                        _errorMessage = "Fatal Error: could not save user to database.";
                    }
                    else
                    {
                        _successMessage = "User '" + un + "' has been saved.";
                    }
                }
            } // if saveUpdates

            StringBuilder html   = new StringBuilder();
            string        formId = "EditUsers";

            html.Append(page.getFormStartHtml(formId));
            if (_errorMessage != "")
            {
                html.Append("<p style=\"color: red;\">" + _errorMessage + "</p>");
            }
            if (_successMessage != "")
            {
                html.Append("<p style=\"color: green;\">" + _successMessage + "  - <a href=\"" + getPageDisplayUrl(new WebPortalUser(), page, PageDisplayMode.ListUsers) + "\">back to user list</a></p>");
            }
            html.Append("<table>");
            // -- User name
            html.Append("<tr><td>Username: </td><td>" + Environment.NewLine);
            if (!isEditingExisting)
            {
                html.Append(PageUtils.getInputTextHtml("username", "username", user.UserName, 30, 255));
            }
            else
            {
                html.Append(user.UserName);
            }
            html.Append("</td></tr>" + Environment.NewLine);

            // -- Password
            html.Append("<tr><td>Password: </td><td>");
            html.Append(PageUtils.getInputTextHtml("password", "password", user.Password, 30, 255));
            html.Append("</td></tr>" + Environment.NewLine);



            NameValueCollection roleOpts = new NameValueCollection();

            foreach (WebPortalUserRole role in getAllAvailableRoles())
            {
                roleOpts.Add(role.Name, role.Name + " - " + role.Description);
            }
            html.Append("<tr><td>Access Level: </td><td>");
            html.Append(PageUtils.getRadioListHtml("roles", "role", roleOpts, userRole, "", "<br />"));
            html.Append("</td></tr>" + Environment.NewLine);

            html.Append("</table>");

            html.Append(PageUtils.getHiddenInputHtml("formaction", "saveupdates"));
            html.Append(PageUtils.getHiddenInputHtml("uid", userId.ToString()));
            html.Append(PageUtils.getHiddenInputHtml("display", Enum.GetName(typeof(PageDisplayMode), PageDisplayMode.EditSelectedUser)));

            html.Append("<input type=\"submit\" value=\"save\">");
            html.Append(" <input type=\"button\" value=\"cancel\" onclick=\"window.location = '" + page.Url + "'\">");
            html.Append(page.getFormCloseHtml(formId));

            if (isEditingExisting)
            {
                formId = "delUser";
                html.Append(page.getFormStartHtml(formId));
                html.Append(PageUtils.getHiddenInputHtml("formaction", "deleteuser"));
                html.Append(PageUtils.getHiddenInputHtml("uid", userId.ToString()));
                html.Append(PageUtils.getHiddenInputHtml("display", Enum.GetName(typeof(PageDisplayMode), PageDisplayMode.EditSelectedUser)));

                html.Append("<p align=\"right\"><input type=\"submit\" value=\"delete user\"></p>");
                html.Append(page.getFormCloseHtml(formId));
            }

            return(html.ToString());
        }
Beispiel #5
0
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            string notFound     = Guid.NewGuid().ToString();
            int    targetPageId = PageUtils.getFromForm("target", Int32.MinValue);

            if (targetPageId < 0)
            {
                targetPageId = CmsContext.HomePage.ID;
            }

            CmsPage targetPage = CmsContext.getPageById(targetPageId);


            string ReturnUrl = PageUtils.getFromForm("ReturnUrl", "");

            CmsPage page = CmsContext.currentPage;

            string _errorMessage = "";

            string action = PageUtils.getFromForm("action", "");
            string un     = PageUtils.getFromForm("un", "");
            string pw     = PageUtils.getFromForm("pw", "");


            // -- logoff action
            if (CmsContext.currentUserIsLoggedIn && action.ToLower().Trim() == "logoff")
            {
                WebPortalAuthentication.SignOut();
                CmsContext.setEditModeAndRedirect(CmsEditMode.View, targetPage);
            }

            // -- login action
            if (action.ToLower().Trim() == "login")
            {
                WebPortalAuthentication auth = new WebPortalAuthentication(un, pw);
                string[] validRoleNames      = new string[] { CmsConfig.getConfigValue("LoginUserRole", new Guid().ToString()), CmsConfig.getConfigValue("AuthorAccessUserRole", "Author"), CmsConfig.getConfigValue("AdminUserRole", "Administrator") };
                if (auth.CheckAuthentication(System.Web.HttpContext.Current, validRoleNames, CmsPortalApplication.GetInstance()))
                {
                    // load cookie for 100 days
                    auth.loadGroupsAndCookie(System.Web.HttpContext.Current, 60 * 24 * 100, true, CmsPortalApplication.GetInstance());
                    // redirect
                    if (ReturnUrl.Trim() != "")
                    {
                        System.Web.HttpContext.Current.Response.Redirect(ReturnUrl);
                    }
                    else
                    {
                        CmsContext.setEditModeAndRedirect(CmsEditMode.View, targetPage);
                    }
                }
                _errorMessage = "Invalid Username or Password. Please try again.";
            }

            // string onloadJS = CmsPage.getOnloadJavascript("setLoginFocus");
            // use eventListeners wherever possible so that any other onload events are also fired.
            string onloadJS = @"				
				    // setLoginFocus			
					var el = document.getElementById('input_login_un');	
					el.focus();
				
			"            ;

            page.HeadSection.AddJSOnReady(onloadJS);

            StringBuilder html   = new StringBuilder();
            string        formId = "loginForm";

            html.Append(page.getFormStartHtml(formId));
            html.Append("<p><strong>Login: </strong><br>");
            html.Append("<table>");
            if (_errorMessage != "")
            {
                html.Append("<tr>");
                html.Append("<td colspan=\"2\" align=\"center\">");
                html.Append("<span style=\"color: red;\">" + _errorMessage + "</span>");
                html.Append("</td>");
                html.Append("<tr>");
            }
            html.Append("<tr>");
            html.Append("<td>Username: </td><td><input id=\"input_login_un\" type=\"text\" value=\"" + un + "\" name=\"un\" size=\"40\"></td>");
            html.Append("</tr>");
            html.Append("<tr>");
            html.Append("<td>Password: </td><td><input type=\"password\" name=\"pw\" size=\"40\"></td>");
            html.Append("</tr>");
            html.Append("</table>");
            html.Append("<input type=\"hidden\" name=\"target\" value=\"" + targetPageId.ToString() + "\">");
            html.Append("<input type=\"hidden\" name=\"ReturnUrl\" value=\"" + ReturnUrl + "\">");
            html.Append("<input type=\"hidden\" name=\"action\" value=\"login\">");
            html.Append("<input type=\"submit\" value=\"login\">");

            html.Append(page.getFormCloseHtml(formId));
            writer.WriteLine(html.ToString());
        }