44 $this->params =&
$params[
'action'];
55 import(
'Dataface/Ontology.php');
59 $atts =& $this->ontology->getAttributes();
61 $query =&
$app->getQuery();
62 if ( !is_array(@
$app->_conf[
'_auth']) ){
66 if ( isset(
$app->_conf[
'_auth'][
'email_column']) ){
69 $atts[
'email'] =& $this->ontology->table->getField(
$app->_conf[
'_auth'][
'email_column'] );
70 $this->fieldnames[
'email'] =
$app->_conf[
'_auth'][
'email_column'];
74 if ( $auth->isLoggedIn() ){
80 if ( !@
$app->_conf[
'_auth'][
'allow_register'] ){
89 $this->form =& df_create_new_record_form(
$app->_conf[
'_auth'][
'users_table']);
92 $this->form->addElement(
'hidden',
'-action');
93 $this->form->setDefaults(array(
'-action'=>$query[
'-action']));
98 if ( count($_POST) > 0 and
PEAR::isError($validationResults) ){
99 $app->addMessage($validationResults->getMessage());
100 $this->form->_errors[
$app->_conf[
'_auth'][
'username_column']] = $validationResults->getMessage();
102 if ( !
PEAR::isError($validationResults) and $this->form->validate() ){
111 $rec =& $this->form->_record;
112 $delegate =& $rec->_table->getDelegate();
116 if ( isset($delegate) and method_exists($delegate,
'beforeRegister') ){
117 $res = $delegate->beforeRegister($rec);
123 $appdel = &
$app->getDelegate();
124 if ( isset($appdel) and method_exists($appdel,
'beforeRegister') ){
125 $res = $appdel->beforeRegister($rec);
131 $res = $this->form->process(array(&$this,
'processRegistrationForm'),
true);
137 $app->addError($res);
142 if ( isset($delegate) and method_exists($delegate,
'afterRegister') ){
143 $res = $delegate->afterRegister($rec);
147 if ( isset($appdel) and method_exists($appdel,
'afterRegister') ){
148 $res = $appdel->afterRegister($rec);
156 if ( isset($_SESSION[
'--redirect']) ) $url = $_SESSION[
'--redirect'];
157 else if ( isset($_SESSION[
'-redirect']) ) $url = $_SESSION[
'-redirect'];
158 else if ( isset($_REQUEST[
'--redirect']) ) $url = $_REQUEST[
'--redirect'];
159 else if ( isset($_REQUEST[
'-redirect']) ) $url = $_REQUEST[
'-redirect'];
160 else $url =
$app->url(
'-action='.
$app->_conf[
'default_action']);
162 if ( @
$params[
'email_validation'] ){
163 $individual = $this->ontology->newIndividual($this->form->_record);
164 $msg = df_translate(
'actions.register.MESSAGE_THANKYOU_PLEASE_VALIDATE',
165 'Thank you. An email has been sent to '.$individual->strval(
'email').
' with instructions on how to complete the registration process.',
166 array(
'email'=>$individual->strval(
'email'))
171 $_SESSION[
'UserName'] = $this->form->exportValue(
$app->_conf[
'_auth'][
'username_column']);
172 $msg = df_translate(
'actions.register.MESSAGE_REGISTRATION_SUCCESSFUL',
173 "Registration successful. You are now logged in."
177 if ( strpos($url,
'?') ===
false ) $url .=
'?';
178 $app->redirect($url.
'&--msg='.urlencode($msg));
185 $this->form->display();
186 $out = ob_get_contents();
189 $context = array(
'registration_form'=>
$out);
193 $app->prefs[
'no_history'] =
true;
194 df_display($context,
'Dataface_Registration.html');
203 $sql =
"create table `dataface__registrations` (
204 registration_code varchar(32) not null,
205 registration_date timestamp not null,
206 registration_data longtext not null,
207 primary key (registration_code))";
214 $res = mysql_query($sql, df_db());
215 if ( !$res )
throw new Exception(mysql_error(df_db()), E_USER_ERROR);
230 $del =&
$app->getDelegate();
231 if ( $del and method_exists($del,
'validateRegistrationForm') ){
232 $res = $del->validateRegistrationForm($values);
234 else if ( is_int($res) and $res === 2 )
return true;
236 $conf =&
$app->_conf[
'_auth'];
239 if ( !@$values[$conf[
'username_column']] )
241 df_translate(
'actions.register.MESSAGE_USERNAME_REQUIRED',
'Please enter a username')
246 $res = mysql_query(
"select count(*) from `".$conf[
'users_table'].
"` where `".$conf[
'username_column'].
"` = '".addslashes($values[$conf[
'username_column']]).
"'", df_db());
247 if ( !$res )
throw new Exception(mysql_error(df_db()), E_USER_ERROR);
249 list($num) = mysql_fetch_row($res);
252 df_translate(
'actions.register.MESSAGE_USERNAME_ALREADY_TAKEN',
'Sorry, that username is already in use by another user.')
257 if ( !@$values[$conf[
'password_column']] )
259 df_translate(
'actions.register.MESSAGE_PASSWORD_REQUIRED',
'Please enter a password')
263 $emailField = $this->ontology->getFieldname(
'email');
264 if ( !@$values[$emailField] or !$this->ontology->validate(
'email', @$values[$emailField],
false ))
266 df_translate(
'actions.register.MESSAGE_EMAIL_REQUIRED',
'Please enter a valid email address in order to register. A valid email address is required because an email will be sent to the address with information on how to activate this account.')
277 $appdel =&
$app->getDelegate();
278 $tdel =&
$table->getDelegate();
280 if ( isset($tdel) and method_exists($tdel, $name) ){
281 $res = $tdel->$name($record,
$params);
287 if ( isset($appdel) and method_exists($appdel, $name) ){
288 $res = $appdel->$name($record,
$params);
301 $conf =&
$app->_conf[
'_auth'];
302 $appConf =&
$app->conf();
305 if ( @$this->params[
'email_validation'] ){
320 "select registration_code
321 from dataface__registrations
322 where registration_code='".addslashes($code).
"'",
330 $sql =
"insert into dataface__registrations
331 (registration_code, registration_data) values
332 ('".addslashes($code).
"',
335 $this->form->_record->getValues()
338 $res = mysql_query($sql, df_db());
339 if ( !$res )
throw new Exception(mysql_error(df_db()), E_USER_ERROR);
341 $activation_url =
$_SERVER[
'HOST_URI'].DATAFACE_SITE_HREF.
'?-action=activate&code='.urlencode($code);
346 $res = $this->
_fireDelegateMethod(
'sendRegistrationActivationEmail', $this->form->_record, $activation_url );
355 $registrant =& $this->ontology->newIndividual($this->form->_record);
357 $email = $registrant->strval(
'email');
367 $info = $this->
_fireDelegateMethod(
'getRegistrationActivationEmailInfo', $this->form->_record, $activation_url);
369 $info[
'to'] = $email;
372 $subject = $this->
_fireDelegateMethod(
'getRegistrationActivationEmailSubject', $this->form->_record, $activation_url);
376 $message = $this->
_fireDelegateMethod(
'getRegistrationActivationEmailMessage', $this->form->_record, $activation_url);
379 $parameters = $this->
_fireDelegateMethod(
'getRegistrationActivationEmailParameters', $this->form->_record, $activation_url);
380 if ( !
PEAR::isError($parameters) ) $info[
'parameters'] = $parameters;
382 $headers = $this->
_fireDelegateMethod(
'getRegistrationActivationEmailHeaders', $this->form->_record, $activation_url);
387 if ( !@$info[
'subject'] )
388 $info[
'subject'] = df_translate(
389 'actions.register.MESSAGE_REGISTRATION_ACTIVATION_EMAIL_SUBJECT',
390 $app->getSiteTitle().
': Activate your account',
391 array(
'site_title'=>
$app->getSiteTitle())
394 if ( !@$info[
'message'] ){
395 $site_title =
$app->getSiteTitle();
396 if ( isset($appConf[
'abuse_email']) ){
397 $admin_email = $appConf[
'abuse_email'];
398 }
else if ( isset($appConf[
'admin_email']) ){
399 $admin_email = $appConf[
'admin_email'];
401 $admin_email =
$_SERVER[
'SERVER_ADMIN'];
404 if ( isset( $appConf[
'application_name'] ) ){
405 $application_name = $appConf[
'application_name'];
407 $application_name = df_translate(
'actions.register.LABEL_A_DATAFACE_APPLICATION',
'a Dataface Application');
410 if ( file_exists(
'version.txt') ){
411 $application_version = trim(file_get_contents(
'version.txt'));
413 $application_version =
'0.1';
416 if ( file_exists(DATAFACE_PATH.
'/version.txt') ){
417 $dataface_version = trim(file_get_contents(DATAFACE_PATH.
'/version.txt'));
419 $dataface_version =
'unknown';
426 Thank you
for registering
for an account on $site_title . In order to complete your registration,
427 please visit $activation_url .
429 If you have not registered
for an account on
this web site and believe that you have received
430 this email eroneously, please report
this to $admin_email .
431 -----------------------------------------------------------
432 This message was sent by $site_title which is powered by $application_name version $application_version
433 $application_name built
using Dataface version $dataface_version (http:
436 $info[
'message'] = df_translate(
437 'actions.register.MESSAGE_REGISTRATION_ACTIVATION_EMAIL_MESSAGE',
440 'site_title'=>$site_title,
441 'activation_url'=>$activation_url,
442 'admin_email'=>$admin_email,
443 'application_name'=>$application_name,
444 'application_version'=>$application_version,
445 'dataface_version'=>$dataface_version
455 if ( @$conf[
'_mail'][
'func'] ) $func = $conf[
'_mail'][
'func'];
457 $res = $func($info[
'to'],
461 @$info[
'parameters']);
471 return $this->form->process(array(&$this->form,
'save'),
true);
479 if ( @$perms[
'register'] ) $perms[
'new'] = 1;