| 1 |
<?php
|
| 2 |
// $Id: openid.pages.inc,v 1.23 2009/11/01 21:26:44 webchick Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* User page callbacks for the openid module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Menu callback; Process an OpenID authentication.
|
| 11 |
*/
|
| 12 |
function openid_authentication_page() {
|
| 13 |
$result = openid_complete();
|
| 14 |
switch ($result['status']) {
|
| 15 |
case 'success':
|
| 16 |
return openid_authentication($result);
|
| 17 |
case 'failed':
|
| 18 |
drupal_set_message(t('OpenID login failed.'), 'error');
|
| 19 |
break;
|
| 20 |
case 'cancel':
|
| 21 |
drupal_set_message(t('OpenID login cancelled.'));
|
| 22 |
break;
|
| 23 |
}
|
| 24 |
drupal_goto();
|
| 25 |
}
|
| 26 |
|
| 27 |
/**
|
| 28 |
* Menu callback; Manage OpenID identities for the specified user.
|
| 29 |
*/
|
| 30 |
function openid_user_identities($account) {
|
| 31 |
drupal_set_title(format_username($account));
|
| 32 |
drupal_add_css(drupal_get_path('module', 'openid') . '/openid.css');
|
| 33 |
|
| 34 |
// Check to see if we got a response
|
| 35 |
$result = openid_complete();
|
| 36 |
if ($result['status'] == 'success') {
|
| 37 |
$identity = $result['openid.claimed_id'];
|
| 38 |
$query = db_insert('authmap')
|
| 39 |
->fields(array(
|
| 40 |
'uid' => $account->uid,
|
| 41 |
'authname' => $identity,
|
| 42 |
'module' => 'openid',
|
| 43 |
))
|
| 44 |
->execute();
|
| 45 |
drupal_set_message(t('Successfully added %identity', array('%identity' => $identity)));
|
| 46 |
}
|
| 47 |
|
| 48 |
$header = array(t('OpenID'), t('Operations'));
|
| 49 |
$rows = array();
|
| 50 |
|
| 51 |
$result = db_query("SELECT * FROM {authmap} WHERE module='openid' AND uid=:uid", array(':uid' => $account->uid));
|
| 52 |
foreach ($result as $identity) {
|
| 53 |
$rows[] = array(check_plain($identity->authname), l(t('Delete'), 'user/' . $account->uid . '/openid/delete/' . $identity->aid));
|
| 54 |
}
|
| 55 |
|
| 56 |
$build['openid_table'] = array(
|
| 57 |
'#theme' => 'table',
|
| 58 |
'#header' => $header,
|
| 59 |
'#rows' => $rows,
|
| 60 |
);
|
| 61 |
$build['openid_user_add'] = drupal_get_form('openid_user_add');
|
| 62 |
return $build;
|
| 63 |
}
|
| 64 |
|
| 65 |
/**
|
| 66 |
* Form builder; Add an OpenID identity.
|
| 67 |
*
|
| 68 |
* @ingroup forms
|
| 69 |
* @see openid_user_add_validate()
|
| 70 |
*/
|
| 71 |
function openid_user_add() {
|
| 72 |
$form['openid_identifier'] = array(
|
| 73 |
'#type' => 'textfield',
|
| 74 |
'#title' => t('OpenID'),
|
| 75 |
);
|
| 76 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Add an OpenID'));
|
| 77 |
return $form;
|
| 78 |
}
|
| 79 |
|
| 80 |
function openid_user_add_validate($form, &$form_state) {
|
| 81 |
// Check for existing entries.
|
| 82 |
$claimed_id = _openid_normalize($form_state['values']['openid_identifier']);
|
| 83 |
if (db_query("SELECT authname FROM {authmap} WHERE authname = :authname", (array(':authname' => $claimed_id)))->fetchField()) {
|
| 84 |
form_set_error('openid_identifier', t('That OpenID is already in use on this site.'));
|
| 85 |
}
|
| 86 |
}
|
| 87 |
|
| 88 |
function openid_user_add_submit($form, &$form_state) {
|
| 89 |
$return_to = url('user/' . arg(1) . '/openid', array('absolute' => TRUE));
|
| 90 |
openid_begin($form_state['values']['openid_identifier'], $return_to);
|
| 91 |
}
|
| 92 |
|
| 93 |
/**
|
| 94 |
* Menu callback; Delete the specified OpenID identity from the system.
|
| 95 |
*/
|
| 96 |
function openid_user_delete_form($form, $form_state, $account, $aid = 0) {
|
| 97 |
$authname = db_query("SELECT authname FROM {authmap} WHERE uid = :uid AND aid = :aid AND module = 'openid'", array(
|
| 98 |
':uid' => $account->uid,
|
| 99 |
':aid' => $aid,
|
| 100 |
))
|
| 101 |
->fetchField();
|
| 102 |
return confirm_form(array(), t('Are you sure you want to delete the OpenID %authname for %user?', array('%authname' => $authname, '%user' => $account->name)), 'user/' . $account->uid . '/openid');
|
| 103 |
}
|
| 104 |
|
| 105 |
function openid_user_delete_form_submit($form, &$form_state) {
|
| 106 |
$query = db_delete('authmap')
|
| 107 |
->condition('uid', $form_state['build_info']['args'][0]->uid)
|
| 108 |
->condition('aid', $form_state['build_info']['args'][1])
|
| 109 |
->condition('module', 'openid')
|
| 110 |
->execute();
|
| 111 |
if ($query) {
|
| 112 |
drupal_set_message(t('OpenID deleted.'));
|
| 113 |
}
|
| 114 |
$form_state['redirect'] = 'user/' . $form_state['build_info']['args'][0]->uid . '/openid';
|
| 115 |
}
|