public function xGenerateApiKeyAction() { if ($this->user->isAdmin() || !\Scalr::config('scalr.system.api.enabled')) { throw new Scalr_Exception_InsufficientPermissions(); } $apiKeyEntity = new ApiKeyEntity($this->user->getId()); $apiKeyEntity->save(); $row = get_object_vars($apiKeyEntity); $row['created'] = Scalr_Util_DateTime::convertTz($apiKeyEntity->created); $row['lastUsed'] = $apiKeyEntity->lastUsed ? Scalr_Util_DateTime::convertTz($apiKeyEntity->lastUsed) : 0; $row['createdHr'] = $apiKeyEntity->created ? Scalr_Util_DateTime::getFuzzyTimeString($apiKeyEntity->created) : ''; $row['lastUsedHr'] = $apiKeyEntity->lastUsed ? Scalr_Util_DateTime::getFuzzyTimeString($apiKeyEntity->lastUsed) : 'Never'; $this->response->data(['key' => $row]); }
public function getUserInfo() { $info['id'] = $this->id; $info['status'] = $this->status; $info['email'] = $this->getEmail(); $info['fullname'] = $this->fullname; $info['dtcreated'] = Scalr_Util_DateTime::convertTz($this->dtCreated); $info['dtlastlogin'] = $this->dtLastLogin ? Scalr_Util_DateTime::convertTz($this->dtLastLogin) : 'Never'; $info['dtlastloginhr'] = $this->dtLastLogin ? Scalr_Util_DateTime::getFuzzyTimeString($this->dtLastLogin) : 'Never'; $info['gravatarhash'] = $this->getGravatarHash(); $info['type'] = $this->type; $info['comments'] = $this->comments; $info['is2FaEnabled'] = $this->getSetting(Scalr_Account_User::SETTING_SECURITY_2FA_GGL) == '1' ? true : false; $info['password'] = $this->password ? true : false; return $info; }
public function xGenerateApiKeyAction() { if ($this->user->isAdmin() || !\Scalr::config('scalr.system.api.enabled')) { throw new Scalr_Exception_InsufficientPermissions(); } $apiKeyEntity = new ApiKeyEntity($this->user->getId()); //It should prevents wiping out existing keys $attempts = 3; do { //Generates API KEY explicitly before saving $apiKeyEntity->keyId = $apiKeyEntity->getIterator()->getField('keyId')->getType()->generateValue($apiKeyEntity); if ($attempts-- == 0) { throw new RuntimeException("Could not generate uniquie API Key"); } } while (ApiKeyEntity::findPk($apiKeyEntity->keyId) !== null); // Saving a new API key $apiKeyEntity->save(); $row = get_object_vars($apiKeyEntity); $row['created'] = Scalr_Util_DateTime::convertTz($apiKeyEntity->created); $row['lastUsed'] = $apiKeyEntity->lastUsed ? Scalr_Util_DateTime::convertTz($apiKeyEntity->lastUsed) : 0; $row['createdHr'] = $apiKeyEntity->created ? Scalr_Util_DateTime::getFuzzyTimeString($apiKeyEntity->created) : ''; $row['lastUsedHr'] = $apiKeyEntity->lastUsed ? Scalr_Util_DateTime::getFuzzyTimeString($apiKeyEntity->lastUsed) : 'Never'; $this->response->data(['key' => $row]); }