[SOLVED] Password protected news articles / blog posts

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
steelexus
New Member
New Member
Posts: 5
Joined: Wed May 25, 2011 3:07 pm

[SOLVED] Password protected news articles / blog posts

Post by steelexus »

Hi. I've made a simple modifications for individual news articles / blog posts password protection.

So...

1. Lets make a UDT, called "passprotect"

Code: Select all

// Params: 
// passprot - password
// contentprot - protected content, smarty tag, etc.
session_start();
$passprot = $params['passprot']; //read password from field definition
$pass = $_POST[pass];
if ($pass)
{
if ($pass==$passprot)
{
$_SESSION[passprot] = $passprot;
echo $params['contentprot'];
}
else
{
echo 'Wrong password.';
}
}
else
{
echo '
<form method=post>
Enter the password: <INPUT TYPE="PASSWORD" NAME="pass" VALUE="'.$pass.'"> 
<INPUT TYPE="SUBMIT" VALUE="OK">
</FORM>
';
}
$action = $_GET[action];
if ($action=="logout")
{
session_destroy(); // auto log out
}
2. Let's make a field definition (for eg.: in News module).
First field (password protect option on/off):

Code: Select all

*Name: Checkpass
*Type: Checkbox
*Public (yes)
Second field (individual password for article):

Code: Select all

*Name: Articlepass
*Type: Text field/area (Normal field, no wysiwyg)
*Max. length:  255
*Public (yes)
3. Now lets go to the summary template:
Find something like this:

Code: Select all

{else if $entry->content}
    <div class="NewsSummaryContent">
       {eval var=$entry->content}
    </div>
{/if}
And modify it, into this:

Code: Select all

{else if $entry->content}

	<div class="NewsSummaryContent">
		{if $entry->checkpass==1}
                   Password protected article {$entry->morelink}
                {else}
		  {eval var=$entry->content}
                {/if}
	</div>
{/if}
First IF - if summary is empty - show me content
Second IF - but if the content is protected (the checkbox called "Checkpass" is selected in this article) - show me "more link" only, and hide the content.

4. Almost done. Lets go to our detail article template:
Find something like this:

Code: Select all

<div id="NewsPostDetailContent">
	{eval var=$entry->content}
</div>
And transform it into this:

Code: Select all

<div id="NewsPostDetailContent">
      {if $entry->checkpass==1}

    {passprotect passprot==$entry->articlepass contentprot==$entry->content }

        {else}
	{eval var=$entry->content}
Done. Its works fine for me.

Make a new article and fill the password field (Articlepass) and check the checkbox (Checkpass) to activate it.

Tell me if something goes wrong (maybe I've done some typo mistake etc.)



All best.
Post Reply

Return to “The Lounge”