Jump to:

23001 Posts in 11854 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » [SOLVED} Password Protect Individual Page

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1344 Views
  • zenmonkey
    Avatar
    Community Member
    524 Posts

    [SOLVED} Password Protect Individual Page Link to this post

    Is it possible to Password Protect and Individual Page. Creating a Security Group with 1 Member won't work as I am using Current Member checks to block access to portions of the site. Basically this would be a page that would require an Access Code to Enter, but this Access Code will distributed to individuals who shouldn't have access to the data.

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: [SOLVED} Password Protect Individual Page Link to this post

    You could do this with a custom form. Just have a text field and on the post check it to be the correct secret code, write the page content to the session. On the template side use a simple control to check the session for having any value, if it does display it.

    Then when user's session times out POOF! Away goes the secret page content.

  • zenmonkey
    Avatar
    Community Member
    524 Posts

    Re: [SOLVED} Password Protect Individual Page Link to this post

    I Keep getting an Unidentified Index error. I assume this is because I'm dynamically generating the session index with the Page Title so that each AccessCodePage can have its own $_SESSION var. Is there a better solution?

  • zenmonkey
    Avatar
    Community Member
    524 Posts

    Re: [SOLVED} Password Protect Individual Page Link to this post

    Solved Thanks to a Hint from IRC
    I used the Session Class instead of a $_SESSION var

    FYI in the pagetype init function I used

    $sesCheck = Session::get($arIndex);
    if (isset($sesCheck)){
    }
    else
    {
    Session::addToArray($arIndex, 1);
    }

    Later in the form Action

    if (strtolower($data['AccessCode']) == strtolower($this->AccessCode))
          {
             //Compare PageCode to Form Code
             $arIndex= strtolower(str_rot13(str_ireplace(" ","",$this->Title)));
             //Save Code To Session
             Session::set($arIndex,strtolower($this->AccessCode));
             
             
             //add function to Add Name and Email to DataObject
             Director::redirect(Director::baseURL(). $this->URLSegment);
          }

    and Finally my Check Function for my Template

    function CodeCheck(){
          $arIndex= strtolower(str_rot13(str_ireplace(" ","",$this->Title)));
          $sesCheck = Session::get($arIndex);
          
          if ($sesCheck == strtolower($this->AccessCode)) {
             return true;
          }
          else
          {
             return false;   
          }
       }

    1344 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.