Skip to content

Commit

Permalink
Adding custom profile fields to the signup page.
Browse files Browse the repository at this point in the history
The only two authentication plugins this affects are email and ldap.
  • Loading branch information
ikawhero committed Aug 20, 2007
1 parent 33a34cd commit 831d450
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
7 changes: 7 additions & 0 deletions auth/email/auth.php
Expand Up @@ -74,11 +74,18 @@ function can_signup() {
* @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');
}
Expand Down
6 changes: 6 additions & 0 deletions auth/ldap/auth.php
Expand Up @@ -340,6 +340,9 @@ function can_signup() {
* @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');
}
Expand All @@ -355,6 +358,9 @@ function user_signup($user, $notify=true) {
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);

Expand Down
3 changes: 3 additions & 0 deletions login/signup_form.php
@@ -1,6 +1,7 @@
<?php // $Id$

require_once($CFG->libdir.'/formslib.php');
require_once($CFG->dirroot.'/user/profile/lib.php');

class login_signup_form extends moodleform {
function definition() {
Expand Down Expand Up @@ -57,6 +58,8 @@ function definition() {
$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', '', '<a href="'.$CFG->sitepolicy.'" onclick="this.target=\'_blank\'">'.get_String('policyagreementclick').'</a>');
Expand Down
19 changes: 17 additions & 2 deletions user/profile/lib.php
Expand Up @@ -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);
}
}
}

?>

0 comments on commit 831d450

Please sign in to comment.