mirror of
https://github.com/moodle/moodle.git
synced 2025-08-02 15:49:43 +02:00
MDL-64148 oauth2: Make email greetings consistent
Some email body strings use first names as greetings, some use full names, and some do not. Using the first name for greeting makes it consistent and a bit more "personal".
This commit is contained in:
parent
020259dbad
commit
b4f1704321
4 changed files with 59 additions and 5 deletions
|
@ -176,7 +176,10 @@ class api {
|
|||
$user = get_complete_user_data('id', $userid);
|
||||
|
||||
$data = new stdClass();
|
||||
$data->fullname = fullname($user);
|
||||
$placeholders = \core_user::get_name_placeholders($user);
|
||||
foreach ($placeholders as $field => $value) {
|
||||
$data->{$field} = $value;
|
||||
}
|
||||
$data->sitename = format_string($site->fullname);
|
||||
$data->admin = generate_email_signoff();
|
||||
$data->issuername = format_string($issuer->get('name'));
|
||||
|
@ -319,7 +322,10 @@ class api {
|
|||
$user = get_complete_user_data('id', $user->id);
|
||||
|
||||
$data = new stdClass();
|
||||
$data->fullname = fullname($user);
|
||||
$placeholders = \core_user::get_name_placeholders($user);
|
||||
foreach ($placeholders as $field => $value) {
|
||||
$data->{$field} = $value;
|
||||
}
|
||||
$data->sitename = format_string($site->fullname);
|
||||
$data->admin = generate_email_signoff();
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
$string['accountexists'] = 'A user already exists on this site with this username. If this is your account, log in by entering your username and password and add it as a linked login via your preferences page.';
|
||||
$string['auth_oauth2description'] = 'OAuth 2 standards based authentication';
|
||||
$string['auth_oauth2settings'] = 'OAuth 2 authentication settings.';
|
||||
$string['confirmaccountemail'] = 'Hi {$a->fullname},
|
||||
$string['confirmaccountemail'] = 'Hi {$a->firstname},
|
||||
|
||||
A new account has been requested at \'{$a->sitename}\'
|
||||
using your email address.
|
||||
|
@ -47,7 +47,7 @@ Please contact the site administrator immediately.';
|
|||
$string['confirmaccountemailsubject'] = '{$a}: account confirmation';
|
||||
$string['confirmationinvalid'] = 'The confirmation link is either invalid, or has expired. Please start the login process again to generate a new confirmation email.';
|
||||
$string['confirmationpending'] = 'This account is pending email confirmation.';
|
||||
$string['confirmlinkedloginemail'] = 'Hi {$a->fullname},
|
||||
$string['confirmlinkedloginemail'] = 'Hi {$a->firstname},
|
||||
|
||||
A request has been made to link the {$a->issuername} login
|
||||
{$a->linkedemail} to your account at \'{$a->sitename}\'
|
||||
|
|
|
@ -22,6 +22,8 @@ namespace auth_oauth2;
|
|||
* @package auth_oauth2
|
||||
* @copyright 2017 Damyon Wiese
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*
|
||||
* @covers \auth_oauth2\api
|
||||
*/
|
||||
class api_test extends \advanced_testcase {
|
||||
|
||||
|
@ -227,4 +229,39 @@ class api_test extends \advanced_testcase {
|
|||
// Explicitly test the user is not yet confirmed.
|
||||
$this->assertEquals(0, $userdata->confirmed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for checking the email greetings in OAuth2 confirmation emails.
|
||||
*/
|
||||
public function test_email_greetings(): void {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$issuer = \core\oauth2\api::create_standard_issuer('microsoft');
|
||||
|
||||
$userinfo = [];
|
||||
$userinfo['username'] = 'apple';
|
||||
$userinfo['email'] = 'apple@example.com';
|
||||
$userinfo['firstname'] = 'Apple';
|
||||
$userinfo['lastname'] = 'Fruit';
|
||||
$sink = $this->redirectEmails(); // Make sure we are redirecting emails.
|
||||
\auth_oauth2\api::send_confirm_account_email($userinfo, $issuer);
|
||||
$result = $sink->get_messages();
|
||||
$sink->close();
|
||||
// Test greetings.
|
||||
$this->assertStringContainsString('Hi ' . $userinfo['firstname'], quoted_printable_decode($result[0]->body));
|
||||
|
||||
$userinfo = [];
|
||||
$userinfo['username'] = 'banana';
|
||||
$userinfo['email'] = 'banana@example.com';
|
||||
$userinfo['firstname'] = 'Banana';
|
||||
$userinfo['lastname'] = 'Fruit';
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$sink = $this->redirectEmails(); // Make sure we are redirecting emails.
|
||||
\auth_oauth2\api::send_confirm_link_login_email($userinfo, $issuer, $user->id);
|
||||
$result = $sink->get_messages();
|
||||
$sink->close();
|
||||
// Test greetings.
|
||||
$this->assertStringContainsString('Hi ' . $user->firstname, quoted_printable_decode($result[0]->body));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace auth_oauth2;
|
|||
* @category test
|
||||
* @copyright 2019 Shamim Rezaie
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \auth_oauth2\auth
|
||||
* @covers \auth_oauth2\auth
|
||||
*/
|
||||
class auth_test extends \advanced_testcase {
|
||||
|
||||
|
@ -89,4 +89,15 @@ class auth_test extends \advanced_testcase {
|
|||
$extrauserinfo = $event->other['extrauserinfo'];
|
||||
$this->assertEquals($info, $extrauserinfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for checking the email greetings in the password change information email.
|
||||
*/
|
||||
public function test_email_greetings(): void {
|
||||
$this->resetAfterTest();
|
||||
$user = $this->getDataGenerator()->create_user(['auth' => 'oauth2']);
|
||||
$auth = get_auth_plugin($user->auth);
|
||||
$info = $auth->get_password_change_info($user);
|
||||
$this->assertStringContainsString('Hi ' . $user->firstname, quoted_printable_decode($info['message']));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue