function gauth_user_services_save in Google Auth 7
Same name and namespace in other branches
- 7.2 gauth_user/gauth_user.module \gauth_user_services_save()
Save an account.
@returns a account array
Same account array reflects the changes
Parameters
array $account: Account array that needs to be saved If you want to create a new account omit the id field in the array If you want to update existing account do have the id field
1 call to gauth_user_services_save()
- gauth_user_services_edit_form_submit in gauth_user/
gauth_user.admin.inc - Submit handler for adding a new account to google auth services accounts.
File
- gauth_user/
gauth_user.module, line 178 - Google Auth Api for drupal.
Code
function gauth_user_services_save(&$account) {
if (!(isset($account['is_new']) && $account['is_new'])) {
$fields = array(
'id' => $account['id'],
);
if (isset($account['name'])) {
$fields['name'] = check_plain($account['name']);
}
if (isset($account['client_id'])) {
$fields['client_id'] = check_plain($account['client_id']);
}
if (isset($account['client_secret'])) {
$fields['client_secret'] = check_plain($account['client_secret']);
}
if (isset($account['developer_key'])) {
$fields['developer_key'] = check_plain($account['developer_key']);
}
if (isset($account['services'])) {
if (is_array($account['services'])) {
$account['services'] = implode(",", $account['services']);
}
$fields['services'] = check_plain($account['services']);
}
if (isset($account['access_type'])) {
$fields['access_type'] = $account['access_type'];
}
if (drupal_write_record('gauth_user_services', $fields, 'id') == SAVED_UPDATED) {
return $fields;
}
else {
return FALSE;
}
}
else {
if (!isset($account['name'])) {
return array(
'is_error' => TRUE,
'message' => 'Name is required for creating new services account',
);
}
if (!isset($account['client_id'])) {
return array(
'is_error' => TRUE,
'message' => 'Client Id can\'t be Null',
);
}
if (!isset($account['client_secret'])) {
return array(
'is_error' => TRUE,
'message' => 'Client Secret can\'t be Null',
);
}
$fields = array(
'id' => $account['id'],
'name' => check_plain($account['name']),
'developer_key' => check_plain($account['developer_key']),
'client_id' => check_plain($account['client_id']),
'client_secret' => check_plain($account['client_secret']),
'access_type' => $account['access_type'],
);
if (is_array($account['services'])) {
$account['services'] = implode(",", $account['services']);
}
$fields['services'] = check_plain($account['services']);
$accounts = gauth_user_services_load(NULL, TRUE, array(
'name',
));
$accounts = array_keys($accounts);
if (in_array($account['name'], $accounts)) {
return array(
'is_error' => TRUE,
'message' => 'Name is already in use. Please choose a unique name for the account',
);
}
if (drupal_write_record('gauth_user_services', $fields) == SAVED_NEW) {
return $fields;
}
else {
return FALSE;
}
}
}