Created
October 12, 2011 20:10
-
-
Save arturo-c/1282387 to your computer and use it in GitHub Desktop.
This file contains 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
diff --git a/www/sites/all/modules/apci_features/apci_public_api_services/resources/user_resource.inc b/www/sites/all/modules/apci_features/apci_public_api_services/resources/user_resource.inc | |
old mode 100644 | |
new mode 100755 | |
index ef2c449..19c9510 | |
--- a/www/sites/all/modules/apci_features/apci_public_api_services/resources/user_resource.inc | |
+++ b/www/sites/all/modules/apci_features/apci_public_api_services/resources/user_resource.inc | |
@@ -58,6 +58,20 @@ function apci_public_api_services_user_resource_definition() { | |
'description' => 'User password', // @todo from *CCK* def | |
'type' => 'string', // @todo from def | |
), | |
+ array( | |
+ 'name' => 'captcha_token', // @todo from def | |
+ 'optional' => TRUE, // @todo from def | |
+ 'source' => 'data', | |
+ 'description' => 'Token of Captcha', // @todo from *CCK* def | |
+ 'type' => 'string', // @todo from def | |
+ ), | |
+ array( | |
+ 'name' => 'captcha_answer', // @todo from def | |
+ 'optional' => TRUE, // @todo from def | |
+ 'source' => 'data', | |
+ 'description' => 'Captcha Answer', // @todo from *CCK* def | |
+ 'type' => 'string', // @todo from def | |
+ ), | |
), | |
'access callback' => '_apci_api_user_access', | |
'access arguments' => array('create'), | |
@@ -411,7 +425,7 @@ function _apci_api_user_access($op, $args) { | |
case 'create': | |
// Users who do not have "services access all users" should not be able to create users | |
// @todo Creation of users should be permissible through controlled roles. | |
- $access = FALSE; | |
+ $access = TRUE; | |
break; | |
case 'index': | |
// Users who do not have "services access all users" should not be able to list users | |
@@ -467,7 +481,7 @@ function _apci_api_user_access($op, $args) { | |
/** | |
* User Resource Callbacks | |
*/ | |
-function _apci_api_user_create($firstname, $lastname, $email, $gender, $birthday, $password = NULL) { | |
+function _apci_api_user_create($firstname, $lastname, $email, $gender, $birthday, $password=NULL, $captcha_token=NULL, $captcha_answer=NULL) { | |
$account = array( | |
'mail' => $email, | |
'field_firstname' => array(array('value' => $firstname)), | |
@@ -487,10 +501,55 @@ function _apci_api_user_create($firstname, $lastname, $email, $gender, $birthday | |
// Force password change on first login. | |
// 'force_password_change' => '1', | |
); | |
- | |
- $user = (object) _user_resource_create($account); | |
- uuid_user('load', $edit, $user, NULL); | |
- return _apci_api_user_retrieve($user->uuid, '*'); | |
+ module_load_include('inc', 'user', 'user.pages'); | |
+ // register a new user | |
+ $form_state['values'] = $account; | |
+ $form_state['values']['pass'] = array( | |
+ 'pass1' => $account['pass'], | |
+ 'pass2' => $account['pass'], | |
+ ); | |
+ $form_state['values']['op'] = t('Create new account'); | |
+ | |
+ module_load_include('inc', 'captcha'); | |
+ if (is_null($captcha_token)) { | |
+ $captcha_sid = _captcha_generate_captcha_session('user_register', CAPTCHA_STATUS_UNSOLVED); | |
+ $captcha_token = md5(mt_rand()); | |
+ list($captcha_type_module, $captcha_type_challenge) = _captcha_parse_captcha_type('default'); | |
+ $captcha = module_invoke($captcha_type_module, 'captcha', 'generate', $captcha_type_challenge, $captcha_sid); | |
+ db_query("UPDATE {captcha_sessions} SET token='%s',solution='%s' WHERE csid=%d", $captcha_token, $captcha['solution'], $captcha_sid); | |
+ } else { | |
+ $result = db_fetch_array(db_query("SELECT csid, solution from {captcha_sessions} WHERE token='%s'", $captcha_token)); | |
+ $captcha['solution'] = $result['solution']; | |
+ $captcha_sid = $result['csid']; | |
+ } | |
+ if ($captcha_answer == $captcha['solution']) { | |
+ db_query("UPDATE {captcha_sessions} SET status=%d, attempts=attempts+1 WHERE csid=%d", CAPTCHA_STATUS_SOLVED, $captcha_sid); | |
+ global $user; | |
+ $user_creator = $user; | |
+ $user = drupal_anonymous_user(); | |
+ $form_state['captcha_info'] = array('form_id' => 'user_register', 'captcha_sid' => $captcha_sid, 'solution' => $captcha_answer); | |
+ drupal_execute('user_register', $form_state); | |
+ } else { | |
+ db_query("UPDATE {captcha_sessions} SET attempts=attempts+1 WHERE csid=%d", $captcha_sid); | |
+ $errors = ""; | |
+ return services_error(implode(" ", $errors), 406, array('form_errors' => 'Invalid captcha, please validate by solving math problem and sending solution, you will need to add capcha_token and captcha_answer to the paramaters.', 'captcha_token' => $captcha_token, 'captcha_problem' => $captcha['form']['captcha_response']['#field_prefix'])); | |
+ } | |
+ // Error if needed. | |
+ if ($errors = form_get_errors()) { | |
+ return services_error(implode(" ", $errors), 406, array('form_errors' => $errors, 'captcha_token' => $captcha_sid, 'captcha_problem' => $captcha['form']['captcha_response']['#field_prefix'])); | |
+ } else { | |
+ $created_user = $form_state['user']; | |
+ uuid_user('load', $edit, $created_user, NULL); | |
+ if ($user_creator->uid == 0) { | |
+ $tmp = NULL; | |
+ session_destroy(); | |
+ user_module_invoke('logout', $tmp, $user); | |
+ $user = drupal_anonymous_user(); | |
+ } else { | |
+ user_load($user_creator); | |
+ } | |
+ return _apci_api_user_retrieve($created_user->uuid, '*'); | |
+ } | |
} | |
/** | |
diff --git a/www/sites/default/global_app_settings.php b/www/sites/default/global_app_settings.php | |
index 295576a..6545f12 100755 | |
--- a/www/sites/default/global_app_settings.php | |
+++ b/www/sites/default/global_app_settings.php | |
@@ -1102,7 +1102,7 @@ $conf['advagg_bundler_max_js'] = "4"; | |
$conf['advagg_checksum_mode'] = "md5"; | |
$conf['advagg_closure'] = TRUE; | |
$conf['advagg_dir_htaccess'] = TRUE; | |
-$conf['advagg_enabled'] = TRUE; | |
+$conf['advagg_enabled'] = FALSE; | |
$conf['advagg_gzip_compression'] = FALSE; | |
$conf['advagg_js_compress_callback'] = TRUE; | |
$conf['advagg_page_cache_mode'] = TRUE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment