materio_user.pages.inc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. function materio_user_registerblock(){
  3. $return = array();
  4. $block = block_load('materio_user','user_createaccount');
  5. $return['block'] = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
  6. drupal_json_output($return);
  7. }
  8. function materio_user_loginandregisterblock(){
  9. $return = array();
  10. $block = block_load('materio_user','user_register');
  11. $return['block'] = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
  12. drupal_json_output($return);
  13. }
  14. function materio_user_register_submit(){
  15. $return = array();
  16. $return['POST'] = $_POST;
  17. $form_state = array( "values"=>$_POST);
  18. drupal_form_submit($_POST['form_id'], $form_state);
  19. // $return['form_state'] = $form_state;
  20. $return['errors'] = form_get_errors();
  21. if($return['errors']){
  22. unset ($_SESSION['messages']['error']);
  23. }else{
  24. $messages = drupal_get_messages('status');
  25. // $return['messages'] = $messages;
  26. // drupal_set_message(t("Congratulations, you juste created your free materiO' account, welcome !"), 'status');
  27. foreach ($messages['status'] as $msg) {
  28. drupal_set_message($msg, 'status');
  29. }
  30. }
  31. // after registration user is automaticly logged in, thank's to login tobogan module
  32. drupal_json_output($return);
  33. }
  34. function materio_user_login_submit(){
  35. $return = array();
  36. $return['POST'] = $_POST;
  37. $form_state = array("values"=>$_POST);
  38. drupal_form_submit($_POST['form_id'], $form_state);
  39. $return['errors'] = form_get_errors();
  40. if($return['errors'])
  41. unset ($_SESSION['messages']['error']);
  42. // if user-login form succed we retreive the user uid on $form_state, then we can effectively loggin the user
  43. if($uid = $form_state['uid'])
  44. user_login_submit(array(), $form_state);
  45. drupal_json_output($return);
  46. }