Mercurial > defr > drupal > core
comparison modules/openid/openid.pages.inc @ 1:c1f4ac30525a 6.0
Drupal 6.0
author | Franck Deroche <webmaster@defr.org> |
---|---|
date | Tue, 23 Dec 2008 14:28:28 +0100 |
parents | |
children | fff6d4c8c043 |
comparison
equal
deleted
inserted
replaced
0:5a113a1c4740 | 1:c1f4ac30525a |
---|---|
1 <?php | |
2 // $Id: openid.pages.inc,v 1.5 2008/01/30 22:11:22 goba 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(check_plain($account->name)); | |
32 drupal_add_css(drupal_get_path('module', 'openid') .'/openid.css', 'module'); | |
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 db_query("INSERT INTO {authmap} (uid, authname, module) VALUES (%d, '%s','openid')", $account->uid, $identity); | |
39 drupal_set_message(t('Successfully added %identity', array('%identity' => $identity))); | |
40 } | |
41 | |
42 $header = array(t('OpenID'), t('Operations')); | |
43 $rows = array(); | |
44 | |
45 $result = db_query("SELECT * FROM {authmap} WHERE module='openid' AND uid=%d", $account->uid); | |
46 while ($identity = db_fetch_object($result)) { | |
47 $rows[] = array($identity->authname, l(t('Delete'), 'user/'. $account->uid .'/openid/delete/'. $identity->aid)); | |
48 } | |
49 | |
50 $output = theme('table', $header, $rows); | |
51 $output .= drupal_get_form('openid_user_add'); | |
52 return $output; | |
53 } | |
54 | |
55 /** | |
56 * Form builder; Add an OpenID identity. | |
57 * | |
58 * @ingroup forms | |
59 * @see openid_user_add_validate() | |
60 */ | |
61 function openid_user_add() { | |
62 $form['openid_identifier'] = array( | |
63 '#type' => 'textfield', | |
64 '#title' => t('OpenID'), | |
65 ); | |
66 $form['submit'] = array('#type' => 'submit', '#value' => t('Add an OpenID')); | |
67 return $form; | |
68 } | |
69 | |
70 function openid_user_add_validate($form, &$form_state) { | |
71 // Check for existing entries. | |
72 $claimed_id = _openid_normalize($form_state['values']['openid_identifier']); | |
73 if (db_result(db_query("SELECT authname FROM {authmap} WHERE authname='%s'", $claimed_id))) { | |
74 form_set_error('openid_identifier', t('That OpenID is already in use on this site.')); | |
75 } | |
76 else { | |
77 $return_to = url('user/'. arg(1) .'/openid', array('absolute' => TRUE)); | |
78 openid_begin($form_state['values']['openid_identifier'], $return_to); | |
79 } | |
80 } | |
81 | |
82 /** | |
83 * Menu callback; Delete the specified OpenID identity from the system. | |
84 */ | |
85 function openid_user_delete($account, $aid = 0) { | |
86 db_query("DELETE FROM {authmap} WHERE uid=%d AND aid=%d AND module='openid'", $account->uid, $aid); | |
87 if (db_affected_rows()) { | |
88 drupal_set_message(t('OpenID deleted.')); | |
89 } | |
90 drupal_goto('user/'. $account->uid .'/openid'); | |
91 } |