示例#1
0
 /**
  * @param Instance $instance
  * @param bool     $object If true, the Metadata object is returned instead of the array
  *
  * @return array|\DreamFactory\Enterprise\Common\Support\Metadata
  */
 public static function makeMetadata(Instance $instance, $object = false)
 {
     if (null === ($_key = AppKey::mine($instance->id, OwnerTypes::INSTANCE))) {
         //  Create an instance key
         $_key = AppKey::create(['key_class_text' => AppKeyClasses::INSTANCE, 'owner_id' => $instance->id, 'owner_type_nbr' => OwnerTypes::INSTANCE, 'server_secret' => config('dfe.security.console-api-key')]);
         if (null === $_key) {
             throw new \RuntimeException('Instance is unlicensed.');
         }
     }
     $_cluster = static::_lookupCluster($instance->cluster_id);
     $_md = new Metadata(array_merge(static::$metadataTemplate, ['storage-map' => InstanceStorage::buildStorageMap($instance->user->storage_id_text), 'env' => static::buildEnvironmentMetadata($instance, $_cluster, $_key), 'db' => static::buildDatabaseMetadata($instance), 'paths' => static::buildPathMetadata($instance), 'audit' => static::buildAuditMetadata($instance), 'limits' => static::buildLimitsMetadata($instance)]), $instance->instance_name_text . '.json', $instance->getOwnerPrivateStorageMount());
     return $object ? $_md : $_md->toArray();
 }
 /**
  *
  * @param int $ownerId
  * @param int $ownerType
  *
  * @return AppKey
  */
 protected static function findAppKey($ownerId, $ownerType)
 {
     return AppKey::mine($ownerId, $ownerType);
 }
示例#3
0
 /**
  * Standardized user creation method
  *
  * @param \Illuminate\Http\Request $request
  * @param bool                     $validate If false, no validation is done.
  *
  * @return \DreamFactory\Enterprise\Common\Packets\ErrorPacket|\DreamFactory\Enterprise\Common\Packets\SuccessPacket
  */
 public static function register(Request $request, $validate = true)
 {
     $_email = $request->input('email', $request->input('email_addr_text'));
     $_first = $request->input('firstname', $request->input('first_name_text'));
     $_last = $request->input('lastname', $request->input('last_name_text'));
     $_password = $request->input('password', $request->input('password_text'));
     $_nickname = $request->input('nickname', $request->input('nickname_text', $_first));
     $_company = $request->input('company', $request->input('company_name_text'));
     $_phone = $request->input('phone', $request->input('phone_text'));
     if ($validate) {
         if (empty($_email) || empty($_password) || empty($_first) || empty($_last)) {
             /** @noinspection PhpUndefinedMethodInspection */
             Log::error('missing required fields from partner post', ['payload' => $request->input()]);
             throw new \InvalidArgumentException('Missing required fields');
         }
         if (false === filter_var($_email, FILTER_VALIDATE_EMAIL)) {
             /** @noinspection PhpUndefinedMethodInspection */
             Log::error('invalid email address "' . $_email . '"', ['payload' => $request->input()]);
             throw new \InvalidArgumentException('Email address invalid');
         }
     }
     //  See if we know this cat...
     if (null !== ($_user = User::byEmail($_email)->first())) {
         //  Existing user found, don't add to database...
         $_values = $_user->toArray();
         unset($_values['password_text'], $_values['external_password_text']);
         /** @noinspection PhpUndefinedMethodInspection */
         Log::info('existing user attempting registration through api', ['user' => $_values]);
         return $_user;
     }
     //  Create a user account
     try {
         /** @type User $_user */
         /** @noinspection PhpUndefinedMethodInspection */
         $_user = DB::transaction(function () use($request, $_first, $_last, $_email, $_password, $_nickname, $_phone, $_company) {
             /** @noinspection PhpUndefinedMethodInspection */
             $_user = User::create(['first_name_text' => $_first, 'last_name_text' => $_last, 'email_addr_text' => $_email, 'nickname_text' => $_nickname, 'password_text' => Hash::make($_password), 'phone_text' => $_phone, 'company_name_text' => $_company]);
             if (null === ($_appKey = AppKey::mine($_user->id, OwnerTypes::USER))) {
                 $_appKey = AppKey::create(['key_class_text' => AppKeyClasses::USER, 'owner_id' => $_user->id, 'owner_type_nbr' => OwnerTypes::USER, 'server_secret' => config('dfe.security.console-api-key')]);
             }
             //  Update the user with the key info and activate
             $_user->api_token_text = $_appKey->client_id;
             $_user->active_ind = 1;
             $_user->save();
             return $_user;
         });
         $_values = $_user->toArray();
         unset($_values['password_text'], $_values['external_password_text']);
         /** @noinspection PhpUndefinedMethodInspection */
         Log::info('new user registered', ['user' => $_values]);
         return $validate ? SuccessPacket::create($_user, Response::HTTP_CREATED) : $_user;
     } catch (\Exception $_ex) {
         if (false !== ($_pos = stripos($_message = $_ex->getMessage(), ' (sql: '))) {
             $_message = substr($_message, 0, $_pos);
         }
         /** @noinspection PhpUndefinedMethodInspection */
         Log::error('database error creating user from ops-resource post: ' . $_message);
         return $validate ? ErrorPacket::create(null, Response::HTTP_INTERNAL_SERVER_ERROR, $_message) : null;
     }
 }