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

Howto override “authenticate” method in app/code/core/Mage/Admin/Model/User.php
 
aongena
Jr. Member
 
Total Posts:  4
Joined:  2008-05-26
 

Hi,

I want to extend “authenticate” to use Radius, however I can not get “my” version of it called. Please help.

What I did:

I created app/code/local/MyComp/Auth/Model/Radius.php

<?php

class MyComp_Auth_Model_Radius extends Mage_Admin_Model_User
{
    
/**
     * Authenticate user name and password and save loaded record
     *
     * @param string $username
     * @param string $password
     * @return boolean
     */
    
public function authenticate($username$password)
    
{
       
/* my code to be added */

        
if ($auth{
            
return true;
        
else {
            $this
->unsetData();
            return 
false;
        
}
    }
}
I added app/etc/modules/MyComp_All.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
MyComp_Auth>
            <
active>true</active>
            <
codePool>local</codePool>
        </
MyComp_Auth>
    </
modules>
</
config>

and somehow I think that I need to add something else to let Magento know to use my function, but I can not figure out what.

Any Idea ?

Txs
Alex

 
Magento Community Magento Community
Magento Community
Magento Community
 
yshahin
Jr. Member
 
Avatar
Total Posts:  30
Joined:  2008-05-14
 

i think u have to say that you are overwriting that class in a config.xml
which will be in app/code/local/MyComp/Auth/etc/config.xml

but i don’t know what to write exactly smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Andreas Bruckmeier
Jr. Member
 
Total Posts:  8
Joined:  2008-05-14
 

At first it would be better to follow the magento naming-rules for subclassing.
If you want to extend Mage_Admin_Model_User then your class should be named MyComp_Admin_Model_User and reside in the file app/code/local/MyComp/Admin/Model/User.php

Maybe your naming is also ok but i’m not shure wink

This is what i would do:

app/code/local/MyComp/Admin/Model/User.php (your new class with overwritten authenticate() function)

<?php
class MyComp_Admin_Model_User extends Mage_Admin_Model_User {
    
public function authenticate($username$password{
       
/* my code to be added */
        
if ($auth{
            
return true;
        
else {
            $this
->unsetData();
            return 
false;
        
}
    }
}
?>

app/etc/modules/MyComp_Admin.xml (to tell magento about your new module)

<?xml version="1.0"?>
<config>
    <
modules>
        <
MyComp_Admin>
            <
active>true</active>
            <
codePool>local</codePool>
        </
MyComp_Admin>
    </
modules>
</
config>

app/code/local/MyComp/Admin/etc/config.xml (tell magento to use your new class)

<?xml version="1.0"?>
<config>
    <global>
        <
models>
            <
admin>
                <
rewrite>
                    <
user>MyComp_Admin_Model_User</user>
                </
rewrite>
            </
admin>
        </
models>
    </global>
</
config>

but i can’t give a guarantee that this works.

Best regards, Andi

 
Magento Community Magento Community
Magento Community
Magento Community
 
aongena
Jr. Member
 
Total Posts:  4
Joined:  2008-05-26
 

Hello Andreas,

it works exactly how you described. I think the ‘app/code/local/MyComp/Admin/etc/config.xml’ file did the Trick. I have changed also to the Magento conventions.

Thank you
Alex

 
Magento Community Magento Community
Magento Community
Magento Community
 
yshahin
Jr. Member
 
Avatar
Total Posts:  30
Joined:  2008-05-14
 

i tried that module but it doen’t work for me.

Magento finds the module and executes the code
but when i set $auth = true; it executes twice and still doesn’t authenticate the user donno why?

 
Magento Community Magento Community
Magento Community
Magento Community
 
yshahin
Jr. Member
 
Avatar
Total Posts:  30
Joined:  2008-05-14
 

it works when i load the user information first
$this->loadbyusername($username)

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