/** * Regenerate Client Id & Secret for application * * @return void */ public function resetClientSecretTask() { // [SECURITY] Check for request forgeries Request::checkToken(); // Incoming $ids = Request::getVar('id', array(0)); $ids = !is_array($ids) ? array($ids) : $ids; // Do we actually have any entries? if (count($ids) < 1) { // No entries found, so go back to the entries list with // a message scolding the user for not selecting anything. Tsk, tsk. App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_DEVELOPER_SELECT_APPLICATION_TO', $this->_task), 'error'); return; } // loop through each id foreach ($ids as $id) { // Load the entry and set its state $row = new Models\Api\Application(intval($id)); // generate new client secret $clientSecret = $row->newClientSecret(); // set our new value on application & store $row->set('client_secret', $clientSecret); $row->store(false); } // Set the redirect URL to the main entries listing. App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_DEVELOPER_REGENERATE_CLIENT_ID_AND_SECRET_SUCCESS')); }
/** * Save developer application details * * @return void */ public function saveTask() { // CSRF check Request::checkToken(); // get request vars $data = Request::getVar('application', array(), 'post', 2, 'none'); $team = Request::getVar('team', array(), 'post', 2, 'none'); // bind data to model $model = new Models\Api\Application($data); // must be logged in if (User::isGuest()) { $return = Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=edit&id=' . $data['id'], false, true); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($return))); return; } // is the app available if ($model->isDeleted()) { App::redirect(Route::url('index.php?option=com_developer&controller=applications'), Lang::txt('COM_DEVELOPER_API_APPLICATION_DOES_NOT_EXIST'), 'warning'); return; } // make sure its ours if (!$this->config->get('access-edit-application', 0) && (!$this->config->get('access-create-application', 0) && $data['id'] > 0)) { App::redirect(Route::url('index.php?option=com_developer&controller=applications'), Lang::txt('COM_DEVELOPER_API_APPLICATION_NOT_AUTHORIZED'), 'warning'); return; } // attempt to save model if (!$model->store(true)) { $this->setError($model->getError()); $this->editTask($model); return; } // parse incoming team $team = array_map('trim', explode(',', $team)); // clean up team foreach ($team as $k => $t) { // handle usernames & emails if (!is_numeric($t)) { // handle emails if (strpos($t, '@')) { // load profile by email $profile = \Hubzero\User\Profile\Helper::find_by_email($t); } else { // load profile by username $profile = \Hubzero\User\Profile::getInstance($t); } // swap usernames for uidnumbers if ($profile) { $team[$k] = $profile->get('uidNumber'); } else { unset($team[$k]); } } } // add creator if new // will only ever get added once $team[] = User::get('id'); // get current team $currentTeam = $model->team()->lists('uidNumber'); // add each non-team member to team foreach (array_diff($team, $currentTeam) as $uidNumber) { if ($uidNumber < 1) { continue; } // new team member object $teamMember = new Models\Api\Application\Team\Member(array('uidNumber' => $uidNumber, 'application_id' => $model->get('id'))); $teamMember->store(); } // Redirect back to the main listing with a success message App::redirect(Route::url($model->link()), Lang::txt('COM_DEVELOPER_API_APPLICATION_SAVED'), 'passed'); }