doctrine2 - Multiple identity properties for authentication in ZF2 with Doctrine 2 -


i have login form input text fields:

  • group name
  • user name
  • user password

i have 2 tables

  • groups
    • id
    • name
  • users
    • id
    • name
    • group_id

i have mapping entities , associations.

but user name not unique within table users, because different groups can include users equal names. therefore need:

  1. find group name in table groups
  2. find user name in table users condition where group_id=<group_id>

how correctly in zend framework 2 using doctrine 2? official documentation , examples depict situation, identity property single column (example).

sorry bad language. thanks.

instead of making own implementation of doctrine's authentication services decide implement via form validation inside isvalid() method of authentication form.

example:

<?php  namespace my\form\namespace;  use zend\form\form; use zend\servicemanager\servicelocatorinterface; use zend\inputfilter\inputfilterproviderinterface;  class auth extends form implement inputfilterproviderinterface {     protected $_em;      public function __construct(servicelocatorinterface $sm)     {         parent::__construct('auth');          // inject doctrine's entity manager         $this->_em = $sm->get('doctrine\orm\entitymanager');          // login field         $this->add(...);          // password field         $this->add(...);          // group_name field         $this->add(...);     }      public function getinputfilterspecification()     {         //input filter specification here         ...     }      public function isvalid()     {         /*          * input filter validations          */         if (!parent::isvalid())             return false;          /*          * group exists validation          */         $group = $this->_em             ->getrepository('<group\entity\namespace>')             ->findoneby(array(                 'name' => $this->get('group_name')->getvalue(),             ));         if (!$group){             $this->get('group_name')                 ->setmessages(array(                     'group not found',                 ));             return false;         }          /*          * user exists validation          */         $user = $this->_em             ->getrepository('<user\entity\namespace>')             ->findoneby(array(                 'group_id' => $group->getid(),                 'name' => $this->get('login')->getvalue(),             ));         if (!$user){             /*              * it's not idea tell user not found,              * let password error              */             $this->get('password')                 ->setmessages(array(                     'login or password wrong',                 ));             return false;         }          /*          * password validation          */         $password = $this->get('password')->getvalue();         // assume password hash md5 of password string         if (md5($password) !== $user->getpassword()){             $this->get('password')                 ->setmessages(array(                     'login or password wrong',                 ));             return false;         }          return true;     } } 

inside controller enough call $form->isvalid() make sure user entered correct authentication data.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -