Пример #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());
        }
Пример #2
0
        /// <summary>
        /// if the user is in any one of the validRoleNames, authentication will proceed.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="validRoleNames"></param>
        /// <returns></returns>
        public bool CheckAuthentication(HttpContext context, string[] validRoleNames, PortalApplication portalApp)
        {
            var IsValid = false;

            if (WebPortalUser.CheckLogin(_un, _pw, portalApp))
            {
                WebPortalUser u = WebPortalUser.FetchUser(_un, portalApp);

                foreach (string requiredRoleName in validRoleNames)
                {
                    bool b = u.inRole(requiredRoleName);
                    if (b)
                    {
                        Roles.Add(requiredRoleName);
                        IsValid = true;
                    }
                }

                if (IsValid)
                {
                    u.SetLastLoginInDatabaseToNow();
                    return(true);
                }
            }

            return(false);
        }
Пример #3
0
        private string getPageDisplayUrl(WebPortalUser user, CmsPage currentPage, PageDisplayMode displayMode)
        {
            Dictionary <string, string> pageParams = new Dictionary <string, string>();

            pageParams.Add("display", Enum.GetName(typeof(PageDisplayMode), displayMode));
            pageParams.Add("uid", user.uid.ToString());
            return(currentPage.getUrl(pageParams));
        }
        /// <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());
        }
Пример #5
0
 public bool CheckAuthentication(HttpContext context, string requiredRoleName, PortalApplication portalApp)
 {
     if (WebPortalUser.CheckLogin(_un, _pw, portalApp))
     {
         WebPortalUser u = WebPortalUser.FetchUser(_un, portalApp);
         bool          b = u.inRole(requiredRoleName);
         if (b)
         {
             u.SetLastLoginInDatabaseToNow();
             return(true);
         }
     }
     return(false);
 }
Пример #6
0
        /// <summary>
        /// Checks whether a user has write access in this zone.
        /// </summary>
        /// <param name="u"></param>
        /// <returns></returns>
        public bool canWrite(WebPortalUser u)
        {
            if (u != null && u.inRole(CmsConfig.getConfigValue("AdminUserRole", "Administrator")))
            {
                return(true);
            }

            WebPortalUserRole[] roleArray = new WebPortalUserRole[] { WebPortalUserRole.dummyPublicUserRole };
            if (u != null)
            {
                u.AddUserRole(WebPortalUserRole.dummyPublicUserRole); // users are always part of the "public" user role.
                roleArray = u.userRoles;
            }

            CmsZoneUserRoleDb db = new CmsZoneUserRoleDb();

            return(db.fetchRoleMatchingCountForWrite(this, roleArray) > 0);
        }
Пример #7
0
        public void loadGroupsAndCookie(HttpContext context, int cookieTimeoutMinutes, bool persistCookie, PortalApplication portalApp)
        {
            // -- Retrieve the user's groups
            WebPortalUser user = WebPortalUser.FetchUser(_un, portalApp);

            WebPortalUserRole[] Roles = user.userRoles;
            string groups             = "";

            for (int i = 0; i < Roles.Length; i++)
            {
                WebPortalUserRole role = Roles[i];
                groups = groups + role.Name;
                if (i < Roles.Length - 1)
                {
                    groups = groups + groupDelimiter;
                }
            } // for


            // -- Create the authetication ticket
            FormsAuthenticationTicket authTicket =
                new FormsAuthenticationTicket(1,  // version
                                              _un,
                                              DateTime.Now,
                                              DateTime.Now.AddMinutes(cookieTimeoutMinutes),
                                              persistCookie, groups);

            // Now encrypt the ticket.
            string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
            // Create a cookie and add the encrypted ticket to the
            // cookie as data.
            HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

            if (authTicket.IsPersistent)
            {
                authCookie.Expires = authTicket.Expiration;
            }

            Console.Write(authCookie.Path);
            Console.Write(authCookie.Domain);

            // Add the cookie to the outgoing cookies collection.
            context.Response.Cookies.Add(authCookie);
        } // loadGroupsAndCookie
        /// <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());
        }
        /// <summary>
        /// Get all the files attached to this event and render the html.
        /// </summary>
        /// <param name="page"></param>
        /// <param name="lang"></param>
        /// <returns></returns>
        protected string renderAttachedFileList(CmsPage page, CmsLanguage lang, CmsUrlFormat fileUrlFormat)
        {
            List <FileLibraryDetailsData> fileList = new FileLibraryDb().fetchDetailsData(lang, page);

            if (fileList.Count == 0)
            {
                return("");
            }

            WebPortalUser u             = CmsContext.currentWebPortalUser;
            List <string> renderedLinks = new List <string>();

            foreach (FileLibraryDetailsData f in fileList)
            {
                string link = renderAttachedFile(lang, f, u, fileUrlFormat);
                if (link != "")
                {
                    renderedLinks.Add(link);
                }
            }
            if (renderedLinks.Count == 0)
            {
                return("");
            }

            StringBuilder html = new StringBuilder();

            html.Append("<tr valign=\"top\">");
            html.Append("<td>" + getAttachedFilesText(lang) + ":</td>");
            html.Append("<td>" + renderedLinks[0] + "</td>");
            html.Append("</tr>");

            for (int x = 1; x < renderedLinks.Count; x++)
            {
                html.Append("<tr valign=\"top\">");
                html.Append("<td> </td>");
                html.Append("<td>" + renderedLinks[x] + "</td>");
                html.Append("</tr>");
            }

            return(html.ToString());
        }
Пример #10
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());
        }
Пример #11
0
 public bool CheckAuthentication(HttpContext context, PortalApplication portalApp)
 {
     return(WebPortalUser.CheckLogin(_un, _pw, portalApp));
 }
        /// <summary>
        /// Render the html to display an attached file
        /// </summary>
        /// <param name="lang"></param>
        /// <param name="f"></param>
        /// <param name="u"></param>
        /// <returns></returns>
        protected string renderAttachedFile(CmsLanguage lang, FileLibraryDetailsData f, WebPortalUser u, CmsUrlFormat fileUrlFormat)
        {
            CmsPage detailsFilePage = CmsContext.getPageById(f.DetailsPageId);

            if (detailsFilePage.Zone.canRead(u) || detailsFilePage.Zone.canWrite(u))
            {
                string iconTag     = IconUtils.getIconTag(CmsContext.ApplicationPath, false, f.fileExtension);
                string urlDownload = FileLibraryDetailsData.getDownloadAnchorHtml(detailsFilePage, f.Identifier, lang, f.FileName, f.FileName, "_blank", "", fileUrlFormat);

                string urlPage = detailsFilePage.getUrl(lang);
                urlPage = "&#160;&#160;<a href=\"" + urlPage + "\" class=\"rightArrowLink\">" + getSeeFileDetailsText(lang) + "</a>";

                return(iconTag + " " + urlDownload + urlPage);
            }
            return("");
        }