mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
Merge pull request #53887 from nextcloud/fix/lower-email-case
This commit is contained in:
commit
1bc1902476
6 changed files with 63 additions and 10 deletions
|
|
@ -142,7 +142,8 @@ abstract class AUserDataOCSController extends OCSController {
|
|||
$additionalEmails = $additionalEmailScopes = [];
|
||||
$emailCollection = $userAccount->getPropertyCollection(IAccountManager::COLLECTION_EMAIL);
|
||||
foreach ($emailCollection->getProperties() as $property) {
|
||||
$additionalEmails[] = $property->getValue();
|
||||
$email = mb_strtolower(trim($property->getValue()));
|
||||
$additionalEmails[] = $email;
|
||||
if ($includeScopes) {
|
||||
$additionalEmailScopes[] = $property->getScope();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -537,6 +537,7 @@ class UsersController extends AUserDataOCSController {
|
|||
$generatePasswordResetToken = true;
|
||||
}
|
||||
|
||||
$email = mb_strtolower(trim($email));
|
||||
if ($email === '' && $this->config->getAppValue('core', 'newUser.requireEmail', 'no') === 'yes') {
|
||||
throw new OCSException($this->l10n->t('Required email address was not provided'), 110);
|
||||
}
|
||||
|
|
@ -583,7 +584,7 @@ class UsersController extends AUserDataOCSController {
|
|||
|
||||
// Send new user mail only if a mail is set
|
||||
if ($email !== '') {
|
||||
$newUser->setEMailAddress($email);
|
||||
$newUser->setSystemEMailAddress($email);
|
||||
if ($this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') {
|
||||
try {
|
||||
$emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken);
|
||||
|
|
@ -857,6 +858,7 @@ class UsersController extends AUserDataOCSController {
|
|||
$mailCollection = $userAccount->getPropertyCollection(IAccountManager::COLLECTION_EMAIL);
|
||||
$mailCollection->removePropertyByValue($key);
|
||||
if ($value !== '') {
|
||||
$value = mb_strtolower(trim($value));
|
||||
$mailCollection->addPropertyWithDefaults($value);
|
||||
$property = $mailCollection->getPropertyByValue($key);
|
||||
if ($isAdminOrSubadmin && $property) {
|
||||
|
|
@ -1142,13 +1144,15 @@ class UsersController extends AUserDataOCSController {
|
|||
}
|
||||
break;
|
||||
case IAccountManager::PROPERTY_EMAIL:
|
||||
$value = mb_strtolower(trim($value));
|
||||
if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') {
|
||||
$targetUser->setEMailAddress($value);
|
||||
$targetUser->setSystemEMailAddress($value);
|
||||
} else {
|
||||
throw new OCSException('', 101);
|
||||
}
|
||||
break;
|
||||
case IAccountManager::COLLECTION_EMAIL:
|
||||
$value = mb_strtolower(trim($value));
|
||||
if (filter_var($value, FILTER_VALIDATE_EMAIL) && $value !== $targetUser->getSystemEMailAddress()) {
|
||||
$userAccount = $this->accountManager->getAccount($targetUser);
|
||||
$mailCollection = $userAccount->getPropertyCollection(IAccountManager::COLLECTION_EMAIL);
|
||||
|
|
|
|||
|
|
@ -609,7 +609,7 @@ class UsersControllerTest extends TestCase {
|
|||
->willReturn(false);
|
||||
$newUser = $this->createMock(IUser::class);
|
||||
$newUser->expects($this->once())
|
||||
->method('setEMailAddress');
|
||||
->method('setSystemEMailAddress');
|
||||
$this->userManager
|
||||
->expects($this->once())
|
||||
->method('createUser')
|
||||
|
|
@ -645,6 +645,51 @@ class UsersControllerTest extends TestCase {
|
|||
));
|
||||
}
|
||||
|
||||
public function testAddUserSuccessfulLowercaseEmail(): void {
|
||||
$this->userManager
|
||||
->expects($this->once())
|
||||
->method('userExists')
|
||||
->with('NewUser')
|
||||
->willReturn(false);
|
||||
$newUser = $this->createMock(IUser::class);
|
||||
$newUser->expects($this->once())
|
||||
->method('setSystemEMailAddress')
|
||||
->with('foo@bar.com');
|
||||
$this->userManager
|
||||
->expects($this->once())
|
||||
->method('createUser')
|
||||
->willReturn($newUser);
|
||||
$this->logger
|
||||
->expects($this->once())
|
||||
->method('info')
|
||||
->with('Successful addUser call with userid: NewUser', ['app' => 'ocs_api']);
|
||||
$loggedInUser = $this->getMockBuilder(IUser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$loggedInUser
|
||||
->expects($this->exactly(2))
|
||||
->method('getUID')
|
||||
->willReturn('adminUser');
|
||||
$this->userSession
|
||||
->expects($this->once())
|
||||
->method('getUser')
|
||||
->willReturn($loggedInUser);
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('isAdmin')
|
||||
->with('adminUser')
|
||||
->willReturn(true);
|
||||
$this->eventDispatcher
|
||||
->expects($this->once())
|
||||
->method('dispatchTyped')
|
||||
->with(new GenerateSecurePasswordEvent());
|
||||
|
||||
$this->assertTrue(key_exists(
|
||||
'id',
|
||||
$this->api->addUser('NewUser', '', '', 'fOo@BaR.CoM')->getData()
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public function testAddUserFailedToGenerateUserID(): void {
|
||||
$this->expectException(OCSException::class);
|
||||
|
|
@ -1629,7 +1674,7 @@ class UsersControllerTest extends TestCase {
|
|||
->willReturn($targetUser);
|
||||
$targetUser
|
||||
->expects($this->once())
|
||||
->method('setEMailAddress')
|
||||
->method('setSystemEMailAddress')
|
||||
->with('demo@nextcloud.com');
|
||||
$targetUser
|
||||
->expects($this->any())
|
||||
|
|
|
|||
|
|
@ -1991,8 +1991,6 @@
|
|||
<code><![CDATA[implementsActions]]></code>
|
||||
<code><![CDATA[implementsActions]]></code>
|
||||
<code><![CDATA[implementsActions]]></code>
|
||||
<code><![CDATA[setEMailAddress]]></code>
|
||||
<code><![CDATA[setEMailAddress]]></code>
|
||||
</DeprecatedMethod>
|
||||
<TypeDoesNotContainNull>
|
||||
<code><![CDATA[$groupid === null]]></code>
|
||||
|
|
|
|||
|
|
@ -155,7 +155,8 @@ class Setting extends Base {
|
|||
$user = $this->userManager->get($uid);
|
||||
if ($user instanceof IUser) {
|
||||
if ($key === 'email') {
|
||||
$user->setEMailAddress($input->getArgument('value'));
|
||||
$email = $input->getArgument('value');
|
||||
$user->setSystemEMailAddress(mb_strtolower(trim($email)));
|
||||
} elseif ($key === 'display_name') {
|
||||
if (!$user->setDisplayName($input->getArgument('value'))) {
|
||||
if ($user->getDisplayName() === $input->getArgument('value')) {
|
||||
|
|
|
|||
|
|
@ -154,6 +154,7 @@ class User implements IUser {
|
|||
*/
|
||||
public function setSystemEMailAddress(string $mailAddress): void {
|
||||
$oldMailAddress = $this->getSystemEMailAddress();
|
||||
$mailAddress = mb_strtolower(trim($mailAddress));
|
||||
|
||||
if ($mailAddress === '') {
|
||||
$this->config->deleteUserValue($this->uid, 'settings', 'email');
|
||||
|
|
@ -176,6 +177,7 @@ class User implements IUser {
|
|||
* @inheritDoc
|
||||
*/
|
||||
public function setPrimaryEMailAddress(string $mailAddress): void {
|
||||
$mailAddress = mb_strtolower(trim($mailAddress));
|
||||
if ($mailAddress === '') {
|
||||
$this->config->deleteUserValue($this->uid, 'settings', 'primary_email');
|
||||
return;
|
||||
|
|
@ -514,14 +516,16 @@ class User implements IUser {
|
|||
* @inheritDoc
|
||||
*/
|
||||
public function getSystemEMailAddress(): ?string {
|
||||
return $this->config->getUserValue($this->uid, 'settings', 'email', null);
|
||||
$email = $this->config->getUserValue($this->uid, 'settings', 'email', null);
|
||||
return $email ? mb_strtolower(trim($email)) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getPrimaryEMailAddress(): ?string {
|
||||
return $this->config->getUserValue($this->uid, 'settings', 'primary_email', null);
|
||||
$email = $this->config->getUserValue($this->uid, 'settings', 'primary_email', null);
|
||||
return $email ? mb_strtolower(trim($email)) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue