/** * {@inheritdoc} */ public static function setConfig($id, $config) { $rosConfig = OpenStackConfig::find($id); $pathConfig = FilePublicPath::find($id); $configPath = ['public_path' => ArrayUtils::get($config, 'public_path'), 'container' => ArrayUtils::get($config, 'container')]; $configRos = ['service_id' => ArrayUtils::get($config, 'service_id'), 'username' => ArrayUtils::get($config, 'username'), 'password' => ArrayUtils::get($config, 'password'), 'tenant_name' => ArrayUtils::get($config, 'tenant_name'), 'api_key' => ArrayUtils::get($config, 'api_key'), 'url' => ArrayUtils::get($config, 'url'), 'region' => ArrayUtils::get($config, 'region'), 'storage_type' => ArrayUtils::get($config, 'storage_type')]; ArrayUtils::removeNull($configRos); ArrayUtils::removeNull($configPath); if (!empty($rosConfig)) { $rosConfig->update($configRos); } else { //Making sure service_id is the first item in the config. //This way service_id will be set first and is available //for use right away. This helps setting an auto-generated //field that may depend on parent data. See OAuthConfig->setAttribute. $configRos = array_reverse($configRos, true); $configRos['service_id'] = $id; $configRos = array_reverse($configRos, true); OpenStackConfig::create($configRos); } if (!empty($pathConfig)) { $pathConfig->update($configPath); } else { //Making sure service_id is the first item in the config. //This way service_id will be set first and is available //for use right away. This helps setting an auto-generated //field that may depend on parent data. See OAuthConfig->setAttribute. $configPath = array_reverse($configPath, true); $configPath['service_id'] = $id; $configPath = array_reverse($configPath, true); FilePublicPath::create($configPath); } }
/** * {@inheritdoc} */ public static function setConfig($id, $config) { $azureConfig = AzureConfig::find($id); $pathConfig = FilePublicPath::find($id); $configPath = ['public_path' => ArrayUtils::get($config, 'public_path'), 'container' => ArrayUtils::get($config, 'container')]; $configAzure = ['service_id' => ArrayUtils::get($config, 'service_id'), 'account_name' => ArrayUtils::get($config, 'account_name'), 'account_key' => ArrayUtils::get($config, 'account_key'), 'protocol' => ArrayUtils::get($config, 'protocol')]; ArrayUtils::removeNull($configAzure); ArrayUtils::removeNull($configPath); if (!empty($azureConfig)) { $azureConfig->update($configAzure); } else { //Making sure service_id is the first item in the config. //This way service_id will be set first and is available //for use right away. This helps setting an auto-generated //field that may depend on parent data. See OAuthConfig->setAttribute. $configAzure = array_reverse($configAzure, true); $configAzure['service_id'] = $id; $configAzure = array_reverse($configAzure, true); AzureConfig::create($configAzure); } if (!empty($pathConfig)) { $pathConfig->update($configPath); } else { //Making sure service_id is the first item in the config. //This way service_id will be set first and is available //for use right away. This helps setting an auto-generated //field that may depend on parent data. See OAuthConfig->setAttribute. $configPath = array_reverse($configPath, true); $configPath['service_id'] = $id; $configPath = array_reverse($configPath, true); FilePublicPath::create($configPath); } }
/** * Registers new user. * * @return array * @throws \DreamFactory\Core\Exceptions\BadRequestException * @throws \DreamFactory\Core\Exceptions\ForbiddenException */ protected function handlePOST() { $payload = $this->getPayloadData(); $login = $this->request->getParameterAsBool('login'); $registrar = new Registrar(); $password = ArrayUtils::get($payload, 'new_password', ArrayUtils::get($payload, 'password')); $data = ['first_name' => ArrayUtils::get($payload, 'first_name'), 'last_name' => ArrayUtils::get($payload, 'last_name'), 'name' => ArrayUtils::get($payload, 'name'), 'email' => ArrayUtils::get($payload, 'email'), 'phone' => ArrayUtils::get($payload, 'phone'), 'security_question' => ArrayUtils::get($payload, 'security_question'), 'security_answer' => ArrayUtils::get($payload, 'security_answer'), 'password' => $password, 'password_confirmation' => ArrayUtils::get($payload, 'password_confirmation', $password)]; if (empty($data['first_name'])) { list($username, $domain) = explode('@', $data['email']); $data['first_name'] = $username; } if (empty($data['last_name'])) { $names = explode('.', $data['first_name']); if (isset($names[1])) { $data['last_name'] = $names[1]; $data['first_name'] = $names[0]; } else { $data['last_name'] = $names[0]; } } if (empty($data['name'])) { $data['name'] = $data['first_name'] . ' ' . $data['last_name']; } ArrayUtils::removeNull($data); /** @var \Illuminate\Validation\Validator $validator */ $validator = $registrar->validator($data); if ($validator->fails()) { $messages = $validator->errors()->getMessages(); throw new BadRequestException('Validation failed', null, null, $messages); } else { $user = $registrar->create($data); if ($login) { if ($user->confirm_code !== 'y' && !is_null($user->confirm_code)) { return ['success' => true, 'confirmation_required' => true]; } else { Session::setUserInfoWithJWT($user); return ['success' => true, 'session_token' => Session::getSessionToken()]; } } else { return ['success' => true]; } } }
/** * Updates user profile. * * @return array * @throws NotFoundException * @throws \Exception */ protected function handlePOST() { $payload = $this->getPayloadData(); $data = ['first_name' => ArrayUtils::get($payload, 'first_name'), 'last_name' => ArrayUtils::get($payload, 'last_name'), 'name' => ArrayUtils::get($payload, 'name'), 'email' => ArrayUtils::get($payload, 'email'), 'phone' => ArrayUtils::get($payload, 'phone'), 'security_question' => ArrayUtils::get($payload, 'security_question'), 'security_answer' => ArrayUtils::get($payload, 'security_answer'), 'default_app_id' => ArrayUtils::get($payload, 'default_app_id')]; ArrayUtils::removeNull($data); $user = Session::user(); if (empty($user)) { throw new NotFoundException('No user session found.'); } $oldToken = Session::getSessionToken(); $email = $user->email; $user->update($data); if (!empty($oldToken) && $email !== ArrayUtils::get($data, 'email', $email)) { // Email change invalidates token. Need to create a new token. $forever = JWTUtilities::isForever($oldToken); Session::setUserInfoWithJWT($user, $forever); $newToken = Session::getSessionToken(); return ['success' => true, 'session_token' => $newToken]; } return ['success' => true]; }