Commit 9ad52315 authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan

changing setting of requried fields so if not set there is a page to set them always

changing ldap to work when only email is set
parent 39d4a634
......@@ -265,9 +265,7 @@ class AuthLdap extends Auth {
$attributes['lastname'] = $this->config['surnamefield' ];
$attributes['email'] = $this->config['emailfield'];
if (!$userinfo = $this->get_userinfo_ldap($username, $attributes)) {
throw new AuthUnknownUserException("Could not get data for user");
}
$userinfo = $this->get_userinfo_ldap($username, $attributes);
return (object)$userinfo;
}
......@@ -551,6 +549,7 @@ class PluginAuthLdap extends PluginAuth {
'title' => get_string('ldapfieldforemail', 'auth.ldap'),
'defaultvalue' => self::$default_config['emailfield'],
'help' => true,
'rules' => array('required' => true),
),
);
......
......@@ -373,6 +373,7 @@ function auth_setup () {
}
$USER->renew();
auth_check_password_change();
auth_check_required_fields();
}
else if ($sessionlogouttime > 0) {
// The session timed out
......@@ -655,6 +656,74 @@ function auth_get_available_auth_types($institution=null) {
return $result;
}
/**
* Checks that all the required fields are set, and handles setting them if required.
*/
function auth_check_required_fields() {
global $USER;
safe_require('artefact', 'internal');
require_once('pieforms/pieform.php');
$elements = array();
foreach(ArtefactTypeProfile::get_mandatory_fields() as $field => $type) {
if (get_profile_field($USER->get('id'), $field) != null) {
continue;
}
$elements[$field] = array(
'type' => $type,
'title' => get_string($field, 'artefact.internal'),
'rules' => array('required' => true)
);
// @todo ruthlessly stolen from artefact/internal/index.php, could be merged
if ($type == 'wysiwyg') {
$elements[$field]['rows'] = 10;
$elements[$field]['cols'] = 60;
}
if ($type == 'textarea') {
$elements[$field]['rows'] = 4;
$elements[$field]['cols'] = 60;
}
if ($field == 'country') {
$elements[$field]['options'] = getoptions_country();
$elements[$field]['defaultvalue'] = 'nz';
}
}
if (empty($elements)) { // No mandatory fields that aren't set
return;
}
$elements['submit'] = array(
'type' => 'submit',
'value' => get_string('submit')
);
$form = pieform(array(
'name' => 'requiredfields',
'method' => 'post',
'action' => '',
'elements' => $elements
));
$smarty = smarty();
$smarty->assign('form', $form);
$smarty->display('requiredfields.tpl');
exit;
}
function requiredfields_submit(Pieform $form, $values) {
global $USER, $SESSION;
foreach ($values as $field => $value) {
if (in_array($field, array('submit', 'sesskey'))) {
continue;
}
set_profile_field($USER->get('id'), $field, $value);
}
$SESSION->add_ok_msg(get_string('requiredfieldsset', 'auth'));
redirect();
}
/**
* Checks whether the current user needs to change their password, and handles
......@@ -984,6 +1053,7 @@ function login_submit(Pieform $form, $values) {
if (empty($authenticated)) {
$SESSION->add_error_msg(get_string('loginfailed'));
return;
}
}
......@@ -1028,41 +1098,40 @@ function login_submit(Pieform $form, $values) {
$USER->authinstance = $authinstance->id;
$userdata = $auth->get_user_info($username);
if (
empty($userdata) ||
empty($userdata->firstname) ||
empty($userdata->lastname) ||
empty($userdata->email)
) {
// TODO: eventually get_user_info won't have to return all of this information
if (empty($userdata) || empty($userdata->email)) {
throw new AuthUnknownUserException("\"$username\" is not known");
}
else {
// We have the data - create the user
$USER->lastlogin = db_format_timestamp(time());
// We have the data - create the user
$USER->lastlogin = db_format_timestamp(time());
if (isset($userdata->firstname)) {
$USER->firstname = $userdata->firstname;
$USER->lastname = $userdata->lastname;
$USER->email = $userdata->email;
try {
db_begin();
$USER->commit();
}
if (isset($userdata->lastname)) {
$USER->lastname = $userdata->lastname;
}
$USER->email = $userdata->email;
try {
db_begin();
$USER->commit();
if (isset($userdata->firstname)) {
set_profile_field($USER->id, 'firstname', $USER->firstname);
}
if (isset($userdata->lastname)) {
set_profile_field($USER->id, 'lastname', $USER->lastname);
set_profile_field($USER->id, 'email', $USER->email);
if ($authinstance->institution !== 'mahara') {
$USER->join_institution($authinstance->institution);
}
handle_event('createuser', $USER->to_stdclass());
db_commit();
$USER->reanimate($USER->id, $authinstance->id);
}
catch (Exception $e) {
db_rollback();
throw $e;
set_profile_field($USER->id, 'email', $USER->email);
if ($authinstance->institution !== 'mahara') {
$USER->join_institution($authinstance->institution);
}
handle_event('createuser', $USER->to_stdclass());
db_commit();
$USER->reanimate($USER->id, $authinstance->id);
}
catch (Exception $e) {
db_rollback();
throw $e;
}
}
......@@ -1120,6 +1189,7 @@ function login_submit(Pieform $form, $values) {
// User is allowed to log in
//$USER->login($userdata);
auth_check_password_change();
auth_check_required_fields();
}
/**
......
......@@ -68,4 +68,7 @@ $string['unabletosigninviasso'] = 'Unable to sign in via SSO';
$string['xmlrpccouldnotlogyouin'] = 'Sorry, could not log you in :(';
$string['xmlrpccouldnotlogyouindetail'] = 'Sorry, we could not log you into Mahara at this time. Please tryin again shortly, and if the problem persists, contact your administrator';
$string['requiredfields'] = 'Required profile fields';
$string['requiredfieldsset'] = 'Required profile fields set';
?>
......@@ -58,8 +58,7 @@ if (!empty($_SESSION['registered'])) {
}
$key = param_alphanum('key', null);
// Step three of registration - given a key, fill out mandatory profile fields,
// optional profile icon, and register the user
// Step three of registration - given a key register the user
if (isset($key)) {
// Begin the registration form buliding
......@@ -151,82 +150,7 @@ if (isset($key)) {
}
redirect();
}
function profileform_submit(Pieform $form, $values) {
create_registered_user($values);
}
function profileform_validate(Pieform $form, $values) {
foreach(ArtefactTypeProfile::get_mandatory_fields() as $field => $type) {
// @todo here and above, use the method for getting "always mandatory" fields
if (in_array($field, array('firstname', 'lastname', 'email'))) {
continue;
}
// @todo here, validate the fields using their static validate method
}
}
safe_require('artefact', 'internal');
$elements = array(
'mandatoryheader' => array(
'type' => 'html',
'value' => get_string('registerstep3fieldsmandatory')
)
);
foreach(ArtefactTypeProfile::get_mandatory_fields() as $field => $type) {
if (in_array($field, array('firstname', 'lastname', 'email'))) {
continue;
}
$elements[$field] = array(
'type' => $type,
'title' => get_string($field, 'artefact.internal'),
'rules' => array('required' => true)
);
// @todo ruthlessly stolen from artefact/internal/index.php, could be merged
if ($type == 'wysiwyg') {
$elements[$field]['rows'] = 10;
$elements[$field]['cols'] = 60;
}
if ($type == 'textarea') {
$elements[$field]['rows'] = 4;
$elements[$field]['cols'] = 60;
}
if ($field == 'country') {
$elements[$field]['options'] = getoptions_country();
$elements[$field]['defaultvalue'] = 'nz';
}
}
if (count($elements) < 2) { // No mandatory fields, just create the user
create_registered_user();
}
$elements['key'] = array(
'type' => 'hidden',
'name' => 'key',
'value' => $key
);
$elements['submit'] = array(
'type' => 'submit',
'value' => get_string('completeregistration', 'auth.internal')
);
$form = pieform(array(
'name' => 'profileform',
'method' => 'post',
'action' => '',
'elements' => $elements
));
$smarty = smarty();
$smarty->assign('register_profile_form', $form);
$smarty->assign('heading', get_string('register'));
$smarty->display('register.tpl');
exit;
create_registered_user();
}
......
{include file="header.tpl"}
{include file="columnfullstart.tpl"}
<h2>{str tag='requiredfields' section='auth'}</h2>
{$form}
{include file="columnfullend.tpl"}
{include file="footer.tpl"}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment