function services_keyauth_admin_keys_form in Services 7
Same name and namespace in other branches
- 6.2 auth/services_keyauth/services_keyauth.admin.inc \services_keyauth_admin_keys_form()
1 string reference to 'services_keyauth_admin_keys_form'
- services_keyauth_menu in auth/
services_keyauth/ services_keyauth.module - Implements hook_menu().
File
- auth/
services_keyauth/ services_keyauth.admin.inc, line 42 - Generate security keys.
Code
function services_keyauth_admin_keys_form() {
$kid = arg(4);
$key = db_query("SELECT * FROM {services_keys} WHERE kid = :key", array(
':key' => $kid,
))
->fetchObject();
$key_kid = isset($key->kid) ? $key->kid : '';
$key_title = isset($key->title) ? $key->title : '';
$form['kid'] = array(
'#type' => 'hidden',
'#default_value' => $key_kid,
);
$accessible_methods = array();
if ($key_kid != '') {
$form['key'] = array(
'#type' => 'markup',
'#title' => t('Key'),
'#value' => '<strong>' . t('API Key') . ':</strong> ' . $key_kid,
);
$result = db_query("SELECT method FROM {services_key_permissions} WHERE kid = :key", array(
':key' => $kid,
));
while ($kid = $result
->fetchObject()) {
$accessible_methods[] = $kid->method;
}
}
$form['title'] = array(
'#title' => t('Application title'),
'#type' => 'textfield',
'#default_value' => $key_title,
'#description' => t('The title of the application or website using the service.'),
);
$form['domain'] = array(
'#title' => t('Allowed domain'),
'#type' => 'textfield',
'#default_value' => isset($key->domain) ? $key->domain : '',
'#description' => t('External domain allowed to use this key.'),
'#required' => TRUE,
);
$methods = services_get_all();
$form_methods = array();
foreach ($methods as $method) {
$form_methods[$method['#method']] = $method['#method'];
}
$form['method_access'] = array(
'#type' => 'checkboxes',
'#title' => t('Method access'),
'#options' => $form_methods,
'#default_value' => $accessible_methods,
'#description' => t('Define which methods are accessible.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => $key_title != '' ? t('Save key') : t('Create key'),
);
return $form;
}