DotNetNuke: Terms and Conditions Module

 

The Terms and Conditions module requires that all users accept the portal's Terms and Conditions before being allowed to access the portal.

Download: TermsAndConditions_01.00.00_Install.zip (this link contains the install and source) (note: If using DotNetNuke 4, You must download, install, place on a page in your DotNetNuke website, and run LinqPrep first. You can obtain it here: http://www.adefwebserver.com/DotNetNukeHELP/Misc/LinqPrep/ )

The Module

After installing the module...

Select Settings

Under Page Settings, uncheck Display Container? and Allow Print?

Under Advanced Settings, select Display Module On All Pages

Click the Update button at the bottom of the Settings page.

When a non-Administrator logs onto the site they will be presented with the Terms and Conditions. If they Decline they will be logged out.

When logged in as an Administrator, you can select Administration.

If the Terms and Conditions are changed, clicking the Clear all Records button will require all users to acknowledge the new Terms and Conditions again. 

The Code

The following code is used to determine if the terms and conditions is to be displayed:

using System;
using DotNetNuke.Common;
using System.Linq;
using DotNetNuke.Security;

namespace TermsAndConditions
{
    public partial class View : DotNetNuke.Entities.Modules.PortalModuleBase, 
        DotNetNuke.Entities.Modules.IActionable
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Only show Terms and Conditions if 
            // user is NOT an Administrator
            // user has not already agreed
            // user is logged in
            if (UserId > -1 && 
                !(((UserInfo.IsInRole("Administrators") || UserInfo.IsSuperUser))))
            {
                ShowTermsAndConditions();
            }
        }

        #region ShowTermsAndConditions
        private void ShowTermsAndConditions()
        {
            TermsAndConditionsDALDataContext objTermsAndConditionsDALDataContext =
                new TermsAndConditionsDALDataContext();

            var result = (from TermsAndConditions_Agreements in
                              objTermsAndConditionsDALDataContext.TermsAndConditions_Agreements
                          where TermsAndConditions_Agreements.UserID == UserId
                          select TermsAndConditions_Agreements).FirstOrDefault();

            if (result == null)
            {
                Response.Redirect(Globals.NavigateURL(PortalSettings.ActiveTab.TabID,
                    "Agreement", "mid=" + ModuleId.ToString()));
            }
        } 
        #endregion

        #region IActionable Members
        public DotNetNuke.Entities.Modules.Actions.ModuleActionCollection ModuleActions
        {
            get
            {
                DotNetNuke.Entities.Modules.Actions.ModuleActionCollection Actions =
                    new DotNetNuke.Entities.Modules.Actions.ModuleActionCollection();
                Actions.Add(
                    GetNextActionID(),
                    "Administration",
                    DotNetNuke.Entities.Modules.Actions.ModuleActionType.AddContent, "", "",
                    EditUrl(), false, SecurityAccessLevel.Edit, true, false);

                return Actions;
            }
        }
        #endregion
    }
}

The following code is used to display the Terms and Conditions and allow a user to accept or decline:

using System;
using DotNetNuke.Security;
using DotNetNuke.Common;
using System.Linq;

namespace TermsAndConditions
{
    public partial class Agreement : DotNetNuke.Entities.Modules.PortalModuleBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lblTerms.Text = DotNetNuke.Services.Localization.Localization.GetSystemMessage
                (PortalSettings, "MESSAGE_PORTAL_TERMS");
        }

        #region lnkBack_Click
        protected void lnkBack_Click(object sender, EventArgs e)
        {
            Response.Redirect(Globals.NavigateURL());
        }
        #endregion

        #region btnAgree_Click
        protected void btnAgree_Click(object sender, EventArgs e)
        {
            TermsAndConditionsDALDataContext objTermsAndConditionsDALDataContext = 
                new TermsAndConditionsDALDataContext();

            var result = (from TermsAndConditions_Agreements in 
                              objTermsAndConditionsDALDataContext.TermsAndConditions_Agreements
                          where TermsAndConditions_Agreements.UserID == UserId
                          select TermsAndConditions_Agreements).FirstOrDefault();

            if (result == null)
            {
                TermsAndConditions_Agreement objTermsAndConditions_Agreement = 
                    new TermsAndConditions_Agreement();

                objTermsAndConditions_Agreement.AgreementDate = DateTime.Now;
                objTermsAndConditions_Agreement.IPAddress = Request.ServerVariables["REMOTE_ADDR"];
                objTermsAndConditions_Agreement.UserID = UserId;

                objTermsAndConditionsDALDataContext.
                    TermsAndConditions_Agreements.InsertOnSubmit(objTermsAndConditions_Agreement);
                objTermsAndConditionsDALDataContext.SubmitChanges();
            }

            // Redirect the user to the current page
            Response.Redirect(Globals.NavigateURL());
        }
        #endregion

        #region btnDecline_Click
        protected void btnDecline_Click(object sender, EventArgs e)
        {
            // Logout user
            PortalSecurity objPortalSecurity = new PortalSecurity();
            objPortalSecurity.SignOut();

            // Redirect the user to the current page
            Response.Redirect(Globals.NavigateURL());
        }
        #endregion
    }
}

 

[Back to: The ADefWebserver DotNetNuke HELP WebSite]

 


Buy DotNetNuke Modules from Snowcovered

 DotNetNuke Powered!DotNetNuke is a registered trademark of DotNetNuke Corporation.