Custom Protection Plugin Issue

Discussion in 'Customization & add-ons' started by jakumpe, Apr 15, 2017.

  1. jakumpe

    jakumpe New Member

    Joined:
    May 14, 2010
    Messages:
    13
    I am trying to build a protection plugin using the Plugin Maker in aMember. Below is what the plugin maker output. It works but in the groups database there is a column of "username" that needs to have the user's login name in it but the script keeps putting the User ID in it instead. I am needing the username column in the rasusergroup table to match the user's username in the radcheck database.

    I tried changing the Am_Protect_Table::GROUP_UID => 'username' to Am_Protect_Table::FIELD_LOGIN => 'username' but that just made it error out.

    Any body know how I might be able to fix this?

    Code:
    <?php
    /**
    * Kumpe-radius Integration Plugin
    * Checklist (mark tested items with x):
    * [x] - template generated
    * [ ] - go to aMember Cp -> Setup -> Plugins and enable this plugin
    * [ ] - test user creation
    *       try to create user in aMember and add access manually.
    *       Login to Kumpe-radius and check that
    *       that corresponding user appeared in users list and all necessary
    *       fields transferred
    * [ ] - test password generation: login to kumpe-radius as the new user
    * [ ] - update user record in amember and try to login and view profile in the script
    * [ ] - implement single-login
    *
    **/
    class Am_Protect_KumpeRadius extends Am_Protect_Databased
    {
        const PLUGIN_DATE = '$Date$';
        const PLUGIN_REVISION = '@@VERSION@@';
    
        protected $guessTablePattern = "radcheck";
        protected $guessFieldsPattern = array(
            'username','attribute','op','value', 
        );
        protected $groupMode = Am_Protect_Databased::GROUP_MULTI;
    
        public function afterAddConfigItems(Am_Form_Setup_ProtectDatabased $form)
        {
            parent::afterAddConfigItems($form);
            // additional configuration items for the plugin may be inserted here
        }
        public function getPasswordFormat()
        {
            return SavedPassTable::PASSWORD_CRYPT;
        }
        /**
         * Return record of customer currently logged-in to the
         * third-party script, or null if not found or not logged-in
         * @return Am_Record|null
         */
        public function getLoggedInRecord()
        {
            // for single-login must return
        }
    
        public function loginUser(Am_Record $record, $password)
        {
            // login user to third-party script
        }
        public function logoutUser(User $user)
        {
            // logout user from third-party script
        }
        public function createTable()
        {
            $table = new Am_Protect_Table($this, $this->getDb(), '?_radcheck', 'id');
            $table->setFieldsMapping(array(
                array(Am_Protect_Table::FIELD_LOGIN, 'username'),
                array(':Crypt-Password', 'attribute'),
                array('::=', 'op'),
                array(Am_Protect_Table::FIELD_PASS, 'value'),
            
            ));
        
            $table->setGroupsTableConfig(array(
                Am_Protect_Table::GROUP_TABLE   =>  '?_radusergroup',
                Am_Protect_Table::GROUP_GID     =>  'groupname',
                Am_Protect_Table::GROUP_UID     =>  'username'
            ));
                
            return $table;
        }
        public function getAvailableUserGroupsSql()
        {
            return "SELECT
                groupname as id,
                groupname as title,
                NULL as is_banned, #must be customized
                NULL as is_admin # must be customized
                FROM ?_radgroupcheck";
        }
        function getReadme()
        {
            return <<<CUT
        kumpe-radius README
    CUT;
        }
    }
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Hello,

    I am afraid plugin maker can not help you in such non standard case. Usually all scripts map data in user group table based on user id in user table. You need to extende default Am_Protect_Table and overwrite method setGroups with your own implementation (which set username instead uid). Then within plugin code replace Am_Protect_Table with your own class.

    Feel free to contact us in helpdesk
    https://www.amember.com/support

    We can develope intgration plugin for your script for a fee.

    Best Regards.
  3. jakumpe

    jakumpe New Member

    Joined:
    May 14, 2010
    Messages:
    13
    If I add a column to the database for uid and let the script add the user by uid would it be possible to also pass the username to a username column in the group table using the plugin maker?

    If not how much would it cost to develop an integration plugin for what I am needing?
  4. jakumpe

    jakumpe New Member

    Joined:
    May 14, 2010
    Messages:
    13
    Or if it can just delete the user from the remote database when subscription is removed that would be great too. I don't really need groups, just need a way to deny access when subscription expires or is removed.
  5. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    I am afraid it is necessary to overwrite method setGroups to pass username to table with groups still.

    Please contact us in helpdesk for a quote.

    Best Regards.

Share This Page