Added logic to confirm privacy before registration #251

This commit is contained in:
Sven Heidemann 2023-03-17 14:43:16 +01:00
parent 4420c0e11c
commit cc0a0a5c69
15 changed files with 830 additions and 8870 deletions

View File

@ -483,18 +483,19 @@ class AuthService(AuthServiceABC):
if user_dto is None: if user_dto is None:
raise ServiceException(ServiceErrorCode.InvalidData, "User not set") raise ServiceException(ServiceErrorCode.InvalidData, "User not set")
members = self._users.get_users_by_discord_id(dc_id)
if members.count() == 0:
raise ServiceException(ServiceErrorCode.InvalidUser, f"Member not found")
added_user = False added_user = False
db_user = self._auth_users.find_auth_user_by_email(user_dto.email) db_user = self._auth_users.find_auth_user_by_email(user_dto.email)
if db_user is None: if db_user is None:
self.add_auth_user(user_dto) self.add_auth_user(user_dto)
added_user = True added_user = True
# raise ServiceException(ServiceErrorCode.InvalidUser, f'User not found')
db_user = self._auth_users.get_auth_user_by_email(user_dto.email) db_user = self._auth_users.get_auth_user_by_email(user_dto.email)
if db_user.users.count() == 0: if db_user.users.count() == 0:
self._users.get_users_by_discord_id(dc_id).for_each( members.for_each(lambda x: self._auth_users.add_auth_user_user_rel(AuthUserUsersRelation(db_user, x)))
lambda x: self._auth_users.add_auth_user_user_rel(AuthUserUsersRelation(db_user, x))
)
if db_user.confirmation_id is not None and not added_user: if db_user.confirmation_id is not None and not added_user:
raise ServiceException(ServiceErrorCode.Forbidden, "E-Mail not verified") raise ServiceException(ServiceErrorCode.Forbidden, "E-Mail not verified")

9562
kdb-web/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "kdb-web", "name": "kdb-web",
"version": "1.0.0.rc2", "version": "1.0.dev251",
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"update-version": "ts-node-esm update-version.ts", "update-version": "ts-node-esm update-version.ts",

View File

@ -53,9 +53,9 @@ export class AppComponent implements OnInit, OnDestroy {
this.socket.startSocket(); this.socket.startSocket();
} }
ngOnDestroy() { public ngOnDestroy(): void {
this.unsubscriber.next(); this.unsubscriber.next();
this.unsubscriber.unsubscribe(); this.unsubscriber.complete();
} }
loadLang(): void { loadLang(): void {

View File

@ -1,4 +1,4 @@
import { Component, OnInit } from "@angular/core"; import { Component, OnDestroy, OnInit } from "@angular/core";
import { catchError, debounceTime, takeUntil } from "rxjs/operators"; import { catchError, debounceTime, takeUntil } from "rxjs/operators";
import { AuthRoles } from "src/app/models/auth/auth-roles.enum"; import { AuthRoles } from "src/app/models/auth/auth-roles.enum";
import { AuthUserDTO } from "src/app/models/auth/auth-user.dto"; import { AuthUserDTO } from "src/app/models/auth/auth-user.dto";
@ -22,7 +22,7 @@ import { TranslateService } from "@ngx-translate/core";
templateUrl: "./auth-user.component.html", templateUrl: "./auth-user.component.html",
styleUrls: ["./auth-user.component.scss"] styleUrls: ["./auth-user.component.scss"]
}) })
export class AuthUserComponent implements OnInit { export class AuthUserComponent implements OnInit, OnDestroy {
users!: AuthUserDTO[]; users!: AuthUserDTO[];
statuses!: any[]; statuses!: any[];
@ -62,7 +62,7 @@ export class AuthUserComponent implements OnInit {
searchCriterions!: AuthUserSelectCriterion; searchCriterions!: AuthUserSelectCriterion;
totalRecords!: number; totalRecords!: number;
private unsubscriber = new Subject(); private unsubscriber = new Subject<void>();
constructor( constructor(
private authService: AuthService, private authService: AuthService,
@ -91,6 +91,11 @@ export class AuthUserComponent implements OnInit {
this.loadNextPage(); this.loadNextPage();
} }
public ngOnDestroy(): void {
this.unsubscriber.next();
this.unsubscriber.complete();
}
setFilterForm() { setFilterForm() {
this.filterForm = this.fb.group({ this.filterForm = this.fb.group({
firstName: [""], firstName: [""],

View File

@ -1,15 +1,14 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from "@angular/core";
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FormBuilder, FormGroup, Validators } from "@angular/forms";
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from "@ngx-translate/core";
import { catchError } from 'rxjs/operators'; import { catchError } from "rxjs/operators";
import { SettingsDTO } from 'src/app/models/config/settings.dto'; import { SettingsDTO } from "src/app/models/config/settings.dto";
import { ErrorDTO } from 'src/app/models/error/error-dto'; import { ErrorDTO } from "src/app/models/error/error-dto";
import { ServiceErrorCode } from 'src/app/models/error/service-error-code.enum'; import { ServiceErrorCode } from "src/app/models/error/service-error-code.enum";
import { AuthService } from 'src/app/services/auth/auth.service'; import { GuiService } from "src/app/services/gui/gui.service";
import { GuiService } from 'src/app/services/gui/gui.service'; import { SettingsService } from "src/app/services/settings/settings.service";
import { SettingsService } from 'src/app/services/settings/settings.service'; import { SpinnerService } from "src/app/services/spinner/spinner.service";
import { SpinnerService } from 'src/app/services/spinner/spinner.service'; import { ToastService } from "src/app/services/toast/toast.service";
import { ToastService } from 'src/app/services/toast/toast.service';
import { throwError } from "rxjs"; import { throwError } from "rxjs";
@Component({ @Component({

View File

@ -67,11 +67,16 @@
</div> </div>
</div> </div>
<div class="input-field">
<p-checkbox id="confirmPrivacyCheckbox" [binary]="true" formControlName="confirmPrivacy"></p-checkbox>
&nbsp;
<label for="confirmPrivacyCheckbox" [innerHTML]="confirmPrivacyString"></label>
</div>
<div class="login-form-submit"> <div class="login-form-submit">
<button pButton label="{{'auth.register.register' | translate}}" class="btn login-form-submit-btn" (click)="register()" <button pButton label="{{'auth.register.register' | translate}}" class="btn login-form-submit-btn" (click)="register()"
[disabled]="loginForm.invalid"></button> [disabled]="loginForm.invalid"></button>
</div> </div>
<div class="login-form-sub-button-wrapper"> <div class="login-form-sub-button-wrapper">
<div class="login-form-sub-btn-wrapper"> <div class="login-form-sub-btn-wrapper">
<button pButton label="{{'auth.register.login' | translate}}" class="btn login-form-sub-btn" (click)="login()"></button> <button pButton label="{{'auth.register.login' | translate}}" class="btn login-form-sub-btn" (click)="login()"></button>

View File

@ -1,7 +1,7 @@
import { Component, OnInit } from "@angular/core"; import { Component, OnDestroy, OnInit } from "@angular/core";
import { FormBuilder, FormControl, FormGroup, Validators } from "@angular/forms"; import { FormBuilder, FormControl, FormGroup, Validators } from "@angular/forms";
import { ActivatedRoute, Router } from "@angular/router"; import { ActivatedRoute, Router } from "@angular/router";
import { catchError, finalize } from "rxjs/operators"; import { catchError, takeUntil } from "rxjs/operators";
import { AuthErrorMessages } from "src/app/models/auth/auth-error-messages.enum"; import { AuthErrorMessages } from "src/app/models/auth/auth-error-messages.enum";
import { AuthUserDTO } from "src/app/models/auth/auth-user.dto"; import { AuthUserDTO } from "src/app/models/auth/auth-user.dto";
import { AuthUserAtrErrors } from "src/app/models/auth/auth-user-atr-errors"; import { AuthUserAtrErrors } from "src/app/models/auth/auth-user-atr-errors";
@ -9,15 +9,16 @@ import { ErrorDTO } from "src/app/models/error/error-dto";
import { ServiceErrorCode } from "src/app/models/error/service-error-code.enum"; import { ServiceErrorCode } from "src/app/models/error/service-error-code.enum";
import { AuthService } from "src/app/services/auth/auth.service"; import { AuthService } from "src/app/services/auth/auth.service";
import { SpinnerService } from "src/app/services/spinner/spinner.service"; import { SpinnerService } from "src/app/services/spinner/spinner.service";
import { throwError } from "rxjs"; import { Subject, throwError } from "rxjs";
import { OAuthDTO } from "../../../../models/auth/oauth.dto"; import { TranslateService } from "@ngx-translate/core";
import { SettingsService } from "../../../../services/settings/settings.service";
@Component({ @Component({
selector: "app-registration", selector: "app-registration",
templateUrl: "./registration.component.html", templateUrl: "./registration.component.html",
styleUrls: ["./registration.component.scss"] styleUrls: ["./registration.component.scss"]
}) })
export class RegistrationComponent implements OnInit { export class RegistrationComponent implements OnInit, OnDestroy {
loginForm!: FormGroup<{ loginForm!: FormGroup<{
firstName: FormControl<string | null>, firstName: FormControl<string | null>,
@ -25,7 +26,8 @@ export class RegistrationComponent implements OnInit {
email: FormControl<string | null>, email: FormControl<string | null>,
emailRepeat: FormControl<string | null>, emailRepeat: FormControl<string | null>,
password: FormControl<string | null>, password: FormControl<string | null>,
passwordRepeat: FormControl<string | null> passwordRepeat: FormControl<string | null>,
confirmPrivacy: FormControl<boolean | null>
}>; }>;
submitted = false; submitted = false;
authUserAtrErrors!: AuthUserAtrErrors; authUserAtrErrors!: AuthUserAtrErrors;
@ -34,12 +36,17 @@ export class RegistrationComponent implements OnInit {
password: false password: false
}; };
public confirmPrivacyString: string = "";
private unsubscriber = new Subject<void>();
constructor( constructor(
private authService: AuthService, private authService: AuthService,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private router: Router, private router: Router,
private spinnerService: SpinnerService, private spinnerService: SpinnerService,
private route: ActivatedRoute private route: ActivatedRoute,
private translate: TranslateService,
private settings: SettingsService
) { ) {
this.spinnerService.showSpinner(); this.spinnerService.showSpinner();
this.authService.isUserLoggedInAsync().then(res => { this.authService.isUserLoggedInAsync().then(res => {
@ -51,12 +58,22 @@ export class RegistrationComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.translate.onLangChange.pipe(takeUntil(this.unsubscriber)).subscribe(lang => {
this.confirmPrivacyString = this.translate.instant("auth.register.confirm_privacy", { url: this.settings.getPrivacyURL() });
});
this.confirmEMail(); this.confirmEMail();
this.initData();
this.spinnerService.showSpinner(); this.spinnerService.showSpinner();
this.initData(); this.initData();
} }
public ngOnDestroy(): void {
this.unsubscriber.next();
this.unsubscriber.complete();
}
initData() { initData() {
this.initLoginForm(); this.initLoginForm();
this.resetStateFlags(); this.resetStateFlags();
@ -82,7 +99,8 @@ export class RegistrationComponent implements OnInit {
email: ["", [Validators.required, Validators.email]], email: ["", [Validators.required, Validators.email]],
emailRepeat: ["", [Validators.required, Validators.email]], emailRepeat: ["", [Validators.required, Validators.email]],
password: ["", [Validators.required, Validators.minLength(8)]], password: ["", [Validators.required, Validators.minLength(8)]],
passwordRepeat: ["", [Validators.required, Validators.minLength(8)]] passwordRepeat: ["", [Validators.required, Validators.minLength(8)]],
confirmPrivacy: [false, [Validators.required, Validators.requiredTrue]]
}); });
} }
@ -143,7 +161,7 @@ export class RegistrationComponent implements OnInit {
.pipe(catchError(error => { .pipe(catchError(error => {
this.router.navigate(["/auth/login"]); this.router.navigate(["/auth/login"]);
this.spinnerService.hideSpinner(); this.spinnerService.hideSpinner();
return throwError(() => error); return throwError(() => error);
})) }))
.subscribe(resp => { .subscribe(resp => {
this.spinnerService.hideSpinner(); this.spinnerService.hideSpinner();
@ -151,4 +169,8 @@ export class RegistrationComponent implements OnInit {
}); });
} }
} }
log($event: Event): void {
console.log($event);
}
} }

View File

@ -60,7 +60,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
this.loadNextPage(); this.loadNextPage();
} }
public ngOnDestroy() { public ngOnDestroy(): void {
this.unsubscriber.next(); this.unsubscriber.next();
this.unsubscriber.complete(); this.unsubscriber.complete();
} }

View File

@ -1,4 +1,4 @@
import { Component, OnInit } from "@angular/core"; import { Component, OnDestroy, OnInit } from "@angular/core";
import { DataService } from "../../../../../../services/data/data.service"; import { DataService } from "../../../../../../services/data/data.service";
import { ActivatedRoute, Router } from "@angular/router"; import { ActivatedRoute, Router } from "@angular/router";
import { AutoRoleRule, AutoRoleRuleFilter } from "../../../../../../models/data/auto_role.model"; import { AutoRoleRule, AutoRoleRuleFilter } from "../../../../../../models/data/auto_role.model";
@ -28,7 +28,7 @@ import { Subject, throwError } from "rxjs";
templateUrl: "./auto-roles-rules.component.html", templateUrl: "./auto-roles-rules.component.html",
styleUrls: ["./auto-roles-rules.component.scss"] styleUrls: ["./auto-roles-rules.component.scss"]
}) })
export class AutoRolesRulesComponent implements OnInit { export class AutoRolesRulesComponent implements OnInit, OnDestroy {
rules: AutoRoleRule[] = []; rules: AutoRoleRule[] = [];
guild: Guild = { channels: [], emojis: [], roles: [] }; guild: Guild = { channels: [], emojis: [], roles: [] };
@ -85,7 +85,6 @@ export class AutoRolesRulesComponent implements OnInit {
} }
public ngOnInit(): void { public ngOnInit(): void {
this.setFilterForm(); this.setFilterForm();
this.data.getServerFromRoute(this.route).then(server => { this.data.getServerFromRoute(this.route).then(server => {
this.server = server; this.server = server;
@ -119,6 +118,11 @@ export class AutoRolesRulesComponent implements OnInit {
}); });
} }
public ngOnDestroy(): void {
this.unsubscriber.next();
this.unsubscriber.complete();
}
public loadNextPage(): void { public loadNextPage(): void {
this.loading = true; this.loading = true;
this.data.query<AutoRoleRuleQuery>(Queries.autoRoleRulesQuery, { this.data.query<AutoRoleRuleQuery>(Queries.autoRoleRulesQuery, {

View File

@ -1,4 +1,4 @@
import { Component, OnInit } from "@angular/core"; import { Component, OnDestroy, OnInit } from "@angular/core";
import { User } from "../../../../../../models/data/user.model"; import { User } from "../../../../../../models/data/user.model";
import { LazyLoadEvent, MenuItem } from "primeng/api"; import { LazyLoadEvent, MenuItem } from "primeng/api";
import { FormBuilder, FormControl, FormGroup } from "@angular/forms"; import { FormBuilder, FormControl, FormGroup } from "@angular/forms";
@ -28,7 +28,7 @@ import { Server } from "../../../../../../models/data/server.model";
templateUrl: "./auto-roles.component.html", templateUrl: "./auto-roles.component.html",
styleUrls: ["./auto-roles.component.scss"] styleUrls: ["./auto-roles.component.scss"]
}) })
export class AutoRolesComponent implements OnInit { export class AutoRolesComponent implements OnInit, OnDestroy {
auto_roles: AutoRole[] = []; auto_roles: AutoRole[] = [];
guild: Guild = { channels: [], emojis: [], roles: [] }; guild: Guild = { channels: [], emojis: [], roles: [] };
channels: MenuItem[] = []; channels: MenuItem[] = [];
@ -100,6 +100,12 @@ export class AutoRolesComponent implements OnInit {
}); });
} }
public ngOnDestroy(): void {
this.unsubscriber.next();
this.unsubscriber.complete();
}
public loadNextPage(): void { public loadNextPage(): void {
this.loading = true; this.loading = true;
this.data.query<AutoRoleQuery>(Queries.autoRolesQuery, { this.data.query<AutoRoleQuery>(Queries.autoRolesQuery, {

View File

@ -1,4 +1,4 @@
import { Component, OnInit } from "@angular/core"; import { Component, OnDestroy, OnInit } from "@angular/core";
import { FormBuilder, FormControl, FormGroup } from "@angular/forms"; import { FormBuilder, FormControl, FormGroup } from "@angular/forms";
import { AuthService } from "../../../../services/auth/auth.service"; import { AuthService } from "../../../../services/auth/auth.service";
import { SpinnerService } from "../../../../services/spinner/spinner.service"; import { SpinnerService } from "../../../../services/spinner/spinner.service";
@ -26,7 +26,7 @@ import { Server } from "../../../../models/data/server.model";
templateUrl: "./members.component.html", templateUrl: "./members.component.html",
styleUrls: ["./members.component.scss"] styleUrls: ["./members.component.scss"]
}) })
export class MembersComponent implements OnInit { export class MembersComponent implements OnInit, OnDestroy {
members!: User[]; members!: User[];
levels!: MenuItem[]; levels!: MenuItem[];
leftServerOptions = [ leftServerOptions = [
@ -114,6 +114,10 @@ export class MembersComponent implements OnInit {
this.loadNextPage(); this.loadNextPage();
}); });
} }
public ngOnDestroy(): void {
this.unsubscriber.next();
this.unsubscriber.complete();
}
loadNextPage() { loadNextPage() {
this.spinner.showSpinner(); this.spinner.showSpinner();

View File

@ -5,7 +5,7 @@
"WebVersion": { "WebVersion": {
"Major": "1", "Major": "1",
"Minor": "0", "Minor": "0",
"Micro": "0.rc2" "Micro": "dev251"
}, },
"Themes": [ "Themes": [
{ {

View File

@ -113,7 +113,8 @@
"register_with_discord": "Mit Discord Registrieren", "register_with_discord": "Mit Discord Registrieren",
"repeat_email": "E-Mail wiederholen", "repeat_email": "E-Mail wiederholen",
"repeat_password": "Passwort wiederholen", "repeat_password": "Passwort wiederholen",
"user_already_exists": "Benutzer existiert bereits" "user_already_exists": "Benutzer existiert bereits",
"confirm_privacy": "Ich erkläre mich mit der <a href=\"{{url}}\">Datenschutzerklärung</a> einverstanden."
} }
}, },
"common": { "common": {

View File

@ -113,7 +113,8 @@
"register_with_discord": "Register with discord", "register_with_discord": "Register with discord",
"repeat_email": "Repeat E-mail", "repeat_email": "Repeat E-mail",
"repeat_password": "Repeat password", "repeat_password": "Repeat password",
"user_already_exists": "User already exists" "user_already_exists": "User already exists",
"confirm_privacy": "I agree to the <a href=\"{{url}}\">Privacy Policy</a>."
} }
}, },
"common": { "common": {