proxy
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { BadRequestException, ConflictException, Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { IsNull, Repository } from 'typeorm';
|
||||
import { In, IsNull, Repository } from 'typeorm';
|
||||
import { AuditService } from '../audit/audit.service';
|
||||
import { assertPasswordPolicy } from '../common/password-policy';
|
||||
import { decryptSecret, encryptSecret, hashToken, randomToken } from '../common/token.util';
|
||||
@@ -26,23 +26,24 @@ export class RegistrationService {
|
||||
|
||||
async register(dto: RegisterDto, ipAddress?: string, userAgent?: string) {
|
||||
assertPasswordPolicy(dto.password);
|
||||
const email = dto.email.toLowerCase();
|
||||
|
||||
const existingLdapUser = await this.lldap.findUserByUsername(dto.username).catch(() => null);
|
||||
const existingLdapUser = await this.lldap.findUserByUsername(email).catch(() => null);
|
||||
if (existingLdapUser) {
|
||||
throw new ConflictException('Der Benutzername ist bereits vergeben.');
|
||||
throw new ConflictException('Diese E-Mail-Adresse ist bereits registriert.');
|
||||
}
|
||||
|
||||
const pending = await this.registrations.findOne({
|
||||
where: { username: dto.username, status: 'pending_email' },
|
||||
where: { username: email, status: 'pending_email' },
|
||||
});
|
||||
if (pending) {
|
||||
throw new ConflictException('Fuer diesen Benutzernamen existiert bereits eine offene Registrierung.');
|
||||
throw new ConflictException('Fuer diese E-Mail-Adresse existiert bereits eine offene Registrierung.');
|
||||
}
|
||||
|
||||
const registration = await this.registrations.save(
|
||||
this.registrations.create({
|
||||
username: dto.username,
|
||||
email: dto.email.toLowerCase(),
|
||||
username: email,
|
||||
email,
|
||||
displayName: dto.displayName,
|
||||
encryptedPassword: encryptSecret(dto.password, this.tokenSecret),
|
||||
status: 'pending_email',
|
||||
@@ -99,7 +100,10 @@ export class RegistrationService {
|
||||
}
|
||||
|
||||
async list() {
|
||||
return this.registrations.find({ order: { createdAt: 'DESC' } });
|
||||
return this.registrations.find({
|
||||
where: { status: In(['pending_email', 'pending_approval']) },
|
||||
order: { createdAt: 'DESC' },
|
||||
});
|
||||
}
|
||||
|
||||
async approve(id: string, reviewer: string, ipAddress?: string, userAgent?: string) {
|
||||
|
||||
Reference in New Issue
Block a user