Magento Login with username

Support specific to the Magento plugin (http://www.magentocommerce.com/).

Moderator: hwevers

Forum rules
Please post all the bugs you encounter on our issue tracker.

Magento Login with username

Postby ngoweb on Mon Oct 26, 2009 10:57 pm

Please fill up the following form to enjoy free support from our Team. No Support will be provided in case this form is not filled up!

1. Have you searched the forums and checked the documentation section for a solution?
Yep

2. Please summarize your problem in a few lines.
Looking for way to use different column in magento for username login

3. What steps will reproduce the problem?
n/a

4. What is the expected output? What do you see instead?
n/a

5. You must include a printout of the login checker in the JFusion component.
n/a

Code: Select all
Enter your login checker output here.

n/a

I have made a modification to Magento that now allows a user to login and register using a username instead of the default email address.
I need to modify the magento plugin to allow this to work / the session system is the same all that is changed is the magento authentication and an addition to the table of a username column.
Has anyone any ideas how i can modify the plugin to lookup the username for the synch instead of the email?
Or any coders out there that fancy the challenge!
Thanks all for any help
User avatar
ngoweb
JFusion Newbie
JFusion Newbie
 
Posts: 5
Joined: Mon Oct 26, 2009 9:19 pm

Re: Magento Login with username

Postby hwevers on Tue Oct 27, 2009 12:34 am

IOf you did the extension properly it wouldn't be too difficult to program an adapted plugin. The routines are general and there is no need to update the core routines in the plugin.
However, As it would be fun to do this, my priorities lay somewhere else at the moment.
Henk
User avatar
hwevers
Developer
Developer
 
Posts: 870
Joined: Fri May 02, 2008 10:06 am
Location: The netherlands

Re: Magento Login with username

Postby diglin on Wed Nov 18, 2009 12:48 pm

It could be great that you share your work concerning this module which allow to use username instead of email address.
Concerning the JFusion module, the development for a so specific module as yours is a too much if it's not used by a large public. But as has said Henk, it's not so complicated to edit yourself the code in the magento plugin to do it on your side.
Regards
JFusion Team Developer - Magento plugin and JFusion core
Personnal website about Joomla/Magento integration - http://www.diglin.com
Engineer Computer Science for rissip http://www.rissip.com
User avatar
diglin
Developer
Developer
 
Posts: 241
Joined: Thu Feb 26, 2009 2:52 pm

Re: Magento Login with username

Postby ngoweb on Wed Nov 18, 2009 11:11 pm

This is what i done and it works but backup and i dont take responsibility!! :D
Notice i didnt use EAV attrib! - oh also made core file changes in magento they should really be made into custom class extensions etc but havent got around to it yet!
I hope this helps someone, and makes sense!!

Code: Select all
************ Change File **************   
/app/code/core/Mage/Adminhtml/Block/Customer/Grid.php magento/app/code/core/Mage/Adminhtml/Block/Customer/Grid.php

             'header'    => Mage::helper('customer')->__('Last Name'),
             'index'     => 'lastname'
         ));*/
+        $this->addColumn('username', array(
+            'header'    => Mage::helper('customer')->__('Username'),
+            'width'     => '150',
+            'index'     => 'username'
+        ));
         $this->addColumn('name', array(
             'header'    => Mage::helper('customer')->__('Name'),
+            'width'     => '150',
             'index'     => 'name'
         ));
         $this->addColumn('email', array(

************ Change File **************   
/app/code/core/Mage/Customer/Model/Convert/Adapter/Customer.php magento/app/code/core/Mage/Customer/Model/Convert/Adapter/Customer.php

            $addressType = array('default_billing','default_shipping');
         }
         $attrFilterArray = array();
+        $attrFilterArray ['username']                  = 'like';
         $attrFilterArray ['firstname']                  = 'like';
         $attrFilterArray ['lastname']                   = 'like';
         $attrFilterArray ['email']                      = 'like';

************ Change File **************         
/app/code/core/Mage/Customer/Model/Customer.php magento/app/code/core/Mage/Customer/Model/Customer.php

      */
     public function authenticate($login, $password)
     {
-        $this->loadByEmail($login);
+        //$this->loadByEmail($login);
+        $this->loadByUsername($login);
         if ($this->getConfirmation() && $this->isConfirmationRequired()) {
             throw new Exception(Mage::helper('customer')->__('This account is not confirmed.'), self::EXCEPTION_EMAIL_NOT_CONFIRMED);
         }

         return $this;
     }
 
+    public function loadByUsername($username)
+    {
+        $this->_getResource()->loadByUsername($this, $username);
+        return $this;
+    }
+   
 
     /**
      * Processing object before save data

************ Change File **************   
/app/code/core/Mage/Customer/Model/Entity/Customer.php magento/app/code/core/Mage/Customer/Model/Entity/Customer.php


             'updated_at',
             'increment_id',
             'store_id',
-            'website_id'
+            'website_id',
+            'username'
         );
     }
 

         parent::_beforeSave($customer);
         $select = $this->_getReadAdapter()->select()
             ->from($this->getEntityTable(), array($this->getEntityIdField()))
+            ->where('username=?', $customer->getUsername());
+        if ($customer->getSharingConfig()->isWebsiteScope()) {
+            $select->where('website_id=?', (int) $customer->getWebsiteId());
+        }
+        if ($customer->getId()) {
+            $select->where('entity_id !=?', $customer->getId());
+        }
+
+        if ($this->_getWriteAdapter()->fetchOne($select)) {
+            Mage::throwException(Mage::helper('customer')->__('Username already exists'));
+        }
+       
+        $select = $this->_getReadAdapter()->select()
+            ->from($this->getEntityTable(), array($this->getEntityIdField()))
             ->where('email=?', $customer->getEmail());
         if ($customer->getSharingConfig()->isWebsiteScope()) {
             $select->where('website_id=?', (int) $customer->getWebsiteId());

         return $this;
     }
 
    public function loadByUsername(Mage_Customer_Model_Customer $customer, $username, $testOnly=false)
   {
        $select = $this->_getReadAdapter()->select()
           ->from($this->getEntityTable(), array($this->getEntityIdField()))
            //->where('email=?', $email);
           ->where('username=:customer_username');
        // possible bug here!
        if ($customer->getSharingConfig()->isWebsiteScope()) {
            $select->where('website_id=?', (int) $customer->getWebsiteId());
        }

        if ($id = $this->_getReadAdapter()->fetchOne($select, array('customer_username' => $username))) {
            $this->load($customer, $id);
       }
        else {
            $customer->setData(array());
        }
        return $this;
    }
     /**
      * Authenticate customer
      *

************ Change File **************   
     /app/code/core/Mage/Customer/Model/Entity/Setup.php

                         'visible'       => false,
                         'required'      => false,
                     ),
                    'username' => array(
                        'type'          => 'static',
                        'label'         => 'Username',                       
                        'required'      => false,
                        'sort_order'    => 90,
                    ),                   
                 ),
             ),

         
************ Change File **************   
/app/code/core/Mage/Customer/etc/config.xml magento/app/code/core/Mage/Customer/etc/config.xml

                 <confirmation><create>1</create></confirmation>
                 <dob><create>1</create><update>1</update></dob>
                 <taxvat><create>1</create><update>1</update></taxvat>
                <username><create>1</create><update>1</update></username>
             </customer_account>
         </fieldsets>
 
 ************ Change File NOT TESTED AND NOT NEEDED I JUST CREATED username field in customer_entity table called username varchar 255 **************   
/app/code/core/Mage/Customer/sql/customer_setup/mysql4-upgrade-0.8.8-0.8.9.php

<?php
/**
 * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * @category   Mage
+ * @package    Mage_Customer
+ * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
+ * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
+ */

$installer = $this;

/* @var $installer Mage_Customer_Model_Entity_Setup */
$installer->startSetup();

$installer->run("
+ALTER TABLE {$this->getTable('customer_entity')}   
+    ADD COLUMN `username` VARCHAR(255) NOT NULL AFTER `email`;
+");
+
+$installer->addAttribute('customer', 'username', array(
+    'label'    => 'Username',
+    'type'     => 'static',
+    'visible'  => true,
+    'required' => true,
+));
+
$installer->endSetup();

************ Change File **************   
/app/design/frontend/default/default/template/customer/account/dashboard/info.phtml


             <a href="<?php echo $this->getUrl('customer/account/edit') ?>"><?php echo $this->__('Edit') ?></a>
         </div>
         <p>
+            <?php echo $this->htmlEscape($this->getCustomer()->getUsername()) ?><br />
             <?php echo $this->htmlEscape($this->getCustomer()->getName()) ?><br />
             <?php echo $this->htmlEscape($this->getCustomer()->getEmail()) ?><br />
             <a href="<?php echo $this->getChangePasswordUrl() ?>"><?php echo $this->__('Change Password') ?></a>
         
************ Change File **************   
/app/design/frontend/default/default/template/customer/dashboard.phtml



 <div class="input-left">
     <h3><?php echo $this->__('Personal Information') ?></h3>
     <p>
-        <?php echo $this->getCustomer()->toString('{{firstname}} {{lastname}}<br/>{{email}}') ?>
+        <?php echo $this->getCustomer()->toString('{{username}}<br/>{{firstname}} {{lastname}}<br/>{{email}}') ?>
         <br/>
         <a href="<?php echo $this->getAccountUrl() ?>"><?php echo $this->__('Edit Personal Information') ?></a>
     </p>

    ************ Change File **************   
    /app/design/frontend/default/default/template/customer/form/edit.phtml
   
     <h4 class="legend"><?php echo $this->__('Account Information') ?></h4>
     <ul>
         <li>
+            <div class="input-box">
+            <label for="username"><?php echo $this->__('Username') ?> <span class="required">*</span></label><br />
+            <input type="text" name="username" id="username" value="<?php echo $this->htmlEscape($this->getCustomer()->getUsername()) ?>" title="<?php echo $this->__('Username') ?>" class="required-entry input-text" />
+            </div>
+        </li>
+        <li>
             <?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getCustomer())->toHtml() ?>
         </li>
         <li>
      
************ Change File **************   
/app/design/frontend/default/default/template/customer/form/login.phtml magento/app/design/frontend/default/default/template/customer/form/login.phtml

             <p><?php echo $this->__('If you have an account with us, please log in.') ?></p>
             <ul class="form-list">
                     <li>
-                        <label for="email"><?php echo $this->__('Email Address') ?> <span class="required">*</span></label><br />
-                        <input name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" title="<?php echo $this->__('Email Address') ?>" id="email" type="text" class="input-text required-entry" style="width:250px;" />
+                        <label for="username"><?php echo $this->__('Username') ?> <span class="required">*</span></label><br />
+                        <input name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" title="<?php echo $this->__('Username') ?>" id="username" type="text" class="input-text required-entry" style="width:250px;" />
                     </li>
                     <li>
                         <label for="pass"><?php echo $this->__('Password') ?> <span class="required">*</span></label><br />

************ Change File **************   
/app/design/frontend/default/default/template/customer/form/mini.login.phtml

 ?>
 <form action="<?php echo $this->getPostActionUrl() ?>" method="post">
     <table width="100%" class="mini-login">
-        <tr><td><?php echo $this->__('Email') ?>:</td><td><input name="login[username]" /></td></tr>
+        <tr><td><?php echo $this->__('Username') ?>:</td><td><input name="login[username]" /></td></tr>
         <tr><td><?php echo $this->__('Password') ?>:</td><td><input name="login[password]" /></td></tr>
         <tr><td>&nbsp;</td><td><input type="submit" value="<?php echo $this->__('Login') ?>" /></td></tr>
     </table>

************ Change File **************   
/app/design/frontend/default/default/template/customer/form/register.phtml

         <h4 class="legend"><?php echo $this->__('Personal Information') ?></h4>
         <ul>
             <li>
+                <div class="input-box">
+                    <label for="username"><?php echo $this->__('Username') ?> <span class="required">*</span></label><br/>
+                    <input type="text" name="username" id="username" value="<?php echo $this->htmlEscape($this->getFormData()->getUsername()) ?>" title="<?php echo $this->__('Username') ?>" class="required-entry input-text" />
+                </div>
+            </li>
+            <li>
                 <?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getFormData())->toHtml() ?>
             </li>
             <li>

User avatar
ngoweb
JFusion Newbie
JFusion Newbie
 
Posts: 5
Joined: Mon Oct 26, 2009 9:19 pm

Re: Magento Login with username

Postby hwevers on Thu Nov 19, 2009 12:16 pm

Great that you acieved what you wanted!

One advice though: There is no need to actually change core files in Magento. You can override any function you want as follows:

If magento's code goes in
/app/code/core/Mage/Adminhtml/Block/Customer/Grid.php
Then you can put your changed code in:
/app/code/local/Mage/Adminhtml/Block/Customer/Grid.php
The beauty is that you only need to put changed functions in the class you changed.

Henk
User avatar
hwevers
Developer
Developer
 
Posts: 870
Joined: Fri May 02, 2008 10:06 am
Location: The netherlands

Re: Magento Login with username

Postby ngoweb on Thu Nov 19, 2009 5:40 pm

yah, I hadnt got that far! but its in stage 2!
I am also putting together the changes i did to the plugin and the wasy i achieved loggin into magento and being automatically logged into joomla (a sorta hack) but was weary of posting it because i know you guys have a commercial plugin for that
User avatar
ngoweb
JFusion Newbie
JFusion Newbie
 
Posts: 5
Joined: Mon Oct 26, 2009 9:19 pm

Re: Magento Login with username

Postby hwevers on Sun Nov 22, 2009 6:52 pm

Actually the price of that Magento extension is for support (inlcudes installation). There are too many support questions attached to this kind of software that actually hacks Magento. I am working on a building block that we can use to make this type of 'reverse' login maintainable. JFusion version 2.0 will have a system in place to make this easy. One of the problems to cope with is that you need prevention for and ensless loop. Magento logs into Joomla,. in turn JFusion logs into magento again.
When 2.0 is comes out we have support for MAgento blocks in Joomla and vise versa. Most of it is aklready done in the latest 2.0 testversion (If you want to test, have a look in our SVN/trunk). t will tak us some time though, to ge it all done.
Henk
User avatar
hwevers
Developer
Developer
 
Posts: 870
Joined: Fri May 02, 2008 10:06 am
Location: The netherlands

Re: Magento Login with username

Postby hawks1 on Thu Apr 08, 2010 8:58 am

After some hours hard code changing ,,
at last i get a final result " Can't save customer"

Sorry , i have to give up ,,, i am using magento 1.4.0.1 :?
User avatar
hawks1
JFusion Newbie II
JFusion Newbie II
 
Posts: 11
Joined: Sat Mar 27, 2010 4:42 pm

Re: Magento Login with username

Postby gfxguru on Tue Aug 24, 2010 6:01 pm

Yea, I give up too. Maybe you need to publish exactly what version of Magento your plugin works with and what version it does not!. People might like to know before they go wasting so much time.
User avatar
gfxguru
JFusion Newbie
JFusion Newbie
 
Posts: 1
Joined: Tue Aug 24, 2010 4:56 pm

Re: Magento Login with username

Postby hwevers on Tue Aug 24, 2010 7:22 pm

Magento has a very complicated (but sophisticated as well) database system. I have put a lot of time into getting some understanding how it all works and how to access it. If you look at my code you will see that you can expand the userrecord, but need field definitions etc.

Actually it is a lot of work. Maybe you are better of asking the Magento community for an username extension of the userrecord. Once available adaption of the Magento plugin won't be difficult.
Henk


User avatar
hwevers
Developer
Developer
 
Posts: 870
Joined: Fri May 02, 2008 10:06 am
Location: The netherlands

Next

Return to Magento

Who is online

Users browsing this forum: No registered users and 0 guests