0
votes

I have client requirement that he is moving his site from development server to production server.

He want to do some testing and other stuff before going live completely. So what he want is to make the site visible to him only (using some authentication).

As soon as he try to access the any url of site,he should be redirected to a login page.This login page is different than magento login page which covers the whole screen so the site content should not be visible until he login .(There should be no registration facility,this is a user specific login )

Only after login with a specified password and username he will be allowed to see the site content.

I tried some thing like this in my index.php

$basePath=getcwd();

require_once $basePath.'/app/Mage.php'; Mage::init();

$currentUrl = Mage::helper('core/url')->getCurrentUrl(); //echo $currentUrl."
";//exit;

if(strpos($currentUrl,"?k=1") ) { $validation=1;
} else { $validation=0; }

//exit; if($validation==0 ) {
// echo "
In if validation 0";
include 'Loginform.php'; } else {
echo "ddd"; /exit;/

        /**
         * Error reporting
         */
        error_reporting(E_ALL | E_STRICT);

        /**
         * Compilation includes configuration file
         */
        define('MAGENTO_ROOT', getcwd());

        $compilerConfig = MAGENTO_ROOT . '/includes/config.php';
        if (file_exists($compilerConfig)) {
            include $compilerConfig;
        }                                       

        $mageFilename = MAGENTO_ROOT . '/app/Mage.php';
        $maintenanceFile = 'maintenance.flag';

        if (!file_exists($mageFilename)) {
            if (is_dir('downloader')) {
                header("Location: downloader");
            } else {
                echo $mageFilename." was not found";
            }
            exit;
        }

        if (file_exists($maintenanceFile)) {
            include_once dirname(__FILE__) . '/errors/503.php';
            exit;
        }

        require_once $mageFilename;

        #Varien_Profiler::enable();

        if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
            Mage::setIsDeveloperMode(true);
        }

        #ini_set('display_errors', 1);

        umask(0);

        /* Store or website code */
        $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

        /* Run store or run website */
        $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

        Mage::run($mageRunCode, $mageRunType);

and I created a file Loginform.php in base directory which has content .

<?php 
    $basePath=getcwd();
    require_once $basePath.'/app/Mage.php';
    Mage::init();

    $cust=Mage::getModel('customer/customer')->getCollection();

foreach($cust as $customer)
{       
    //echo $customer->getEmail();
}
// echo "<br/>";
// echo $_POST['username'];  
 $email=$_POST['username'];


 echo "<br/>";
    //echo $_POST['password'];  
    //echo md5($_POST['password']); 
 $password=$_POST['password'];

  echo "<br/>";

$customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId());

try 
{
  if($customer->authenticate($email,$password)) 
  {
        //echo 'success<br/>';


        $url=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); //exit;
        $url=$url.'index.php'.'?k=1';
        //echo $url;

            //Mage::app()->getResponse()->setRedirect($url); //Redirecting to base url
            //Mage::app()->getFrontController()->getResponse()->setRedirect($url);


            header("Location:$url");        

  }
}
catch (Mage_Core_Exception $e )
{
    echo $e->getMessage();      

}


?>
<html>
<head>
</head>
<body>
    <form method="post" action="Loginform.php"> 
    User Name<input type="text" name="username"/>
    Password<input type="password" name="password"/>
    <input type="submit" name="submit" value="submit"/>
    </form>
</body>

</html>

But using this logic I am facing lot of problems. Please suggest some solution.

2

2 Answers

2
votes

Since this is a temporary problem, I'd recommend you protect the site by requiring a password on the root directory using htaccess.

Here's a site with step by step instructions: http://www.thesitewizard.com/apache/password-protect-directory.shtml

And another: http://www.seas.upenn.edu/cets/answers/auth-htpasswd.html

This solution may not be elegant, but it should save you the time of coding a custom solution.

0
votes

you can put the particular customer under some unique customer group and in the files you can place the check on that customer group ,that if a user is under that customer group he can see whatever you want to display and in else condition ..whatever you want