0

I would login by email only , without password.

I have Read these two Posts but it not works for me.

Programmatically login a user

https://blog.ancud.de/home/-/blogs/magento-how-to-login-a

I use Magento 1.9

This is my code at the momment:

function loginByEmail($email, $websiteId)
{
    Mage::init('test', 'website');
    // ensure that we are on the correct website
    $customer = Mage::getModel('customer/customer');
    $customer->setWebsiteId($websiteId);
        // the website must be set here again!!!
    $customer->loadByEmail($email);
    $session = Mage::getSingleton('customer/session');

    if ($customer->getId()) {
        $session->setCustomerAsLoggedIn($customer);
        return $session;
    }
}

require_once ( "/var/www/html/app/Mage.php");

Mage::init('test', 'website');
Mage::app("test");


$email = '[email protected]';
$session = loginByEmail($email,'test');


header('Location: /');

I hope you can help me.

thx a lot

so long Maxwill

2 Answers 2

1

Try this below code :

 $email = '[email protected]';
 $customer = Mage::getModel('customer/customer');
 $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
 $customer->loadByEmail(trim($email));
 Mage::getSingleton('customer/session')->loginById($customer->getId());
1
  • Thx for yor answer , but it doesn't work for me. i will redirect to the login mask.
    – Maxwill
    Commented Jan 22, 2019 at 12:47
0

This is a print of my customer model:

2019-01-22T12:58:01+00:00 DEBUG (7): Mage_Customer_Model_Customer Object
(
    [_eventPrefix:protected] => customer
    [_eventObject:protected] => customer
    [_errors:protected] => Array()
    [_attributes:protected] => 
    [_addresses:protected] => 
    [_addressesCollection:protected] => 
    [_isDeleteable:protected] => 1
    [_isReadonly:protected] => 
    [_cacheTag:protected] => customer
    [_resourceName:protected] => customer/customer
    [_resource:protected] => 
    [_resourceCollectionName:protected] => customer/customer_collection
    [_dataSaveAllowed:protected] => 1
    [_isObjectNew:protected] => 
    [_data:protected] => Array
    (
        [website_id] => 13
        [entity_id] => 18764
        [entity_type_id] => 1
        [attribute_set_id] => 0
        [email] => [email protected]
        [group_id] => 26
        [increment_id] => 
        [store_id] => 0
        [created_at] => 2018-12-19T16:10:16+01:00
        [updated_at] => 2018-12-19 16:20:04
        [is_active] => 1
        [disable_auto_group_change] => 0
        [default_billing] => 19896
        [default_shipping] => 19896
        [payment_invoice] => 0
        [activate_customer] => 0
        [created_in] => Admin
        [prefix] => 
        [firstname] => fn_test
        [middlename] => mn_test
        [lastname] => ln_test
        [suffix] => 
        [password_hash] => b111111133d4d77d2efecdf74f53b47:N6
        [taxvat] => 
        [rp_token] => 
        [rogler_customer_id] => 
        [cost_center] => 
    )

    [_hasDataChanges:protected] => 1
    [_origData:protected] => Array
    (
        [website_id] => 13
        [entity_id] => 18764
        [entity_type_id] => 1
        [attribute_set_id] => 0
        [email] => [email protected]
        [group_id] => 26
        [increment_id] => 
        [store_id] => 0
        [created_at] => 2018-12-19 15:10:16
        [updated_at] => 2018-12-19 16:20:04
        [is_active] => 1
        [disable_auto_group_change] => 0
        [default_billing] => 19896
        [default_shipping] => 19896
        [payment_invoice] => 0
        [activate_customer] => 0
        [created_in] => Admin
        [prefix] => 
        [firstname] => fn_test
        [middlename] => mn_test
        [lastname] => ln_test
        [suffix] => 
        [password_hash] => b1111111111112efecdf74f53b47:N6
        [taxvat] => 
        [rp_token] => 
        [rogler_customer_id] => 
        [cost_center] => 
    )

    [_idFieldName:protected] => entity_id
    [_isDeleted:protected] => 
    [_oldFieldsMap:protected] => Array
    (
    )

    [_syncFieldsMap:protected] => Array
    (
    )

)

And the Session model is:

2019-01-22T12:58:01+00:00 DEBUG (7): Mage_Customer_Model_Session Object
(
    [_customer:protected] => 
    [_isCustomerIdChecked:protected] => 
    [_persistentCustomerGroupId:protected] => 
    [_skipSessionIdFlag:protected] => 
    [_data:protected] => Array
    (
        [_session_validator_data] => Array
            (
                [remote_addr] => 111.111.111.111
                [http_via] => 
                [http_x_forwarded_for] => 
                [http_user_agent] => Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
            )

        [session_hosts] => Array
            (
                [test.de] => 1
            )

        [id] => 18764
    )

    [_hasDataChanges:protected] => 1
    [_origData:protected] => 
    [_idFieldName:protected] => 
    [_isDeleted:protected] => 
    [_oldFieldsMap:protected] => Array
    (
    )

    [_syncFieldsMap:protected] => Array
    (
    )

)

And loginById return 1

After that i make a "header('Location: /');"

I hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.