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

Admin amail changing at install time

parent 490df230
...@@ -394,21 +394,38 @@ class ArtefactTypeEmail extends ArtefactTypeProfileField { ...@@ -394,21 +394,38 @@ class ArtefactTypeEmail extends ArtefactTypeProfileField {
parent::commit(); parent::commit();
$email_record = get_record('artefact_internal_profile_email', 'owner', $this->owner, 'email', $this->title); $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) { if(!$email_record) {
$principal = get_record('artefact_internal_profile_email', 'owner', $this->owner, 'principal', 1); if (record_exists('artefact_internal_profile_email', 'owner', $this->owner, 'artefact', $this->id)) {
update_record(
insert_record( 'artefact_internal_profile_email',
'artefact_internal_profile_email', (object) array(
(object) array( 'email' => $this->title,
'owner' => $this->owner, 'verified' => 1,
'email' => $this->title, ),
'verified' => 1, (object) array(
'principal' => ( $principal ? 0 : 1 ), 'owner' => $this->owner,
'artefact' => $this->id, '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() { ...@@ -253,13 +253,22 @@ function auth_check_password_change() {
'title' => get_string('confirmpassword') . ':', 'title' => get_string('confirmpassword') . ':',
'description' => get_string('yournewpasswordagain'), 'description' => get_string('yournewpasswordagain'),
'rules' => array( '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( 'submit' => array(
'type' => 'submit', 'type' => 'submit',
'value' => get_string('changepassword') 'value' => get_string('changepassword'),
) ),
) )
); );
...@@ -308,7 +317,7 @@ function change_password_submit(Pieform $form, $values) { ...@@ -308,7 +317,7 @@ function change_password_submit(Pieform $form, $values) {
$authtype = auth_get_authtype_for_institution($USER->get('institution')); $authtype = auth_get_authtype_for_institution($USER->get('institution'));
$authclass = 'Auth' . ucfirst($authtype); $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. // password form would not have been shown.
if ($password = call_static_method($authclass, 'change_password', $USER->get('username'), $values['password1'])) { if ($password = call_static_method($authclass, 'change_password', $USER->get('username'), $values['password1'])) {
$user = new StdClass; $user = new StdClass;
...@@ -320,6 +329,9 @@ function change_password_submit(Pieform $form, $values) { ...@@ -320,6 +329,9 @@ function change_password_submit(Pieform $form, $values) {
$USER->set('password', $password); $USER->set('password', $password);
$USER->set('passwordchange', 0); $USER->set('passwordchange', 0);
$SESSION->add_ok_msg(get_string('passwordsaved')); $SESSION->add_ok_msg(get_string('passwordsaved'));
if (!empty($values['email'])) {
set_profile_field($USER->get('id'), 'email', $values['email']);
}
redirect(); redirect();
} }
......
...@@ -164,10 +164,26 @@ function expected_account_preferences() { ...@@ -164,10 +164,26 @@ function expected_account_preferences() {
function set_profile_field($userid, $field, $value) { function set_profile_field($userid, $field, $value) {
safe_require('artefact', 'internal'); safe_require('artefact', 'internal');
$classname = generate_artefact_class_name($field);
$profile = new $classname(0, array('owner' => $userid)); // this is a special case that replaces the primary email address with the
$profile->set('title', $value); // specified one
$profile->commit(); 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) { ...@@ -543,8 +559,6 @@ function suspend_user($suspendeduserid, $reason, $suspendinguserid=null) {
function friend_submit($form, $values) { function friend_submit($form, $values) {
global $user, $USER; global $user, $USER;
log_debug($values);
$loggedinid = $USER->get('id'); $loggedinid = $USER->get('id');
$userid = $user->id; $userid = $user->id;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
'wwwroot': '{$WWWROOT}' 'wwwroot': '{$WWWROOT}'
{literal}}{/literal}; {literal}}{/literal};
</script> </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 from=$JAVASCRIPT item=script} <script type="text/javascript" src="{$script}"></script>
{/foreach} {/foreach}
{foreach from=$HEADERS item=header} {$header} {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