Created
October 15, 2013 00:06
-
-
Save mikemilano/6984493 to your computer and use it in GitHub Desktop.
alt login example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Provides a web service for logging in. | |
*/ | |
/** | |
* Implements hook_menu(). | |
*/ | |
function altlogin_menu() { | |
$items = array(); | |
$items['altlogin'] = array( | |
'page callback' => 'altlogin_login_callback', | |
'delivery callback' => 'altlogin_delivery', | |
'access callback' => TRUE, | |
//'theme callback' => 'ajax_base_page_theme', | |
'type' => MENU_CALLBACK | |
); | |
return $items; | |
} | |
/** | |
* Login callback. | |
*/ | |
function altlogin_login_callback() { | |
// Pass login through user_login_authenticate_validate | |
// so we can hit the flood/ip validation logic. | |
$form = array(); | |
$form_state = array( | |
'values' => array( | |
'name' => $_POST['name'], | |
'pass' => $_POST['pass'] | |
) | |
); | |
user_login_authenticate_validate($form, $form_state); | |
// If $form_state['uid'] is set, then we passed validation. | |
if ($form_state['uid'] > 0) { | |
// Seal the deal with a new session | |
// and invoke login implementations | |
user_login_finalize(); | |
// Return a json success: status 1, or whatever makes sense. | |
return drupal_json_encode(array('status' => 1)); | |
} | |
// Return json failure: status 0 | |
return drupal_json_encode(array('status' => 0)); | |
} | |
/** | |
* Delivery plain json. | |
*/ | |
function altlogin_delivery($json) { | |
// Set header | |
drupal_add_http_header('Content-Type', 'application/json; charset=utf-8'); | |
print $json; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment