Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Backend Login through URL
 
Christian123
Jr. Member
 
Total Posts:  2
Joined:  2012-07-09
 

Hi,

is it possible to do a admin login by entering a link like:  mymagento/admin/?username="admin"&password;="password"

where should i edit the code?

tried this script , but does not work

<?php
// Include Magento application
require_once ( "app/Mage.php" );
umask(0);

// Initialize Magento
Mage::app();

// You have two options here,
// "frontend" for frontend session or "adminhtml" for admin session
Mage::getSingleton("core/session", array("name" => "adminhtml"));

$session Mage::getSingleton("admin/session");
$session->login('admin','password');
$session->start();

 if (
$session->isLoggedIn())
            echo 
"logged in";
       else
            echo 
"logged out";

appreciate your help

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ryan Sun _Kuafu
Guru
 
Total Posts:  317
Joined:  2008-11-14
FL
 

the script works

 
Magento Community Magento Community
Magento Community
Magento Community
 
Christian123
Jr. Member
 
Total Posts:  2
Joined:  2012-07-09
 

Thanks for your suppy. My Problem is I want to run the csv-Export-Mudul from external via link. But when i do this i need to be logged in the backend before. I have to login again after excecuting the script above.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ryan Sun _Kuafu
Guru
 
Total Posts:  317
Joined:  2008-11-14
FL
 

I don’t know how did you run your scripts but here is an exporting example

<?php
// Include Magento application
require_once ( "app/Mage.php" );
umask(0);

// Initialize Magento
Mage::app();

// You have two options here,
// "frontend" for frontend session or "adminhtml" for admin session
Mage::getSingleton("core/session", array("name" => "adminhtml"));

$session Mage::getSingleton("admin/session");
$session->login('admin','password');

 if (
$session->isLoggedIn())
            
{
                $fileName   
'orders.csv';
                
$grid       Mage::app()->getLayout()->createBlock('adminhtml/sales_order_grid');
                
$content    =  $grid->getCsvFile();
                
_prepareDownloadResponse($fileName $content);
            
}
       
else
            echo 
"logged out";


//copyed from admin contrller
function _prepareDownloadResponse($fileName$content$contentType 'application/octet-stream'$contentLength null)
{
    $isFile 
false;
    
$file   null;
    if (
is_array($content)) {
        
if (!isset($content['type']) || !isset($content['value'])) {
            
return $this;
        
}
        
if ($content['type'== 'filename'{
            $isFile         
true;
            
$file           $content['value'];
            
$contentLength  filesize($file);
        
}
    }

    Mage
::app()->getResponse()
        ->
setHttpResponseCode(200)
        ->
setHeader('Pragma''public'true)
        ->
setHeader('Cache-Control''must-revalidate, post-check=0, pre-check=0'true)
        ->
setHeader('Content-type'$contentTypetrue)
        ->
setHeader('Content-Length'is_null($contentLength) ? strlen($content) : $contentLength)
        ->
setHeader('Content-Disposition''attachment; filename="'.$fileName.'"')
        ->
setHeader('Last-Modified'date('r'));

    if (!
is_null($content)) {
        
if ($isFile{
            Mage
::app()->getResponse()->clearBody();
            
Mage::app()->getResponse()->sendHeaders();

            
$ioAdapter = new Varien_Io_File();
            
$ioAdapter->open(array('path' => $ioAdapter->dirname($file)));
            
$ioAdapter->streamOpen($file'r');
            while (
$buffer $ioAdapter->streamRead()) {
                
print $buffer;
            
}
            $ioAdapter
->streamClose();
            if (!empty(
$content['rm'])) {
                $ioAdapter
->rm($file);
            
}
        } 
else {
            Mage
::app()->getResponse()->setBody($content);
        
}
    }
    
return $this;
}

you have to make sure the login script and export script share the same session

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top