Commit dd3bd845 authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith

Admin amail changing at install time

parent 490df230
......@@ -394,21 +394,38 @@ class ArtefactTypeEmail extends ArtefactTypeProfileField {
parent::commit();
$email_record = get_record('artefact_internal_profile_email', 'owner', $this->owner, 'email', $this->title);
// we've created a new artefact that doesn't have a profile email thingy.
// we assume that it's a validated email, and set it to primary (if there isn't already one)
if(!$email_record) {
$principal = get_record('artefact_internal_profile_email', 'owner', $this->owner, 'principal', 1);
insert_record(
'artefact_internal_profile_email',
(object) array(
'owner' => $this->owner,
'email' => $this->title,
'verified' => 1,
'principal' => ( $principal ? 0 : 1 ),
'artefact' => $this->id,
)
);
if (record_exists('artefact_internal_profile_email', 'owner', $this->owner, 'artefact', $this->id)) {
update_record(
'artefact_internal_profile_email',
(object) array(
'email' => $this->title,
'verified' => 1,
),
(object) array(
'owner' => $this->owner,
'artefact' => $this->id,
)
);
if (get_field('artefact_internal_profile_email', 'principal', 'owner', $this->owner, 'artefact', $this->id)) {
update_record('usr', (object) array( 'email' => $this->title, 'id' => $this->owner));
}
}
else {
$principal = get_record('artefact_internal_profile_email', 'owner', $this->owner, 'principal', 1);
insert_record(
'artefact_internal_profile_email',
(object) array(
'owner' => $this->owner,
'email' => $this->title,
'verified' => 1,
'principal' => ( $principal ? 0 : 1 ),
'artefact' => $this->id,
)
);
}
}
}
}
......
......@@ -253,13 +253,22 @@ function auth_check_password_change() {
'title' => get_string('confirmpassword') . ':',
'description' => get_string('yournewpasswordagain'),
'rules' => array(
'required' => true
)
'required' => true,
),
),
'email' => array(
'type' => 'text',
'title' => get_string('principalemailaddress', 'artefact.internal'),
'ignore' => (trim($USER->get('email')) != '' && !preg_match('/@example\.org$/', $USER->get('email'))),
'rules' => array(
'required' => true,
'email' => true,
),
),
'submit' => array(
'type' => 'submit',
'value' => get_string('changepassword')
)
'value' => get_string('changepassword'),
),
)
);
......@@ -308,7 +317,7 @@ function change_password_submit(Pieform $form, $values) {
$authtype = auth_get_authtype_for_institution($USER->get('institution'));
$authclass = 'Auth' . ucfirst($authtype);
// This method should exists, because if it did not then the change
// This method should exist, because if it did not then the change
// password form would not have been shown.
if ($password = call_static_method($authclass, 'change_password', $USER->get('username'), $values['password1'])) {
$user = new StdClass;
......@@ -320,6 +329,9 @@ function change_password_submit(Pieform $form, $values) {
$USER->set('password', $password);
$USER->set('passwordchange', 0);
$SESSION->add_ok_msg(get_string('passwordsaved'));
if (!empty($values['email'])) {
set_profile_field($USER->get('id'), 'email', $values['email']);
}
redirect();
}
......
......@@ -164,10 +164,26 @@ function expected_account_preferences() {
function set_profile_field($userid, $field, $value) {
safe_require('artefact', 'internal');
$classname = generate_artefact_class_name($field);
$profile = new $classname(0, array('owner' => $userid));
$profile->set('title', $value);
$profile->commit();
// this is a special case that replaces the primary email address with the
// specified one
if ($field == 'email') {
try {
$email = artefact_instance_from_type('email');
}
catch (ArtefactNotFoundException $e) {
$email = new ArtefactTypeEmail();
$email->set('owner', $userid);
}
$email->set('title', $value);
$email->commit();
}
else {
$classname = generate_artefact_class_name($field);
$profile = new $classname(0, array('owner' => $userid));
$profile->set('title', $value);
$profile->commit();
}
}
/**
......@@ -543,8 +559,6 @@ function suspend_user($suspendeduserid, $reason, $suspendinguserid=null) {
function friend_submit($form, $values) {
global $user, $USER;
log_debug($values);
$loggedinid = $USER->get('id');
$userid = $user->id;
......
......@@ -8,6 +8,7 @@
'wwwroot': '{$WWWROOT}'
{literal}}{/literal};
</script>
<script type="text/javascript" src="{$WWWROOT}js/firebug/firebug.js"></script>
{foreach from=$JAVASCRIPT item=script} <script type="text/javascript" src="{$script}"></script>
{/foreach}
{foreach from=$HEADERS item=header} {$header}
......
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