ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Password protect entire site

June 28, 2011 11:10am

Subscribe [3]
  • #1 / Jun 28, 2011 11:10am

    AnneW

    15 posts

    Hi,
    I´m not a developer and a complete newbie on EE. But I volunteered to set up a small webpage for an exclusive auto-club which I am a member in. We have a roof of maximum 50 member, and I have started to registering everybody in the member module with username and password. Since the members are people who don´t like to display themselves on internet the whole site must be closed for others than members.
    Well, I have managed to set up a simple website where we can post the info we want, I just have to tune it and get a better display/design. I have also attached an EE discussion forum which opens in a new window. The forum has the functionality with login with username and password from the member module which I want for the rest of the site, no other people can read the posts. 

    How can I do this in the easiest way?
    I would like to have a box on the front page (which others can read) with field for username and password and a login button. If you enter a valid username and password you can see all the other pages, if not you dont get further.
    Or:
    A pop-up window could ask for the username and password.

    Can anyone help me with how to solve this? Remember I´m not a developer and new to EE.  :roll:

    Anne 😊

  • #2 / Jun 29, 2011 5:47am

    John Henry Donovan

    12339 posts

    Hi Anne,

    To add a login form to any template you just need to use the Login Form Tag example from the docs


    Then you could use the Template Access Restriction for each template you have on your site to restrict it to your member’s group.

    You don’t need to use HTTP Authentication but for the option of a page to show then an unauthorized memebr views that template choose the template where you have placed your login form.


    Does that help?

  • #3 / Jun 29, 2011 6:38am

    AnneW

    15 posts

    Thanks John, thats a good start! 😊

    I put the code into the includes/.header template, and the boxes for checking in showed up there. I just hav to adjust it so that it gets placed in the middle and is straight.

    But when I put in my name and password and ticked for auto-login on future visits I expected the form to go away. But it seems as if nothing happens, everything looks the same. And if I´m not logged in I´m still able to access all the pages.

    First of all, where is it most sensible to put this code? It should protect all the pages but one should only have to login once.
    Secondly, why does it not seem to log me in?
    And thirdly, how make it showed that I am logged in when I actually am?

    I really appreciate your help as I´m new to EE and have a hard time figuring out how it all plays together.  😊

  • #4 / Jun 29, 2011 6:48am

    John Henry Donovan

    12339 posts

    Anne,

    I would create a separate template for logging in with just the login form on it.
    You want the whole site protected yes? So there is no need to have this appear in the header for all pages because somebody is not going to see them as they wont be allowed browse the site in the first place

    Then this is the page I would link to in your Template Access preferences.

    You are probably logged in and you just don’t have anything in your template to show it.

    There are 2 conditionals to help with this {if logged_in} and {if logged_out}

    Try something like the following

    {if logged_in}
    <a href="http://{path=LOGOUT}">Log out</a>
    {/if}
    
    {if logged_out}
    {exp:member:login_form return="site/index"}
    
    <label>Username</label>
    
    <input type="text" name="username" value="" maxlength="32" class="input" size="25" /></p>
    
    <label>Password</label>
    
    <input type="password" name="password" value="" maxlength="32" class="input" size="25" /></p>
    
    {if auto_login}
    <input class='checkbox' type='checkbox' name='auto_login' value='1' /> Auto-login on future visits
    {/if}
    
    <input class='checkbox' type='checkbox' name='anon' value='1' checked='checked' /> Show my name in the online users list
    
    <input type="submit" name="submit" value="Submit" /></p>
    
    <a href="http://{path=member/forgot_password}">Forgot your password?</a>
    
    {/exp:member:login_form}
    {/if}
  • #5 / Jun 29, 2011 7:42am

    AnneW

    15 posts

    Thanks John!

    You are correct, I want to protect the whole site.
    Since i´m so unsure about this, is this what you mean?:
    1. I make a template called for eksampel login
    2. I paste in the code from the login form tag example in the index of this template and save it

    You say “then this is the page I would like to link to in your Template Access preferences”. What exactly do you mean? Do you mean the login index file that I made? How do I access the Template Access preferences? Is it in the Templates Preferences Manager? Should I make login/index my default site’s home page?
    The code you showed me, should I paste this into the login/index file with the code from “login form tag” example?
    Will the result now be that when a person that is not logged in goes to my site the login page will open first, and then if they enter a valid username and password they will go to the normal inex-page of the site.

    I´m so sorry that I need to get this in with a teaspoon.  :red:

  • #6 / Jul 01, 2011 5:26pm

    Sue Crocker

    26054 posts

    Hi, AnneW.

    It sounds like what John Henry is saying is that since there won’t be any links for spiders to crawl, you should be OK.

    Here’s how I’d handle it.

    (My approach is slightly different from John’s.)

    Create a page called login/index. Make login/index your default template group.

    See: HowTo Change the Default Template Group

    Does that help?

  • #7 / Jul 01, 2011 9:06pm

    AnneW

    15 posts

    Hi Sue,

    This certainly helps. The login form/page now pops up before I´m allowed to enter the site. Thanks a lot! 😊

    As far as I can see there is only one remaining thing to solve now.
    Inside the site I can move around normally. But when I hit the home button the login form/page pops up again even though I ticked off for “Auto-login on future visits”.
    How can I make the system remember that I´m already logged in and that I have to log in every time I hit the home button?

    I really appreciate your help.

    Best regards
    Anne 😊

  • #8 / Jul 03, 2011 6:28am

    Sue Crocker

    26054 posts

    Hi, AnneW.

    You add a condition to your main page -

    See: http://eebeginners.com/index.php/begin/articles/how-do-i-know-im-logged-in

    You’d put your login form in between the if logged_in code.

    Does that help?

  • #9 / Jul 03, 2011 7:13pm

    AnneW

    15 posts

    Hi Sue, thanks for your answer. 😊

    First of all, I think I wrote wrongly. The correct is that I dont want the login form to appear every time I hit the home button. I want to login once, and then keep me logged in if I tick off for that.

    So what I have now is the login/index which is also made the main page (default group). This is the code:

    {exp:member:login_form return="site/index"}
    
        <label>Username</label>
    
    
        <input type="text" name="username" value=""  maxlength="32" class="input" size="25" /></p>
    
            <label>Password</label>
    
    
        <input type="password" name="password" value="" maxlength="32" class="input" size="25" /></p>
    
        {if auto_login}
    
        <input class='checkbox' type='checkbox' name='auto_login' value='1'  /> Auto-login on future visits
    
        {/if}
    
        <input class='checkbox' type='checkbox' name='anon' value='1'
        checked='checked' />  Show my name in the online users list
    
        <input type="submit" name="submit" value="Submit" /></p>
    
        <a href="http://{path=member/forgot_password}">Forgot your password?</a>
    
    {/exp:member:login_form}

    And I have the site-page (site/index) which is the “home-page” with this code:

    {embed="includes/.head"}
    
      </head>
    <body>
    
        {embed="includes/.header"}
        {embed="includes/.navigation"}
    <div class="container_12 content">
        <div class="grid_12">
            {exp:channel:entries channel="forside" orderby="date" sort="desc" limit="10" disable="member_data|trackbacks"}
                <h2>{title}</h2>
    <p>            {page_body}<br />
            {/exp:channel:entries}<br />
        </div><br />
        <div class="clear"></div><br />
    </div></p>
    
    <p>{embed="includes/.footer"}<br />
    {embed="includes/.analytics"}<br />
    </body><br />
    </html>

    When you say I have to add a condition to my main page, do you mean site/index or login/index?

    Well I assumed that you meant the login/index and I changed the code to this:

    {if logged_in}
    You're logged in!
    {if:else}
    {/if} 
    
    {exp:member:login_form return="site/index"}
    
        <label>Username</label>
    
    
        <input type="text" name="username" value=""  maxlength="32" class="input" size="25" /></p>
    
            <label>Password</label>
    
    
        <input type="password" name="password" value="" maxlength="32" class="input" size="25" /></p>
    
        {if auto_login}
    
        <input class='checkbox' type='checkbox' name='auto_login' value='1'  /> Auto-login on future visits
    
        {/if}
    
        <input class='checkbox' type='checkbox' name='anon' value='1'
        checked='checked' />  Show my name in the online users list
    
        <input type="submit" name="submit" value="Submit" /></p>
    
        <a href="http://{path=member/forgot_password}">Forgot your password?</a>
    
    {/exp:member:login_form}
    {/if}

    But now nothing shows up, the whole page is blank. Am I misunderstanding you? What am I doing wrong?

  • #10 / Jul 06, 2011 10:29am

    Sue Crocker

    26054 posts

    Hi, AnneW.

    Your first if is slightly off.

    Here’s what I’d do:

    {if logged_out}
    ... all the exp:member login stuff
    {/if}
    {if logged_in}
    Welcome back!
    {/if}

    Give that a try. You can check for logged_in or logged_out - either will work. Notice how I set the two different if statements up instead of nesting them.

  • #11 / Jul 06, 2011 9:27pm

    AnneW

    15 posts

    Hi Sue,

    Thanks for your help!  😊

    When I used the

    {if logged_in}
    Welcome back!
    {/if}

    a white page showed up and I was not able to go further.
    But when I changed the Welcome back with the code from site/index the page opened up. It seems to work now. But I´m not sure if this is the right way to do this. Does this look correct?
    If this is ok I´m ready to fill the site with content.  😊

    {if logged_out}
    
    {exp:member:login_form return="site/index"}
    
    
        <label>Username</label>
    
    
        <input type="text" name="username" value=""  maxlength="32" class="input" size="25" /></p>
    
            <label>Password</label>
    
    
        <input type="password" name="password" value="" maxlength="32" class="input" size="25" /></p>
    
        {if auto_login}
    
        <input class='checkbox' type='checkbox' name='auto_login' value='1'  /> Auto-login on future visits
    
        {/if}
    
        <input class='checkbox' type='checkbox' name='anon' value='1'
        checked='checked' />  Show my name in the online users list
    
        <input type="submit" name="submit" value="Submit" /></p>
    
        <a href="http://{path=member/forgot_password}">Forgot your password?</a>
    
    {/exp:member:login_form}
    {/if}
    
    {if logged_in}
    
        {embed="includes/.head"}
      </head>
    <body>
        {embed="includes/.header"}
        {embed="includes/.navigation"}
    <div class="container_12 content">
        <div class="grid_12">
            {exp:channel:entries channel="forside" orderby="date" sort="desc" limit="10" disable="member_data|trackbacks"}
                <h2>{title}</h2>
    <p>            {page_body}<br />
            {/exp:channel:entries}<br />
        </div><br />
        <div class="clear"></div><br />
    </div></p>
    
    <p>{embed="includes/.footer"}<br />
    {embed="includes/.analytics"}<br />
    </body><br />
    </html></p>
    
    <p>{/if}

  • #12 / Jul 07, 2011 1:48pm

    Kevin Smith

    4784 posts

    Hi AnneW,

    I went back through some of your posts and enclosed your code samples with code brackets to make it easier to read. When you’re posting, you can find them in the gray bar above the textarea.

    When I used the

    {if logged_in}
    Welcome back!
    {/if}

    a white page showed up and I was not able to go further.

    Do you mean that this code sample is all you had in your template? If so, and you’re not logged in while viewing it, then you would get a white page. What did you see when you used Sue’s most recent suggestion?

    Your full template example looks good to me, but the real test will come when you try it out yourself on the site. When you do that, does everything work as intended?

  • #13 / Jul 07, 2011 7:46pm

    AnneW

    15 posts

    Hi Kevin,

    No, of course not. 😊

    I probably misunderstood Sue. Therefore the code in my template login/index was:

    {if logged_out}

    {exp:member:login_form return="site/index"}


      <label>Username</label>


      <input type=“text” name=“username” value=””  maxlength=“32” class=“input” size=“25” /></p>

          <label>Password</label>


      <input type=“password” name=“password” value=”” maxlength=“32” class=“input” size=“25” /></p>

      {if auto_login}

      <input class=‘checkbox’ type=‘checkbox’ name=‘auto_login’ value=‘1’  /> Auto-login on future visits

      {/if}

      <input class=‘checkbox’ type=‘checkbox’ name=‘anon’ value=‘1’
      checked=‘checked’ />  Show my name in the online users list

      <input type=“submit” name=“submit” value=“Submit” /></p>

      Forgot your password?

    {/exp:member:login_form}
    {/if}

    {if logged_in}

    Welcome back!

    {/if}

    And of course that didn´t work. When logging in a white page page opened with the text “Welcome back!”. Nothing else, and no possibility to get anywhere else.

    I then thought that I had to put in a link to the site/index. But since I was not sure how to do that I tried to paste in the entire code from the site/index in between the {if logged_in} and the {/if} instead of the “Welcome back!”. The result was the code below in the login/index. I have tried it out from several computers, and it seems to work as intended. Thanks you guys!  😊

    {if logged_out}

    {exp:member:login_form return="site/index"}


      <label>Username</label>


      <input type=“text” name=“username” value=””  maxlength=“32” class=“input” size=“25” /></p>

          <label>Password</label>


      <input type=“password” name=“password” value=”” maxlength=“32” class=“input” size=“25” /></p>

      {if auto_login}

      <input class=‘checkbox’ type=‘checkbox’ name=‘auto_login’ value=‘1’  /> Auto-login on future visits

      {/if}

      <input class=‘checkbox’ type=‘checkbox’ name=‘anon’ value=‘1’
      checked=‘checked’ />  Show my name in the online users list

      <input type=“submit” name=“submit” value=“Submit” /></p>

      Forgot your password?

    {/exp:member:login_form}
    {/if}

    {if logged_in}

      {embed="includes/.head"}
      </head>
    <body>
      {embed="includes/.header"}
      {embed="includes/.navigation"}
    <div class=“container_12 content”>
      <div class=“grid_12”>
          {exp:channel:entries channel="forside" orderby="date" sort="desc" limit="10" disable="member_data|trackbacks"}

    {title}

            {page_body}
          {/exp:channel:entries}
      </div>
      <div class=“clear”></div>
    </div>

    {embed="includes/.footer"}
    {embed="includes/.analytics"}
    </body>
    </html>

    {/if}

  • #14 / Jul 08, 2011 5:35pm

    Sue Crocker

    26054 posts

    Hi, Anne - sounds like you’re good to go.. If anything else comes up, please do let us know in a new thread..

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases