2007-08-19 09:48:33 +00:00
< ? php
// $Id$
/**
* @ file
* User page callbacks for the openid module .
*/
/**
* Menu callback ; Process an OpenID authentication .
*/
function openid_authentication_page () {
2008-01-30 22:11:22 +00:00
$result = openid_complete ();
2007-08-19 09:48:33 +00:00
switch ( $result [ 'status' ]) {
case 'success' :
return openid_authentication ( $result );
case 'failed' :
drupal_set_message ( t ( 'OpenID login failed.' ), 'error' );
break ;
case 'cancel' :
drupal_set_message ( t ( 'OpenID login cancelled.' ));
break ;
}
drupal_goto ();
}
/**
* Menu callback ; Manage OpenID identities for the specified user .
*/
function openid_user_identities ( $account ) {
2008-10-13 00:33:05 +00:00
drupal_set_title ( $account -> name );
2008-10-26 18:06:39 +00:00
drupal_add_css ( drupal_get_path ( 'module' , 'openid' ) . '/openid.css' );
2007-08-19 09:48:33 +00:00
// Check to see if we got a response
2008-01-30 22:11:22 +00:00
$result = openid_complete ();
2007-08-19 09:48:33 +00:00
if ( $result [ 'status' ] == 'success' ) {
2008-01-30 22:11:22 +00:00
$identity = $result [ 'openid.claimed_id' ];
db_query ( " INSERT INTO { authmap} (uid, authname, module) VALUES (%d, '%s','openid') " , $account -> uid , $identity );
drupal_set_message ( t ( 'Successfully added %identity' , array ( '%identity' => $identity )));
2007-08-19 09:48:33 +00:00
}
$header = array ( t ( 'OpenID' ), t ( 'Operations' ));
$rows = array ();
$result = db_query ( " SELECT * FROM { authmap} WHERE module='openid' AND uid=%d " , $account -> uid );
while ( $identity = db_fetch_object ( $result )) {
2008-11-22 10:32:42 +00:00
$rows [] = array ( check_plain ( $identity -> authname ), l ( t ( 'Delete' ), 'user/' . $account -> uid . '/openid/delete/' . $identity -> aid ));
2007-08-19 09:48:33 +00:00
}
$output = theme ( 'table' , $header , $rows );
$output .= drupal_get_form ( 'openid_user_add' );
return $output ;
}
/**
* Form builder ; Add an OpenID identity .
*
* @ ingroup forms
2008-01-08 10:35:43 +00:00
* @ see openid_user_add_validate ()
2007-08-19 09:48:33 +00:00
*/
function openid_user_add () {
2008-01-30 22:11:22 +00:00
$form [ 'openid_identifier' ] = array (
2007-08-19 09:48:33 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'OpenID' ),
);
$form [ 'submit' ] = array ( '#type' => 'submit' , '#value' => t ( 'Add an OpenID' ));
return $form ;
}
function openid_user_add_validate ( $form , & $form_state ) {
// Check for existing entries.
2008-01-30 22:11:22 +00:00
$claimed_id = _openid_normalize ( $form_state [ 'values' ][ 'openid_identifier' ]);
2007-08-19 09:48:33 +00:00
if ( db_result ( db_query ( " SELECT authname FROM { authmap} WHERE authname='%s' " , $claimed_id ))) {
2008-01-30 22:11:22 +00:00
form_set_error ( 'openid_identifier' , t ( 'That OpenID is already in use on this site.' ));
2007-08-19 09:48:33 +00:00
}
else {
2008-04-14 17:48:46 +00:00
$return_to = url ( 'user/' . arg ( 1 ) . '/openid' , array ( 'absolute' => TRUE ));
2008-01-30 22:11:22 +00:00
openid_begin ( $form_state [ 'values' ][ 'openid_identifier' ], $return_to );
2007-08-19 09:48:33 +00:00
}
}
/**
* Menu callback ; Delete the specified OpenID identity from the system .
*/
2008-11-22 10:32:42 +00:00
function openid_user_delete_form ( $form_state , $account , $aid = 0 ) {
$authname = db_result ( db_query ( 'SELECT authname FROM {authmap} WHERE uid = %d AND aid = %d' , $account -> uid , $aid ));
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' );
}
function openid_user_delete_form_submit ( & $form_state , $form_values ) {
db_query ( " DELETE FROM { authmap} WHERE uid = %d AND aid = %d AND module = 'openid' " , $form_state [ '#parameters' ][ 2 ] -> uid , $form_state [ '#parameters' ][ 3 ]);
2007-08-19 09:48:33 +00:00
if ( db_affected_rows ()) {
drupal_set_message ( t ( 'OpenID deleted.' ));
}
2008-11-22 10:32:42 +00:00
$form_state [ '#redirect' ] = 'user/' . $form_state [ '#parameters' ][ 2 ] -> uid . '/openid' ;
2007-08-19 09:48:33 +00:00
}
2008-11-22 10:32:42 +00:00