Пример #1
0
 /**
  * Called before each test object.
  */
 public function __construct()
 {
     $this->ia = elgg_set_ignore_access(TRUE);
     parent::__construct();
     $this->user = new ElggUser();
     $this->user->username = '******' . rand();
     $this->user->email = '*****@*****.**';
     $this->user->name = 'I am a Test User';
     $this->user->access_id = ACCESS_PUBLIC;
     $this->user->salt = generate_random_cleartext_password();
     $this->user->password = generate_user_password($this->user, "pass123");
     $this->user->container_guid = 0;
     $this->user->owner_guid = 0;
     $this->user->save();
     // all __construct() code should come after here
     $this->user2 = new ElggUser();
     // generating API key
     $keypair = create_api_user($CONFIG->site_id);
     if ($keypair) {
         $this->apikey = new ElggObject();
         $this->apikey->subtype = 'api_key';
         $this->apikey->access_id = ACCESS_PUBLIC;
         $this->apikey->title = "User web services";
         $this->apikey->public = $keypair->api_key;
         $this->apikey->save();
     }
 }
Пример #2
0
 * Implementation of the Regenerate Keys option on an API Key object
 * 
 * @package ElggAPIAdmin
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
 * 
 * @author Moodsdesign Ltd
 * @copyright Moodsdesign Ltd 2012
 * @link http://www.elgg.org
*/
global $CONFIG;
admin_gatekeeper();
$key = (int) get_input('keyid');
$obj = get_entity($key);
if ($obj && $obj instanceof ElggObject && $obj->subtype == get_subtype_id('object', 'api_key')) {
    if (remove_api_user($CONFIG->site_id, $obj->public)) {
        $keypair = create_api_user($CONFIG->site_id);
        if ($keypair) {
            $obj->public = $keypair->api_key;
        } else {
            register_error(elgg_echo('apiadmin:regenerationfail'));
        }
        if (!$obj->save()) {
            register_error(elgg_echo('apiadmin:regenerationfail'));
        } else {
            system_message(elgg_echo('apiadmin:regenerated'));
        }
    } else {
        register_error(elgg_echo('apiadmin:regenerationfail'));
    }
}
forward(REFERER);
Пример #3
0
 /**
  * Activates the API application
  *
  * @return boolean
  */
 function activate()
 {
     $result = false;
     // make sure this entity is enabled
     if (!$this->isEnabled()) {
         if (!$this->enable()) {
             return false;
         }
     }
     // now create API keys
     if (!isset($this->api_user_id)) {
         if ($api_user = create_api_user($this->site_guid)) {
             $this->api_user_id = sanitise_int($api_user->id);
             $result = true;
         }
     } else {
         $result = ws_pack_activate_api_user_from_id($this->api_user_id);
     }
     return $result;
 }