phpDocumentor pond
[ class tree: pond ] [ index: pond ] [ all elements ]

Source for file register.php

Documentation is available at register.php

  1. <?php
  2. /**
  3.  * Register a new user.
  4.  *
  5.  * This file is part of Quam Plures - {@link http://quamplures.net/}
  6.  * See also {@link https://launchpad.net/quam-plures}.
  7.  *
  8.  * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
  9.  * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
  10.  *  Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
  11.  *
  12.  *  {@internal License choice
  13.  *  - If you have received this file as part of a package, please find the license.txt file in
  14.  *    the same folder or the closest folder above for complete license terms.
  15.  *  - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  16.  *    then you must choose one of the following licenses before using the file:
  17.  *    - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  18.  *    - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  19.  *  }}}
  20.  *
  21.  *  {@internal Open Source relicensing agreement:
  22.  *  Daniel HAHLER grants Francois PLANQUE the right to license
  23.  *  Daniel HAHLER's contributions to this file and the b2evolution project
  24.  *  under any OSI approved OSS license (http://www.opensource.org/licenses/).
  25.  *  }}}
  26.  *
  27.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  28.  * @author blueyed: Daniel HAHLER
  29.  * @author fplanque: Francois PLANQUE
  30.  *
  31.  * @package pond
  32.  */
  33.  
  34. /**
  35.  * Includes:
  36.  */
  37. require_once dirname(__FILE__).'/../qp_config/_config.php';
  38.  
  39. require_once $inc_path.'_main.inc.php';
  40.  
  41. // Login is not required on the register page:
  42. $login_required false;
  43.  
  44.  
  45. param'action''string''' );
  46. param'login''string''' );
  47. param'email''string''' );
  48. param'redirect_to''string''' )// do not default to $admin_url; "empty" gets handled better in the end (uses $blogurl, if no admin perms).
  49.  
  50.  
  51. if$Settings->get('newusers_canregister') )
  52. {
  53.     $action 'disabled';
  54. }
  55.  
  56. switch$action )
  57. {
  58.     case 'register':
  59.         /*
  60.          * Do the registration:
  61.          */
  62.         param'pass1''string''' );
  63.         param'pass2''string''' );
  64.  
  65.         // Call plugin event to allow catching input in general and validating own things from DisplayRegisterFormFieldset event
  66.         $Plugins->trigger_event'RegisterFormSent'array(
  67.                 'login' => $login,
  68.                 'email' => $email,
  69.                 'locale' => $locale,
  70.                 'pass1' => $pass1,
  71.                 'pass2' => $pass2,
  72.             ) );
  73.  
  74.         if$Messages->count'error' ) )
  75.         // a Plugin has added an error
  76.             break;
  77.         }
  78.  
  79.         // Check profile params:
  80.         profile_check_paramsarray(
  81.             'login' => $login,
  82.             'pass1' => $pass1,
  83.             'pass2' => $pass2,
  84.             'email' => $email,
  85.             'pass_required' => true ) );
  86.  
  87.         // We want all logins to be lowercase to guarantee uniqueness regardless of the database case handling for UNIQUE indexes:
  88.         $login strtolower$login );
  89.  
  90.         $UserCache get_Cache'UserCache' );
  91.         if$UserCache->get_by_login$login ) )
  92.         // The login is already registered
  93.             param_error'login'sprintfT_('The login &laquo;%s&raquo; is already registered, please choose another one.')$login ) );
  94.         }
  95.  
  96.         if$Messages->count'error' ) )
  97.         {
  98.             break;
  99.         }
  100.  
  101.         $DB->begin();
  102.  
  103.         $new_User new User();
  104.         $new_User->set'login'$login );
  105.         $new_User->set'pass'md5($pass1) )// encrypted
  106.         $new_User->set'nickname'$login );
  107.         $new_User->set_email$email );
  108.         $new_User->set'ip'$Hit->IP );
  109.         $new_User->set'domain'$Hit->get_remote_hosttrue ) );
  110.         $new_User->set'browser'substr$Hit->get_user_agent()200 ) );
  111.         $new_User->set_datecreated$localtimenow );
  112.         $new_User->set'locale'$locale );
  113.         $newusers_grp_ID $Settings->get('newusers_grp_ID');
  114.         $GroupCache get_Cache'GroupCache' );
  115.         $new_user_Group $GroupCache->get_by_ID$newusers_grp_ID );
  116.         $new_User->set_Group$new_user_Group );
  117.  
  118.          // Determine if the user must validate before using the system:
  119.         $new_User->set'validated'$Settings->get('newusers_mustvalidate') );
  120.  
  121.         $new_User->dbinsert();
  122.  
  123.         $new_user_ID $new_User->ID// we need this to "rollback" user creation if there's no DB transaction support
  124.  
  125.         // TODO: Optionally auto create a blog (handle this together with the LDAP plugin)
  126.  
  127.         // TODO: Optionally auto assign rights
  128.  
  129.         // Actions to be appended to the user registration transaction:
  130.         if$Plugins->trigger_event_first_false'AppendUserRegistrTransact'array'User' => $new_User ) ) )
  131.         {
  132.             // TODO: notify the plugins that have been called before about canceling of the event?!
  133.             $DB->rollback();
  134.  
  135.             // Delete, in case there's no transaction support:
  136.             $new_User->dbdelete$Debuglog );
  137.  
  138.             $Messages->addT_('No user account has been created!')'error' );
  139.             break// break out to _reg_form.php
  140.         }
  141.  
  142.         // User created:
  143.         $DB->commit();
  144.  
  145.         $UserCache->add$new_User );
  146.  
  147.         // Send email to admin (using his locale):
  148.         /**
  149.          * @var User 
  150.          */
  151.         $AdminUser $UserCache->get_by_ID);
  152.         locale_temp_switch$AdminUser->get'locale' ) );
  153.  
  154.         $message  T_('New user registration on your blog').":\n"
  155.                             ."\n"
  156.                             .T_('Login:')." $login\n"
  157.                             .T_('Email')."$email\n"
  158.                             ."\n"
  159.                             .T_('Edit user').': '.$admin_url.'?ctrl=users&user_ID='.$new_User->ID."\n";
  160.  
  161.         send_mail$AdminUser->get'email' )NULLT_('New user registration on your blog')$message$notify_from )// ok, if this may fail..
  162.  
  163.         locale_restore_previous()// restores previous locale
  164.  
  165.         $Plugins->trigger_event'AfterUserRegistration'array'User' => $new_User ) );
  166.  
  167.  
  168.         if$Settings->get('newusers_mustvalidate') )
  169.         // We want that the user validates his email address:
  170.             if$new_User->send_validate_email($redirect_to) )
  171.             {
  172.                 $Messages->addT_('An email has been sent to your email address. Please click on the link therein to validate your account.')'success' );
  173.             }
  174.             else
  175.             {
  176.                 $Messages->addT_('Sorry, the email with the link to validate and activate your password could not be sent.')
  177.                     .'<br />'.T_('Possible reason: the PHP mail() function may have been disabled on the server.')'error' );
  178.                 // fp> TODO: allow to enter a different email address (just in case it's that kind of problem)
  179.             }
  180.         }
  181.  
  182.         // Autologin the user. This is more comfortable for the user and avoids
  183.         // extra confusion when account validation is required.
  184.         $Session->set_User$new_User );
  185.  
  186.         // Display confirmation screen:
  187.         require $admintemplates_path.'login/_reg_complete.main.php';
  188.  
  189.         exit(0);
  190.         break;
  191.  
  192.  
  193.     case 'disabled':
  194.         /*
  195.          * Registration disabled:
  196.          */
  197.         require $admintemplates_path.'login/_reg_disabled.main.php';
  198.  
  199.         exit(0);
  200. }
  201.  
  202.  
  203. /*
  204.  * Default: registration form:
  205.  */
  206. // Display reg form:
  207. require $admintemplates_path.'login/_reg_form.main.php';
  208.  
  209.  
  210. ?>