openid.pages.inc

User page callbacks for the openid module.

Archivo

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

Functions

Nombreorden descendente Descripción
openid_authentication_page Menu callback; Process an OpenID authentication.
openid_user_add Form builder; Add an OpenID identity.
openid_user_add_submit
openid_user_add_validate
openid_user_delete_form Present a confirmation form to delete the specified OpenID identity from the system.
openid_user_delete_form_submit
openid_user_identities Menu callback; Manage OpenID identities for the specified user.