00001 <?php
00002
00003
00012 function openid_authentication_page() {
00013 $result = openid_complete();
00014 switch ($result['status']) {
00015 case 'success':
00016 return openid_authentication($result);
00017 case 'failed':
00018 drupal_set_message(t('OpenID login failed.'), 'error');
00019 break;
00020 case 'cancel':
00021 drupal_set_message(t('OpenID login cancelled.'));
00022 break;
00023 }
00024 drupal_goto();
00025 }
00026
00030 function openid_user_identities($account) {
00031 drupal_set_title(check_plain($account->name));
00032 drupal_add_css(drupal_get_path('module', 'openid') . '/openid.css', 'module');
00033
00034
00035 $result = openid_complete();
00036 if ($result['status'] == 'success') {
00037 $identity = $result['openid.claimed_id'];
00038 db_query("INSERT INTO {authmap} (uid, authname, module) VALUES (%d, '%s','openid')", $account->uid, $identity);
00039 drupal_set_message(t('Successfully added %identity', array('%identity' => $identity)));
00040 }
00041
00042 $header = array(t('OpenID'), t('Operations'));
00043 $rows = array();
00044
00045 $result = db_query("SELECT * FROM {authmap} WHERE module='openid' AND uid=%d", $account->uid);
00046 while ($identity = db_fetch_object($result)) {
00047 $rows[] = array($identity->authname, l(t('Delete'), 'user/' . $account->uid . '/openid/delete/' . $identity->aid));
00048 }
00049
00050 $output = theme('table', $header, $rows);
00051 $output .= drupal_get_form('openid_user_add');
00052 return $output;
00053 }
00054
00061 function openid_user_add() {
00062 $form['openid_identifier'] = array(
00063 '#type' => 'textfield',
00064 '#title' => t('OpenID'),
00065 );
00066 $form['submit'] = array('#type' => 'submit', '#value' => t('Add an OpenID'));
00067 return $form;
00068 }
00069
00070 function openid_user_add_validate($form, &$form_state) {
00071
00072 $claimed_id = _openid_normalize($form_state['values']['openid_identifier']);
00073 if (db_result(db_query("SELECT authname FROM {authmap} WHERE authname='%s'", $claimed_id))) {
00074 form_set_error('openid_identifier', t('That OpenID is already in use on this site.'));
00075 }
00076 else {
00077 $return_to = url('user/' . arg(1) . '/openid', array('absolute' => TRUE));
00078 openid_begin($form_state['values']['openid_identifier'], $return_to);
00079 }
00080 }
00081
00085 function openid_user_delete($account, $aid = 0) {
00086 db_query("DELETE FROM {authmap} WHERE uid=%d AND aid=%d AND module='openid'", $account->uid, $aid);
00087 if (db_affected_rows()) {
00088 drupal_set_message(t('OpenID deleted.'));
00089 }
00090 drupal_goto('user/' . $account->uid . '/openid');
00091 }