Add students registration endpoint

Fix issues when registering
This commit is contained in:
Artur Savitskiy 2024-04-30 16:44:28 +02:00
parent ce25e4e6d0
commit c485b12c61
8 changed files with 124 additions and 52 deletions

View File

@ -27,18 +27,20 @@
$phone = escape($connection, $_POST["phone"]); $phone = escape($connection, $_POST["phone"]);
$email = escape($connection, $_POST["email"]); $email = escape($connection, $_POST["email"]);
$accountHolder = escape($connection, $_POST["accountHolder"]); $accountholder = escape($connection, $_POST["accountHolder"]);
$iban = escape($connection, $_POST["iban"]); $iban = escape($connection, $_POST["iban"]);
$bic = escape($connection, $_POST["bic"]); $bic = escape($connection, $_POST["bic"]);
$bank = escape($connection, $_POST["bank"]); $bank = escape($connection, $_POST["bank"]);
$applicationConsent = intval($_POST["applicationConsent"]); $applicationconsent = $_POST["applicationConsent"] === "true";
$dataChangeConsent = intval($_POST["dataChangeConsent"]); $datachangeconsent = $_POST["dataChangeConsent"] === "true";
$privacyPolicyConsent = intval($_POST["privacyPolicyConsent"]); $privacypolicyconsent = $_POST["privacyPolicyConsent"] === "true";
$directDebitConsent = intval($_POST["directDebitConsent"]); $directdebitconsent = $_POST["directDebitConsent"] === "true";
$returnDebitConsent = intval($_POST["returnDebitConsent"]); $returndebitconsent = $_POST["returnDebitConsent"] === "true";
$dataStorageConsent = intval($_POST["dataStorageConsent"]); $datastorageconsent = $_POST["dataStorageConsent"] === "true";
$multimediaConsent = intval($_POST["multimediaConsent"]); $multimediaconsent = $_POST["multimediaConsent"] === "true";
$registrationfrom = registrationDate()->format('Y-m-d');
$querystr = "SELECT * FROM li_registrations $querystr = "SELECT * FROM li_registrations
WHERE li_registrations.rid = ${rid}"; WHERE li_registrations.rid = ${rid}";
@ -50,18 +52,20 @@
zip='${zip}', city='${city}', phone='${phone}', email='${email}', zip='${zip}', city='${city}', phone='${phone}', email='${email}',
accountholder='${accountHolder}', iban='${iban}', bic='${bic}', bank='${bank}', accountholder='${accountHolder}', iban='${iban}', bic='${bic}', bank='${bank}',
applicationconsent=${applicationconsent}, datachangeconsent=${datachangeconsent}, privacypolicyconsent=${privacypolicyconsent}, applicationconsent=${applicationconsent}, datachangeconsent=${datachangeconsent}, privacypolicyconsent=${privacypolicyconsent},
returndebitconsent=${returndebitconsent}, datastorageconsent=${datastorageconsent}, multimediaconsent=${multimediaconsent}, directdebitconsent=${directdebitconsent}, returndebitconsent=${returndebitconsent}, datastorageconsent=${datastorageconsent}, multimediaconsent=${multimediaconsent},
WHERE rid=${rid}"; WHERE rid=${rid}";
} else { } else {
$querystr = "INSERT INTO li_registrations (firstname, lastname, birthday, gender, street, house, zip, city, phone, email, $querystr = "INSERT INTO li_registrations (firstname, lastname, birthday, gender, street, house, zip, city, phone, email,
accountholder, iban, bic, bank, accountholder, iban, bic, bank,
applicationconsent, datachangeconsent, privacypolicyconsent, applicationconsent, datachangeconsent, privacypolicyconsent, directdebitconsent,
returndebitconsent, datastorageconsent, multimediaconsent) returndebitconsent, datastorageconsent, multimediaconsent, registrationfrom)
VALUES('{$firstname}', '{$lastname}', '{$birthday}', {$gender}, '{$street}', {$house}, '{$house_suffix}', '{$zip}', '{$city}', '{$phone}', '{$email}'. VALUES('{$firstname}', '{$lastname}', '{$birthday}', {$gender}, '{$street}', {$house}, '{$zip}', '{$city}', '{$phone}', '{$email}',
'${accountHolder}', '${iban}', '${bic}', '${bank}', '{$accountholder}', '{$iban}', '{$bic}', '{$bank}',
${applicationconsent}, ${datachangeconsent}, ${privacypolicyconsent}, {$applicationconsent}, {$datachangeconsent}, {$privacypolicyconsent}, {$directdebitconsent},
${returndebitconsent}, ${datastorageconsent}, ${multimediaconsent})"; {$returndebitconsent}, {$datastorageconsent}, {$multimediaconsent}, '{$registrationfrom}')";
echo json_encode('{ "result": "' . $querystr . '" }');
} }
$result = mysqli_query($connection, $querystr); $result = mysqli_query($connection, $querystr);

View File

@ -43,4 +43,20 @@ function login( $token ) {
return ($expectedToken === $token); return ($expectedToken === $token);
} }
function registrationDate() {
$today = new DateTime();
$currentYear = $today->format('Y');
$currentMonth = $today->format('m');
$currentDate = $today->format('d');
if ($currentDate === 1) {
return new DateTime("$currentYear-$currentMonth-01"); // Today is the 1st of the month.
} elseif ($currentDate <= 20) {
return new DateTime("$currentYear-$currentMonth-15"); // Return the 15th of the current month.
} else {
$nextMonth = $today->modify('first day of next month'); // Advance to the first day of the next month.
return $nextMonth;
}
}
?> ?>

View File

@ -28,15 +28,15 @@
<mat-label>Geburtstag</mat-label> <mat-label>Geburtstag</mat-label>
<input <input
matInput matInput
[matDatepicker]="birthdatePicker" [matDatepicker]="birthdayPicker"
formControlName="birthdate" formControlName="birthday"
placeholder="DD.MM.YYYY" placeholder="DD.MM.YYYY"
required /> required />
<mat-datepicker-toggle <mat-datepicker-toggle
matSuffix matSuffix
[for]="birthdatePicker"></mat-datepicker-toggle> [for]="birthdayPicker"></mat-datepicker-toggle>
<mat-datepicker <mat-datepicker
#birthdatePicker #birthdayPicker
startView="multi-year"></mat-datepicker> startView="multi-year"></mat-datepicker>
</mat-form-field> </mat-form-field>
@ -67,7 +67,7 @@
<mat-form-field appearance="fill"> <mat-form-field appearance="fill">
<mat-label>Postleitzahl</mat-label> <mat-label>Postleitzahl</mat-label>
<input matInput formControlName="postalCode" required /> <input matInput formControlName="zip" required />
</mat-form-field> </mat-form-field>
<mat-form-field appearance="fill"> <mat-form-field appearance="fill">
@ -81,6 +81,9 @@
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>
<div class="flexContainerColumn whitebox big">
<p>Sie melden sich zum {{registrationDate | date:'dd.MM.yyyy' }} an</p>
</div>
<div class="flexContainerColumn whitebox"> <div class="flexContainerColumn whitebox">
<mat-checkbox formControlName="applicationConsent" required><span [innerHTML]="infoTextAufnahme"></span></mat-checkbox> <mat-checkbox formControlName="applicationConsent" required><span [innerHTML]="infoTextAufnahme"></span></mat-checkbox>
<br style="margin-bottom: 20px;"> <br style="margin-bottom: 20px;">
@ -123,7 +126,7 @@
<mat-form-field appearance="fill"> <mat-form-field appearance="fill">
<mat-label>Name der Bank</mat-label> <mat-label>Name der Bank</mat-label>
<input matInput formControlName="nameOfFinancialInstitute" required /> <input matInput formControlName="bank" required />
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>

View File

@ -1,6 +1,8 @@
.stepperContainer { .stepperContainer {
display: flex; display: flex;
justify-content: space-around; justify-content: space-around;
max-width: 1024px;
margin: auto;
} }
.mat-stepper-horizontal { .mat-stepper-horizontal {
@ -54,6 +56,15 @@
p { p {
text-align: justify; text-align: justify;
} }
}
.big {
font-size: 1.9em;
p {
text-align: center;
}
} }
textarea { textarea {

View File

@ -1,8 +1,8 @@
import {Component, input, OnInit} from '@angular/core'; import {Component, input, OnInit} from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import {FormBuilder, FormGroup, Validators } from '@angular/forms';
import {ValidatorService} from "angular-iban"; import {ValidatorService} from "angular-iban";
import {StudentRegistration} from "../../../models/student-registration"; import {StudentRegistration} from "../../../models/student-registration";
import {RegisterService} from "../../../services/register/register.service"; import {RegistrationsService} from "../../../services/registrations/registrations.service";
export const MY_DATE_FORMAT= { export const MY_DATE_FORMAT= {
parse: { parse: {
@ -70,16 +70,16 @@ export class StudentRegisterComponent implements OnInit {
'Ein späterer rückwirkender Widerruf für aktuell stattfindende bzw. bereits stattgefundene ' + 'Ein späterer rückwirkender Widerruf für aktuell stattfindende bzw. bereits stattgefundene ' +
'Veranstaltungen ist ausgeschlossen.'; 'Veranstaltungen ist ausgeschlossen.';
constructor(private _formBuilder: FormBuilder, private registerService: RegisterService) {} constructor(private _formBuilder: FormBuilder, private registrationsService: RegistrationsService) {}
ngOnInit() { ngOnInit() {
this.firstFormGroup = this._formBuilder.group({ this.firstFormGroup = this._formBuilder.group({
firstName: ['', Validators.required], firstName: ['', Validators.required],
lastName: ['', Validators.required], lastName: ['', Validators.required],
birthdate: ['', Validators.required], birthday: ['', Validators.required],
street: ['', Validators.required], street: ['', Validators.required],
house: ['', Validators.required, Validators.pattern("^[0-9]*$")], house: ['', Validators.required, Validators.pattern("^[0-9]$")],
zip: ['', [Validators.required, Validators.pattern(/^\d+$/)]], //^: Asserts the start of the string. \d+: Matches one or more digits.$: Asserts the end of the string. zip: ['', [Validators.required, Validators.pattern(/^\d+$/)]], //^: Asserts the start of the string. \d+: Matches one or more digits.$: Asserts the end of the string.
city: ['', Validators.required], city: ['', Validators.required],
phone: ['', [Validators.required, Validators.pattern(/^(\+?\d{1,3})?[ ]*\d{9,}$/)]], phone: ['', [Validators.required, Validators.pattern(/^(\+?\d{1,3})?[ ]*\d{9,}$/)]],
@ -94,7 +94,7 @@ export class StudentRegisterComponent implements OnInit {
accountHolder: ['', Validators.required], accountHolder: ['', Validators.required],
iban: ['', [Validators.required, ValidatorService.validateIban]], iban: ['', [Validators.required, ValidatorService.validateIban]],
bic: ['', [Validators.required, Validators.pattern(/^[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3})?$/)]], bic: ['', [Validators.required, Validators.pattern(/^[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3})?$/)]],
nameOfFinancialInstitute: ['', Validators.required], bank: ['', Validators.required],
directDebitConsent: ['', Validators.required], directDebitConsent: ['', Validators.required],
returnDebitConsent: ['', Validators.required], returnDebitConsent: ['', Validators.required],
}); });
@ -111,6 +111,21 @@ export class StudentRegisterComponent implements OnInit {
}) })
} }
get registrationDate(): Date {
const today = new Date();
const currentYear = today.getFullYear();
const currentMonth = today.getMonth();
const currentDate = today.getDate();
if (currentDate === 1) {
return new Date(currentYear, currentMonth, 1); // Today is the 1st of the month.
} else if (currentDate <= 20) {
return new Date(currentYear, currentMonth, 15); // Return the 15th of the current month.
} else {
return new Date(currentYear, currentMonth + 1, 1); // Return the 1st of the next month.
}
}
capitalizeFirstTwoLetters() { capitalizeFirstTwoLetters() {
let ibanValue = this.secondFormGroup.get("iban")?.value let ibanValue = this.secondFormGroup.get("iban")?.value
if(ibanValue.length >= 2) { if(ibanValue.length >= 2) {
@ -129,7 +144,7 @@ export class StudentRegisterComponent implements OnInit {
// First Form Group // First Form Group
firstName: this.firstFormGroup.get('firstName')?.value, firstName: this.firstFormGroup.get('firstName')?.value,
lastName: this.firstFormGroup.get('lastName')?.value, lastName: this.firstFormGroup.get('lastName')?.value,
birthdate: this.firstFormGroup.get('birthdate')?.value, birthday: this.firstFormGroup.get('birthday')?.value,
gender: this.firstFormGroup.get('gender')?.value, gender: this.firstFormGroup.get('gender')?.value,
street: this.firstFormGroup.get('street')?.value, street: this.firstFormGroup.get('street')?.value,
house: this.firstFormGroup.get('house')?.value, house: this.firstFormGroup.get('house')?.value,
@ -155,6 +170,6 @@ export class StudentRegisterComponent implements OnInit {
multimediaConsent: this.thirdFormGroup.get('multimediaConsent')?.value multimediaConsent: this.thirdFormGroup.get('multimediaConsent')?.value
}; };
this.registerService.set(studentRegistration); this.registrationsService.set(studentRegistration).subscribe();
} }
} }

View File

@ -1,7 +1,7 @@
export interface StudentRegistration { export interface StudentRegistration {
firstName: string; firstName: string;
lastName: string; lastName: string;
birthdate: Date; birthday: Date;
gender: number; gender: number;
street: string; street: string;
house: number; house: number;

View File

@ -1,21 +0,0 @@
import { Injectable } from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {StudentRegistration} from "../../models/student-registration";
import {Observable} from "rxjs";
import { environment } from 'src/environments/environment';
@Injectable({
providedIn: 'root'
})
export class RegisterService {
private readonly serviceName = 'register';
constructor(private http: HttpClient) { }
public set(registration: StudentRegistration): Observable<void> {
const payload = JSON.stringify(registration);
return this.http.post<void>(`${environment.apiUrl}${this.serviceName}/set.php`,
payload
);
}
}

View File

@ -0,0 +1,44 @@
import { Injectable } from '@angular/core';
import { HttpClient } from "@angular/common/http";
import { StudentRegistration } from "../../models/student-registration";
import { Observable } from "rxjs";
import { environment } from 'src/environments/environment';
@Injectable({
providedIn: 'root'
})
export class RegistrationsService {
private readonly serviceName = 'registrations';
constructor(private http: HttpClient) { }
public set(registration: StudentRegistration): Observable<void> {
const formatDate = (date: Date): string => date.toISOString().split('T')[0];
const payload = `firstname=${encodeURIComponent(registration.firstName)}&` +
`lastname=${encodeURIComponent(registration.lastName)}&` +
`birthday=${encodeURIComponent(formatDate(registration.birthday))}&` +
`gender=${encodeURIComponent(registration.gender)}&` +
`street=${encodeURIComponent(registration.street)}&` +
`house=${encodeURIComponent(registration.house)}&` +
`zip=${encodeURIComponent(registration.zip)}&` +
`city=${encodeURIComponent(registration.city)}&` +
`phone=${encodeURIComponent(registration.phone)}&` +
`email=${encodeURIComponent(registration.email)}&` +
`accountHolder=${encodeURIComponent(registration.accountHolder)}&` +
`iban=${encodeURIComponent(registration.iban)}&` +
`bic=${encodeURIComponent(registration.bic)}&` +
`bank=${encodeURIComponent(registration.bank)}&` +
`applicationConsent=${encodeURIComponent(registration.applicationConsent)}&` +
`dataChangeConsent=${encodeURIComponent(registration.dataChangeConsent)}&` +
`privacyPolicyConsent=${encodeURIComponent(registration.privacyPolicyConsent)}&` +
`directDebitConsent=${encodeURIComponent(registration.directDebitConsent)}&` +
`returnDebitConsent=${encodeURIComponent(registration.returnDebitConsent)}&` +
`dataStorageConsent=${encodeURIComponent(registration.dataStorageConsent)}&` +
`multimediaConsent=${encodeURIComponent(registration.multimediaConsent)}`;
return this.http.post<void>(`${environment.apiUrl}${this.serviceName}/set.php`,
payload
);
}
}