mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
@@ -39,13 +39,19 @@ export class UsersService extends ItemsService {
|
||||
* User email has to be unique case-insensitive. This is an additional check to make sure that
|
||||
* the email is unique regardless of casing
|
||||
*/
|
||||
private async checkUniqueEmails(emails: string[]) {
|
||||
private async checkUniqueEmails(emails: string[], excludeKey?: PrimaryKey) {
|
||||
if (emails.length > 0) {
|
||||
const results = await this.knex
|
||||
const query = this.knex
|
||||
.select('email')
|
||||
.from('directus_users')
|
||||
.whereRaw(`LOWER(??) IN (${emails.map(() => '?')})`, ['email', ...emails]);
|
||||
|
||||
if (excludeKey) {
|
||||
query.whereNot('id', excludeKey);
|
||||
}
|
||||
|
||||
const results = await query;
|
||||
|
||||
if (results.length > 0) {
|
||||
throw new RecordNotUniqueException('email', {
|
||||
collection: 'directus_users',
|
||||
@@ -125,7 +131,7 @@ export class UsersService extends ItemsService {
|
||||
const email = data.email?.toLowerCase();
|
||||
|
||||
if (email) {
|
||||
await this.checkUniqueEmails([email]);
|
||||
await this.checkUniqueEmails([email], key);
|
||||
}
|
||||
|
||||
if (data.password) {
|
||||
|
||||
Reference in New Issue
Block a user