zend framework - Can (and should?) Zend_Auth return class as the Identity? -


I have a class R00_Model_User, which is eagerly enough, it's the user as it is. Can $ result-> getIdentity () return an object of this class to me? (Or maybe it's stupid?)

(R00_Model_User has a factory method that prevents duplicating of objects. I like Zend_Auth to use it instead of creating a new object) < / P>

two options:

  • Write your own authentication adapter Best match for your scenario

      class R00_Auth_Adapter extends Zend_Auth_Adapter_ * * {/ ** * Authentication () - by Zend_Auth_Adapter_Interface This defined defining method is called to attempt authentication. Prior to this call, this adapter was already configured with * all required information so that the database could be successfully connected * and try to enter the matching identity provided. * * @thread_and_ath_adapter_expressation is impossible to answer authentication queries * @Return Zend_Auth_Result * / Public Function Authentication () {$ result = parent :: authentic (); If ($ result-> invalid ()) return to new Zend_Auth_Result ($ result-> getCode (), R00_Model_User :: load ($ result-> getIdentity ()), $ result-> GetMessages ());} Else {return $ result;}}}  

    This will give you code

      $ adapter = new R00_Auth_Adapter (); // Adapter will allow initialization (username, password, etc.) $ result = Zend_Auth :: getInstance () - & gt; Certify ($ Adapter);  

    And on successful activation, your user object is stored automatically Authentication storage (session by default).

  • Use your login-actions to update the stored user identity

      $ adapter = new zend_auth_adapter_ * (); $ Result = $ adapter- & gt; Authenticate (); If ($ result-> is invalid ()) {$ user = R00_Model_User :: load ($ result-> getIdentity ()); Zend_Auth :: getInstance () - & gt; GetStorage () - & gt; Type ($ user);}  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -