1) the main function in a class Ibrams/Application/Model/User.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param array $userData | |
*/ | |
public function addApiUser(array $userData) | |
{ | |
$api_role = Mage::getModel('api/roles') | |
->setName($userData['roleName']) | |
->setPid(false) | |
->setRoleType('G') | |
->save(); | |
Mage::getModel('api/rules') | |
->setRoleId($api_role->getId()) | |
->setResources(array('all')) | |
->saveRel(); | |
$api_user = Mage::getModel('api/user'); | |
$api_user->loadByUsername($userData['userName']); | |
$data = array( | |
'username' => $userData['userName'], | |
'firstname' => $userData['firstName'], | |
'lastname' => $userData['lastName'], | |
'email' => $userData['email'], | |
'api_key' => $userData['apiKey'], | |
'api_key_confirmation' => $userData['apiKey'], | |
'is_active' => 1, | |
'user_roles' => '', | |
'assigned_user_role' => '', | |
'role_name' => '', | |
'roles' => array($api_role->getId()) | |
); | |
if($api_user->getUserId()) | |
{ | |
$data['user_id'] = $api_user->getId(); | |
} | |
$api_user->setData($data); | |
$api_user->save(); | |
$api_user->load($api_user->getId()); | |
$api_user->setRoleIds(array($api_role->getId())) | |
->setRoleUserId($api_user->getUserId()) | |
->saveRelations(); | |
} |
2) the call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$defaultApiUser = array(); | |
$defaultApiUser['userName'] = 'apiadmin'; | |
$defaultApiUser['email'] = 'admin@test.com'; | |
$defaultApiUser['apiKey'] = 'asecret'; | |
$defaultApiUser['firstName'] = 'apiadmin'; | |
$defaultApiUser['lastName'] = 'apiadmin'; | |
$defaultApiUser['roleName'] = 'apiadmin'; | |
/** @var Ibrams_Application_Model_User */ | |
$userModel = Mage::getModel("application/user"); | |
$api_user = Mage::getModel('api/user'); | |
$userModel->addApiUser($defaultApiUser); | |
$coreConfig = new Mage_Core_Model_Config(); |
Keine Kommentare:
Kommentar veröffentlichen