Projet

Général

Profil

Paste
Télécharger (3,69 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / openid / openid.pages.inc @ 6eb57d7f

1
<?php
2

    
3
/**
4
 * @file
5
 * User page callbacks for the openid module.
6
 */
7

    
8
/**
9
 * Menu callback; Process an OpenID authentication.
10
 */
11
function openid_authentication_page() {
12
  $result = openid_complete();
13
  switch ($result['status']) {
14
    case 'success':
15
      return openid_authentication($result);
16
    case 'failed':
17
      drupal_set_message(t('OpenID login failed.'), 'error');
18
      break;
19
    case 'cancel':
20
      drupal_set_message(t('OpenID login cancelled.'));
21
      break;
22
  }
23
  drupal_goto();
24
}
25

    
26
/**
27
 * Menu callback; Manage OpenID identities for the specified user.
28
 */
29
function openid_user_identities($account) {
30
  drupal_set_title(format_username($account));
31
  drupal_add_css(drupal_get_path('module', 'openid') . '/openid.css');
32

    
33
  // Check to see if we got a response
34
  $result = openid_complete();
35
  if ($result['status'] == 'success') {
36
    $identity = $result['openid.claimed_id'];
37
    $query = db_insert('authmap')
38
      ->fields(array(
39
        'uid' => $account->uid,
40
        'authname' => $identity,
41
        'module' => 'openid',
42
      ))
43
      ->execute();
44
    drupal_set_message(t('Successfully added %identity', array('%identity' => $identity)));
45
  }
46

    
47
  $header = array(t('OpenID'), t('Operations'));
48
  $rows = array();
49

    
50
  $result = db_query("SELECT * FROM {authmap} WHERE module='openid' AND uid=:uid", array(':uid' => $account->uid));
51
  foreach ($result as $identity) {
52
    $rows[] = array(check_plain($identity->authname), l(t('Delete'), 'user/' . $account->uid . '/openid/delete/' . $identity->aid));
53
  }
54

    
55
  $build['openid_table'] = array(
56
    '#theme' => 'table',
57
    '#header' => $header,
58
    '#rows' => $rows,
59
    '#empty' => t('No OpenID identities available for this account.'),
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['actions'] = array('#type' => 'actions');
77
  $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Add an OpenID'));
78
  return $form;
79
}
80

    
81
function openid_user_add_validate($form, &$form_state) {
82
  // Check for existing entries.
83
  $claimed_id = openid_normalize($form_state['values']['openid_identifier']);
84
  if (db_query("SELECT authname FROM {authmap} WHERE authname = :authname", (array(':authname' => $claimed_id)))->fetchField()) {
85
    form_set_error('openid_identifier', t('That OpenID is already in use on this site.'));
86
  }
87
}
88

    
89
function openid_user_add_submit($form, &$form_state) {
90
  $return_to = url('user/' . arg(1) . '/openid', array('absolute' => TRUE));
91
  openid_begin($form_state['values']['openid_identifier'], $return_to);
92
}
93

    
94
/**
95
 * Menu callback; Delete the specified OpenID identity from the system.
96
 */
97
function openid_user_delete_form($form, $form_state, $account, $aid = 0) {
98
  $authname = db_query("SELECT authname FROM {authmap} WHERE uid = :uid AND aid = :aid AND module = 'openid'", array(
99
    ':uid' => $account->uid,
100
    ':aid' => $aid,
101
  ))
102
  ->fetchField();
103
  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');
104
}
105

    
106
function openid_user_delete_form_submit($form, &$form_state) {
107
  $query = db_delete('authmap')
108
    ->condition('uid', $form_state['build_info']['args'][0]->uid)
109
    ->condition('aid', $form_state['build_info']['args'][1])
110
    ->condition('module', 'openid')
111
    ->execute();
112
  if ($query) {
113
    drupal_set_message(t('OpenID deleted.'));
114
  }
115
  $form_state['redirect'] = 'user/' . $form_state['build_info']['args'][0]->uid . '/openid';
116
}