public function stage() { parent::stage(); if (!$this->serviceExists('files')) { \DreamFactory\Core\Models\Service::create(['name' => 'files', 'label' => 'Local file service', 'description' => 'Local file service for unit test', 'is_active' => true, 'type' => 'local_file', 'config' => ['container' => 'local']]); } }
/** * Authenticates valid user. * * @return array * @throws \DreamFactory\Core\Exceptions\BadRequestException * @throws \DreamFactory\Core\Exceptions\UnauthorizedException */ protected function handlePOST() { $serviceName = $this->getPayloadData('service'); if (empty($serviceName)) { $serviceName = $this->request->getParameter('service'); } if (!empty($serviceName)) { $service = ServiceHandler::getService($serviceName); $serviceModel = Service::find($service->getServiceId()); $serviceType = $serviceModel->serviceType()->first(); $serviceGroup = $serviceType->group; if (!in_array($serviceGroup, [ServiceTypeGroups::OAUTH, ServiceTypeGroups::LDAP])) { throw new BadRequestException('Invalid login service provided. Please use an OAuth or AD/Ldap service.'); } if ($serviceGroup === ServiceTypeGroups::LDAP) { $credentials = ['username' => $this->getPayloadData('username'), 'password' => $this->getPayloadData('password')]; return $service->handleLogin($credentials, $this->getPayloadData('remember_me')); } elseif ($serviceGroup === ServiceTypeGroups::OAUTH) { $oauthCallback = $this->request->getParameterAsBool('oauth_callback'); if (!empty($oauthCallback)) { return $service->handleOAuthCallback(); } else { return $service->handleLogin($this->request->getDriver()); } } } else { $credentials = ['email' => $this->getPayloadData('email'), 'password' => $this->getPayloadData('password'), 'is_sys_admin' => false]; return $this->handleLogin($credentials, boolval($this->getPayloadData('remember_me'))); } }
public function testPasswordResetUsingConfirmationCode() { if (!$this->serviceExists('mymail')) { $emailService = \DreamFactory\Core\Models\Service::create(["name" => "mymail", "label" => "Test mail service", "description" => "Test mail service", "is_active" => true, "type" => "local_email", "mutable" => true, "deletable" => true, "config" => ["driver" => "sendmail", "command" => "/usr/sbin/sendmail -bs"]]); $userConfig = \DreamFactory\Core\User\Models\UserConfig::find(4); $userConfig->password_email_service_id = $emailService->id; $userConfig->save(); } if (!\DreamFactory\Core\Models\EmailTemplate::whereName('mytemplate')->exists()) { $template = \DreamFactory\Core\Models\EmailTemplate::create(['name' => 'mytemplate', 'description' => 'test', 'to' => $this->user2['email'], 'subject' => 'rest password test', 'body_text' => 'link {link}']); $userConfig = \DreamFactory\Core\User\Models\UserConfig::find(4); $userConfig->password_email_template_id = $template->id; $userConfig->save(); } Arr::set($this->user2, 'email', '*****@*****.**'); $user = $this->createUser(2); Config::set('mail.pretend', true); $rs = $this->makeRequest(Verbs::POST, static::RESOURCE, ['reset' => 'true'], ['email' => $user['email']]); $content = $rs->getContent(); $this->assertTrue($content['success']); /** @var User $userModel */ $userModel = User::find($user['id']); $code = $userModel->confirm_code; $rs = $this->makeRequest(Verbs::POST, static::RESOURCE, ['login' => 'true'], ['email' => $user['email'], 'code' => $code, 'new_password' => '778877']); $content = $rs->getContent(); $this->assertTrue($content['success']); $this->assertTrue(Session::isAuthenticated()); $userModel = User::find($user['id']); $this->assertEquals('y', $userModel->confirm_code); $this->service = ServiceHandler::getService($this->serviceId); $rs = $this->makeRequest(Verbs::POST, 'session', [], ['email' => $user['email'], 'password' => '778877']); $content = $rs->getContent(); $this->assertTrue(!empty($content['session_id'])); }
public function getLaunchUrlAttribute() { $launchUrl = ''; switch ($this->type) { case AppTypes::STORAGE_SERVICE: if (!empty($this->storage_service_id)) { /** @var $service Service */ $service = Service::whereId($this->storage_service_id)->first(); if (!empty($service)) { $launchUrl .= $service->name . '/'; if (!empty($this->storage_container)) { $launchUrl .= trim($this->storage_container, '/'); } if (!empty($this->path)) { $launchUrl .= '/' . ltrim($this->path, '/'); } $launchUrl = url($launchUrl); } } break; case AppTypes::PATH: $launchUrl = url($this->path); break; case AppTypes::URL: $launchUrl = $this->url; break; } return $launchUrl; }
/** * Internal building method builds all static services and some dynamic * services from file annotations, otherwise swagger info is loaded from * database or storage files for each service, if it exists. * * @throws \Exception */ protected static function buildEventMaps() { \Log::info('Building event cache'); // Build event mapping from services in database // Initialize the event map $processEventMap = []; $broadcastEventMap = []; // Pull any custom swagger docs $result = ServiceModel::with(['serviceDocs' => function ($query) { $query->where('format', ApiDocFormatTypes::SWAGGER); }])->get(); // Spin through services and pull the events foreach ($result as $service) { $apiName = $service->name; try { if (empty($content = ServiceModel::getStoredContentForService($service))) { throw new \Exception(' * No event content found for service.'); continue; } $serviceEvents = static::parseSwaggerEvents($apiName, $content); // Parse the events while we get the chance... $processEventMap[$apiName] = ArrayUtils::get($serviceEvents, 'process', []); $broadcastEventMap[$apiName] = ArrayUtils::get($serviceEvents, 'broadcast', []); unset($content, $service, $serviceEvents); } catch (\Exception $ex) { \Log::error(" * System error building event map for service '{$apiName}'.\n{$ex->getMessage()}"); } } static::$eventMap = ['process' => $processEventMap, 'broadcast' => $broadcastEventMap]; // Write event cache file \Cache::forever(static::EVENT_CACHE_KEY, static::$eventMap); \Log::info('Event cache build process complete'); }
protected function getRecordExtras() { $emailService = Service::whereName('email')->first(); $emailTemplateInvite = EmailTemplate::whereName('User Invite Default')->first(); $emailTemplatePassword = EmailTemplate::whereName('Password Reset Default')->first(); $emailTemplateOpenReg = EmailTemplate::whereName('User Registration Default')->first(); return ['config' => ['allow_open_registration' => false, 'open_reg_email_service_id' => !empty($emailService) ? $emailService->id : null, 'open_reg_email_template_id' => !empty($emailTemplateOpenReg) ? $emailTemplateOpenReg->id : null, 'invite_email_service_id' => !empty($emailService) ? $emailService->id : null, 'invite_email_template_id' => !empty($emailTemplateInvite) ? $emailTemplateInvite->id : null, 'password_email_service_id' => !empty($emailService) ? $emailService->id : null, 'password_email_template_id' => !empty($emailTemplatePassword) ? $emailTemplatePassword->id : null]]; }
public function stage() { parent::stage(); Artisan::call('migrate', ['--path' => 'vendor/dreamfactory/df-rackspace/database/migrations/']); Artisan::call('db:seed', ['--class' => DreamFactory\Core\Rackspace\Database\Seeds\DatabaseSeeder::class]); if (!$this->serviceExists('ros')) { \DreamFactory\Core\Models\Service::create(["name" => "ros", "label" => "Rackspace Cloud Files service", "description" => "Rackspace Cloud Files service for unit test", "is_active" => true, "type" => "rackspace_cloud_files", "config" => ['username' => env('ROS_USERNAME'), 'password' => env('ROS_PASSWORD'), 'tenant_name' => env('ROS_TENANT_NAME'), 'api_key' => env('ROS_API_KEY'), 'url' => env('ROS_URL'), 'region' => env('ROS_REGION'), 'storage_type' => env('ROS_STORAGE_TYPE'), 'container' => env('ROS_CONTAINER')]]); } }
public function stage() { parent::stage(); Artisan::call('migrate', ['--path' => 'vendor/dreamfactory/df-aws/database/migrations/']); Artisan::call('db:seed', ['--class' => DreamFactory\Core\Aws\Database\Seeds\DatabaseSeeder::class]); if (!$this->serviceExists('s3')) { \DreamFactory\Core\Models\Service::create(["name" => "s3", "label" => "S3 file service", "description" => "S3 file service for unit test", "is_active" => true, "type" => "aws_s3", "config" => ['key' => env('AWS_S3_KEY'), 'secret' => env('AWS_S3_SECRET'), 'region' => env('AWS_S3_REGION'), 'container' => env('AWS_S3_CONTAINER')]]); } }
public function stage() { parent::stage(); Artisan::call('migrate', ['--path' => 'vendor/dreamfactory/df-azure/database/migrations/']); Artisan::call('db:seed', ['--class' => DreamFactory\Core\Azure\Database\Seeds\DatabaseSeeder::class]); if (!$this->serviceExists('azure')) { \DreamFactory\Core\Models\Service::create(["name" => "azure", "label" => "Azure Blob file service", "description" => "Azure Blob file service for unit test", "is_active" => true, "type" => "azure_blob", "config" => ['protocol' => 'https', 'account_name' => env('AB_ACCOUNT_NAME'), 'account_key' => env('AB_ACCOUNT_KEY'), 'container' => env('AB_CONTAINER')]]); } }
public function stage() { parent::stage(); Artisan::call('migrate', ['--path' => 'vendor/dreamfactory/df-rws/database/migrations/']); Artisan::call('db:seed', ['--class' => DreamFactory\Core\Rws\Database\Seeds\DatabaseSeeder::class]); if (!$this->serviceExists('rave')) { \DreamFactory\Core\Models\Service::create(["name" => "rave", "type" => "rws", "label" => "Remote web service", "config" => ["base_url" => "http://df.local/rest", "cache_enabled" => false]]); } }
public function stage() { parent::stage(); Artisan::call('migrate', ['--path' => 'vendor/dreamfactory/df-rws/database/migrations/']); Artisan::call('db:seed', ['--class' => DreamFactory\Core\Rws\Database\Seeds\DatabaseSeeder::class]); if (!$this->serviceExists('gmap')) { \DreamFactory\Core\Models\Service::create(["name" => "gmap", "type" => "rws", "label" => "Remote web service", "config" => ["base_url" => "http://maps.googleapis.com/maps/api/directions/json", "cache_enabled" => false, "parameters" => [["name" => "origin", "value" => "5965 Willow Oak Pass, Cumming, GA 30040", "outbound" => true, "cache_key" => true, "action" => 31], ["name" => "destination", "value" => "3600 Mansell Rd. Alpharetta, GA", "outbound" => true, "cache_key" => true, "action" => 31]]]]); } if (!$this->serviceExists('dsp-tester')) { \DreamFactory\Core\Models\Service::create(["name" => "dsp-tester", "type" => "rws", "label" => "Remote web service", "config" => ["base_url" => "https://dsp-tester.cloud.dreamfactory.com/rest", "cache_enabled" => false, "headers" => [["name" => "Authorization", "value" => "Basic YXJpZmlzbGFtQGRyZWFtZmFjdG9yeS5jb206dGVzdCEyMzQ=", "pass_from_client" => false, "action" => 31], ["name" => "X-DreamFactory-Application-Name", "value" => "admin", "pass_from_client" => false, "action" => 31], ["name" => "X-HTTP-Method", "pass_from_client" => true, "action" => 31]]]]); } }
public function index() { $uri = static::getURI($_SERVER); $dist = env('DF_INSTALL', ''); if (empty($dist) && false !== stripos(env('DB_DATABASE', ''), 'bitnami')) { $dist = 'Bitnami'; } $appCount = App::all()->count(); $adminCount = User::whereIsSysAdmin(1)->count(); $userCount = User::whereIsSysAdmin(0)->count(); $serviceCount = Service::all()->count(); $roleCount = Role::all()->count(); $status = ["uri" => $uri, "managed" => env('DF_MANAGED', false), "dist" => $dist, "demo" => Environment::isDemoApplication(), "version" => \Config::get('df.version'), "host_os" => PHP_OS, "resources" => ["app" => $appCount, "admin" => $adminCount, "user" => $userCount, "service" => $serviceCount, "role" => $roleCount]]; return ResponseFactory::sendResponse(ResponseFactory::create($status)); }
/** * @param array $schema */ protected static function prepareConfigSchemaField(array &$schema) { parent::prepareConfigSchemaField($schema); $roleList = [['label' => '', 'name' => null]]; $emailSvcList = [['label' => '', 'name' => null]]; $templateList = [['label' => '', 'name' => null]]; switch ($schema['name']) { case 'open_reg_role_id': $roles = Role::whereIsActive(1)->get(); foreach ($roles as $role) { $roleList[] = ['label' => $role->name, 'name' => $role->id]; } $schema['type'] = 'picklist'; $schema['values'] = $roleList; $schema['label'] = 'Open Reg Role'; $schema['description'] = 'Select a role for self registered users.'; break; case 'open_reg_email_service_id': case 'invite_email_service_id': case 'password_email_service_id': $label = substr($schema['label'], 0, strlen($schema['label']) - 11); $services = Service::whereIsActive(1)->whereIn('type', ['aws_ses', 'smtp_email', 'mailgun_email', 'mandrill_email', 'local_email'])->get(); foreach ($services as $service) { $emailSvcList[] = ['label' => $service->label, 'name' => $service->id]; } $schema['type'] = 'picklist'; $schema['values'] = $emailSvcList; $schema['label'] = $label . ' Service'; $schema['description'] = 'Select an Email service for sending out ' . $label . '.'; break; case 'open_reg_email_template_id': case 'invite_email_template_id': case 'password_email_template_id': $label = substr($schema['label'], 0, strlen($schema['label']) - 11); $templates = EmailTemplate::get(); foreach ($templates as $template) { $templateList[] = ['label' => $template->name, 'name' => $template->id]; } $schema['type'] = 'picklist'; $schema['values'] = $templateList; $schema['label'] = $label . ' Template'; $schema['description'] = 'Select an Email template to use for ' . $label . '.'; break; } }
/** * {@inheritdoc} */ protected static function sendPasswordResetEmail(User $user) { $email = $user->email; $userService = Service::getCachedByName('user'); $config = $userService['config']; if (empty($config)) { throw new InternalServerErrorException('Unable to load user service configuration.'); } $emailServiceId = $config['password_email_service_id']; if (!empty($emailServiceId)) { try { /** @var EmailService $emailService */ $emailService = ServiceHandler::getServiceById($emailServiceId); if (empty($emailService)) { throw new ServiceUnavailableException("Bad service identifier '{$emailServiceId}'."); } $data = []; $templateId = $config['password_email_template_id']; if (!empty($templateId)) { $data = $emailService::getTemplateDataById($templateId); } if (empty($data) || !is_array($data)) { throw new ServiceUnavailableException("No data found in default email template for password reset."); } $data['to'] = $email; $data['content_header'] = 'Password Reset'; $data['first_name'] = $user->first_name; $data['last_name'] = $user->last_name; $data['name'] = $user->name; $data['phone'] = $user->phone; $data['email'] = $user->email; $data['link'] = url(\Config::get('df.confirm_reset_url')) . '?code=' . $user->confirm_code; $data['confirm_code'] = $user->confirm_code; $emailService->sendEmail($data, ArrayUtils::get($data, 'body_text'), ArrayUtils::get($data, 'body_html')); return true; } catch (\Exception $ex) { throw new InternalServerErrorException("Error processing password reset.\n{$ex->getMessage()}"); } } return false; }
/** * Creates a non-admin user. * * @param array $data * * @return \DreamFactory\Core\Models\User * @throws \DreamFactory\Core\Exceptions\ForbiddenException * @throws \DreamFactory\Core\Exceptions\InternalServerErrorException * @throws \Exception */ public function create(array $data) { $userService = Service::getCachedByName('user'); if (!$userService['config']['allow_open_registration']) { throw new ForbiddenException('Open Registration is not enabled.'); } $openRegEmailSvcId = $userService['config']['open_reg_email_service_id']; $openRegEmailTplId = $userService['config']['open_reg_email_template_id']; $openRegRoleId = $userService['config']['open_reg_role_id']; /** @type User $user */ $user = User::create($data); if (!empty($openRegEmailSvcId)) { $this->sendConfirmation($user, $openRegEmailSvcId, $openRegEmailTplId); } else { if (!empty($data['password'])) { $user->password = $data['password']; $user->save(); } } if (!empty($openRegRoleId)) { User::applyDefaultUserAppRole($user, $openRegRoleId); } return $user; }
public function __construct($type, array $settings) { $this->fill($settings); $this->type = $type; $table = $this->refTable; if ($this->isForeignService && $this->refServiceId) { $table = Service::getCachedNameById($this->refServiceId) . '.' . $table; } switch ($this->type) { case static::BELONGS_TO: $this->name = $table . '_by_' . $this->field; break; case static::HAS_MANY: $this->name = $table . '_by_' . $this->refFields; break; case static::MANY_MANY: $junction = $this->junctionTable; if ($this->isForeignJunctionService && $this->junctionServiceId) { $junction = Service::getCachedNameById($this->junctionServiceId) . '.' . $junction; } $this->name = $table . '_by_' . $junction; break; default: break; } }
protected function getRecordExtras() { $systemServiceId = Service::whereType('system')->value('id'); return ['service_id' => $systemServiceId, 'table' => 'sql_db_config']; }
/** * Package schemas for export. * * @return bool * @throws \DreamFactory\Core\Exceptions\InternalServerErrorException */ private function packageSchemas() { if (!empty($this->exportSchemas)) { $schemas = []; foreach ($this->exportSchemas as $serviceName => $component) { if (is_array($component)) { $component = implode(',', $component); } if (is_numeric($serviceName)) { /** @type Service $service */ $service = Service::find($serviceName); } else { /** @type Service $service */ $service = Service::whereName($serviceName)->whereDeletable(1)->first(); } if (!empty($service) && !empty($component)) { if ($service->type === 'sql_db') { $schema = ServiceHandler::handleRequest(Verbs::GET, $serviceName, '_schema', ['ids' => $component]); $schemas[] = ['name' => $serviceName, 'table' => $this->resourceWrapped ? $schema[$this->resourceWrapper] : $schema]; } } } if (!empty($schemas) && !$this->zip->addFromString('schema.json', json_encode(['service' => $schemas], JSON_UNESCAPED_SLASHES))) { throw new InternalServerErrorException("Can not include database schema in package file."); } return true; } return false; }
/** * @param array $extras * * @return void */ public function setSchemaFieldExtras($extras) { if (empty($extras)) { return; } foreach ($extras as $extra) { if (!empty($table = ArrayUtils::get($extra, 'table')) && !empty($field = ArrayUtils::get($extra, 'field'))) { if (!empty($extra['ref_table']) && empty($extra['ref_service_id'])) { if (!empty($extra['ref_service'])) { // translate name to id for storage $extra['ref_service_id'] = Service::getCachedByName($extra['ref_service'], 'id', $this->getServiceId()); } else { // don't allow empty ref_service_id into the database, needs to be searchable from other services $extras['ref_service_id'] = $this->getServiceId(); } } DbFieldExtras::updateOrCreate(['service_id' => $this->getServiceId(), 'table' => $table, 'field' => $field], array_only($extra, ['alias', 'label', 'extra_type', 'description', 'picklist', 'validation', 'client_info', 'db_function', 'ref_service_id', 'ref_table', 'ref_fields', 'ref_on_update', 'ref_on_delete'])); } } }
protected function getRecordExtras() { $systemServiceId = Service::whereType('system')->value('id'); return ['service_id' => $systemServiceId]; }
protected static function setExceptions() { if (class_exists(\DreamFactory\Core\User\Services\User::class)) { $userService = Service::getCachedByName('user'); if ($userService['config']['allow_open_registration']) { static::$exceptions[] = ['verb_mask' => 2, 'service' => 'user', 'resource' => 'register']; } } }
protected function createDbService($num) { $serviceName = 'db' . $num; $service = \DreamFactory\Core\Models\Service::whereName($serviceName)->first(); if (empty($service)) { $service = \DreamFactory\Core\Models\Service::create(["name" => $serviceName, "label" => "Database" . $num, "description" => "Local Database" . $num, "is_active" => true, "type" => "sql_db", 'config' => ['dsn' => 'foo', 'username' => 'user', 'password' => 'password', 'db' => 'mydb', 'options' => 'options', 'attributes' => 'attributes']]); } return $service->id; }
/** * Execute the console command. * * @return mixed */ public function handle() { if (!class_exists('DreamFactory\\Core\\ADLdap\\Services\\ADLdap')) { $this->error('Command unavailable. Please install \'dreamfactory/df-adldap\' package to use this command.'); return; } try { $serviceName = $this->argument('service'); $username = $this->option('username'); $password = $this->option('password'); /** @type ADLdap $service */ $service = ServiceHandler::getService($serviceName); $serviceModel = Service::find($service->getServiceId()); $serviceType = $serviceModel->serviceType()->first(); $serviceGroup = $serviceType->group; if ($serviceGroup !== ServiceTypeGroups::LDAP) { throw new BadRequestException('Invalid service name [' . $serviceName . ']. Please use a valid Active Directory service'); } $this->line('Contacting your Active Directory server...'); $service->authenticateAdminUser($username, $password); $this->line('Fetching Active Directory groups...'); $groups = $service->getDriver()->listGroup(['dn', 'description']); $roles = []; foreach ($groups as $group) { $dfRole = RoleADLdap::whereDn($group['dn'])->first(); if (empty($dfRole)) { $role = ['name' => static::dnToRoleName($group['dn']), 'description' => $group['description'], 'is_active' => true, 'role_adldap_by_role_id' => [['dn' => $group['dn']]]]; $this->info('|--------------------------------------------------------------------'); $this->info('| DN: ' . $group['dn']); $this->info('| Role Name: ' . $role['name']); $this->info('| Description: ' . $role['description']); $this->info('|--------------------------------------------------------------------'); $roles[] = $role; } } $roleCount = count($roles); if ($roleCount > 0) { $this->warn('Total Roles to import: [' . $roleCount . ']'); if ($this->confirm('The above roles will be imported into your DreamFactroy instance based on your Active Directory groups. Do you wish to continue?')) { $this->line('Importing Roles...'); $payload = ResourcesWrapper::wrapResources($roles); ServiceHandler::handleRequest(Verbs::POST, 'system', 'role', ['continue' => true], $payload); $this->info('Successfully imported all Active Directory groups as Roles.'); } else { $this->info('Aborted import process. No Roles were imported'); } } else { if (count($groups) > 0 && $roleCount === 0) { $this->info('All groups found on the Active Directory server are already imported.'); } else { $this->warn('No group was found on Active Directory server.'); } } } catch (RestException $e) { $this->error($e->getMessage()); if ($this->option('verbose')) { $this->error(print_r($e->getContext(), true)); } } catch (\Exception $e) { $this->error($e->getMessage()); } }
/** * * @return array */ public static function listServices() { return ResourcesWrapper::wrapResources(Service::available()); }
public static function getStoredContentForService(Service $service) { // check the database records for custom doc in swagger, raml, etc. $info = $service->serviceDocs()->first(); $content = isset($info) ? $info->content : null; if (is_string($content)) { $content = json_decode($content, true); } else { $serviceClass = $service->serviceType()->first()->class_name; $settings = $service->toArray(); /** @var BaseRestService $obj */ $obj = new $serviceClass($settings); $content = $obj->getApiDocInfo(); } return $content; }
/** * Checks to see if a service already exists * * @param string $serviceName * * @return bool */ protected function serviceExists($serviceName) { return Service::whereName($serviceName)->exists(); }
/** * @param $userId * @param bool|false $deleteOnError * * @throws \DreamFactory\Core\Exceptions\BadRequestException * @throws \DreamFactory\Core\Exceptions\InternalServerErrorException * @throws \DreamFactory\Core\Exceptions\NotFoundException * @throws \Exception */ protected static function sendInvite($userId, $deleteOnError = false) { /** @type BaseSystemModel $user */ $user = \DreamFactory\Core\Models\User::find($userId); if (empty($user)) { throw new NotFoundException('User not found with id ' . $userId . '.'); } if ('y' === strtolower($user->confirm_code)) { throw new BadRequestException('User with this identifier has already confirmed this account.'); } try { $userService = Service::getCachedByName('user'); $config = $userService['config']; if (empty($config)) { throw new InternalServerErrorException('Unable to load system configuration.'); } $emailServiceId = $config['invite_email_service_id']; $emailTemplateId = $config['invite_email_template_id']; if (empty($emailServiceId)) { throw new InternalServerErrorException('No email service configured for user invite.'); } if (empty($emailTemplateId)) { throw new InternalServerErrorException("No default email template for user invite."); } /** @var EmailService $emailService */ $emailService = ServiceHandler::getServiceById($emailServiceId); $emailTemplate = EmailTemplate::find($emailTemplateId); if (empty($emailTemplate)) { throw new InternalServerErrorException("No data found in default email template for user invite."); } try { $email = $user->email; $code = \Hash::make($email); $user->confirm_code = base64_encode($code); $user->save(); $templateData = $emailTemplate->toArray(); $data = array_merge($templateData, ['to' => $email, 'confirm_code' => $user->confirm_code, 'link' => url(\Config::get('df.confirm_invite_url')) . '?code=' . $user->confirm_code, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'name' => $user->name, 'email' => $user->email, 'phone' => $user->phone, 'content_header' => ArrayUtils::get($templateData, 'subject', 'You are invited to try DreamFactory.'), 'instance_name' => \Config::get('df.instance_name')]); } catch (\Exception $e) { throw new InternalServerErrorException("Error creating user invite. {$e->getMessage()}", $e->getCode()); } $emailService->sendEmail($data, $emailTemplate->body_text, $emailTemplate->body_html); } catch (\Exception $e) { if ($deleteOnError) { $user->delete(); } throw new InternalServerErrorException("Error processing user invite. {$e->getMessage()}", $e->getCode()); } }
/** * @return array */ protected static function getAdLdapServices() { $ldap = ServiceModel::whereIn('type', ['ldap', 'adldap'])->whereIsActive(1)->get(['name', 'type', 'label']); $services = []; foreach ($ldap as $l) { $services[] = ['path' => 'user/session?service=' . strtolower($l->name), 'name' => $l->name, 'label' => $l->label, 'verb' => Verbs::POST, 'payload' => ['username' => 'string', 'password' => 'string', 'service' => $l->name, 'remember_me' => 'bool']]; } return $services; }
/** * Main retrieve point for each service * * @param string $name Which service (name) to retrieve. * * @return string * @throws NotFoundException */ public function getSwaggerForService($name) { $cachePath = $name . '.json'; if (null === ($content = \Cache::get($cachePath))) { $service = Service::whereName($name)->get()->first(); if (empty($service)) { throw new NotFoundException("Service '{$name}' not found."); } $content = ['swaggerVersion' => static::SWAGGER_VERSION, 'apiVersion' => \Config::get('df.api_version', static::API_VERSION), 'basePath' => url('/api/v2')]; try { $result = Service::getStoredContentForService($service); if (empty($result)) { throw new NotFoundException("No Swagger content found."); } $content = array_merge($content, $result); $content = json_encode($content, JSON_UNESCAPED_SLASHES); // replace service type placeholder with api name for this service instance $content = str_replace('{api_name}', $name, $content); // cache it for later access \Cache::forever($cachePath, $content); } catch (\Exception $ex) { \Log::error(" * System error creating swagger file for service '{$name}'.\n{$ex->getMessage()}"); } } return $content; }