From 831d450e3ff4157c4b3cfdb960eaae88b7bb7a23 Mon Sep 17 00:00:00 2001 From: ikawhero Date: Mon, 20 Aug 2007 08:30:34 +0000 Subject: [PATCH] Adding custom profile fields to the signup page. The only two authentication plugins this affects are email and ldap. --- auth/email/auth.php | 7 +++++++ auth/ldap/auth.php | 6 ++++++ login/signup_form.php | 3 +++ user/profile/lib.php | 19 +++++++++++++++++-- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/auth/email/auth.php b/auth/email/auth.php index 2fc47c0672..2480271ec5 100644 --- a/auth/email/auth.php +++ b/auth/email/auth.php @@ -74,11 +74,18 @@ class auth_plugin_email extends auth_plugin_base { * @param boolean $notify print notice with link and terminate */ function user_signup($user, $notify=true) { + global $CFG; + require_once($CFG->dirroot.'/user/profile/lib.php'); + $user->password = hash_internal_user_password($user->password); if (! ($user->id = insert_record('user', $user)) ) { print_error('auth_emailnoinsert','auth'); } + + /// Save any custom profile field information + profile_save_data($user); + if (! send_confirmation_email($user)) { print_error('auth_emailnoemail','auth'); } diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php index ea0c5c5b2c..cb2ec2efbf 100644 --- a/auth/ldap/auth.php +++ b/auth/ldap/auth.php @@ -340,6 +340,9 @@ class auth_plugin_ldap extends auth_plugin_base { * @param boolean $notify print notice with link and terminate */ function user_signup($user, $notify=true) { + global $CFG; + require_once($CFG->dirroot.'/user/profile/lib.php'); + if ($this->user_exists($user->username)) { print_error('auth_ldap_user_exists', 'auth'); } @@ -355,6 +358,9 @@ class auth_plugin_ldap extends auth_plugin_base { print_error('auth_emailnoinsert', 'auth'); } + /// Save any custom profile field information + profile_save_data($user); + $this->update_user_record($user->username); update_internal_user_password($user, $plainslashedpassword); diff --git a/login/signup_form.php b/login/signup_form.php index df2f0a1e96..c335774f99 100644 --- a/login/signup_form.php +++ b/login/signup_form.php @@ -1,6 +1,7 @@ libdir.'/formslib.php'); +require_once($CFG->dirroot.'/user/profile/lib.php'); class login_signup_form extends moodleform { function definition() { @@ -57,6 +58,8 @@ class login_signup_form extends moodleform { $mform->addRule('country', get_string('missingcountry'), 'required', null, 'server'); $mform->setDefault('country', ''); + profile_signup_fields($mform); + if (!empty($CFG->sitepolicy)) { $mform->addElement('header', '', get_string('policyagreement'), ''); $mform->addElement('static', 'policylink', '', ''.get_String('policyagreementclick').''); diff --git a/user/profile/lib.php b/user/profile/lib.php index 84ea1288ab..1d09efc31f 100644 --- a/user/profile/lib.php +++ b/user/profile/lib.php @@ -366,7 +366,22 @@ function profile_display_fields($userid) { } } - - +/** + * Adds code snippet to a moodle form object for custom profile fields that + * should appear on the signup page + * @param object moodle form object + */ +function profile_signup_fields(&$mform) { + global $CFG; + + if ($fields = get_records('user_info_field', 'signup', 1)) { + foreach ($fields as $field) { + require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php'); + $newfield = 'profile_field_'.$field->datatype; + $formfield = new $newfield($field->id); + $formfield->edit_field($mform); + } + } +} ?> -- 2.39.5