Add students registration endpoint
Fix issues when registering
This commit is contained in:
parent
ce25e4e6d0
commit
c485b12c61
|
@ -27,22 +27,24 @@
|
|||
$phone = escape($connection, $_POST["phone"]);
|
||||
$email = escape($connection, $_POST["email"]);
|
||||
|
||||
$accountHolder = escape($connection, $_POST["accountHolder"]);
|
||||
$accountholder = escape($connection, $_POST["accountHolder"]);
|
||||
$iban = escape($connection, $_POST["iban"]);
|
||||
$bic = escape($connection, $_POST["bic"]);
|
||||
$bank = escape($connection, $_POST["bank"]);
|
||||
|
||||
$applicationConsent = intval($_POST["applicationConsent"]);
|
||||
$dataChangeConsent = intval($_POST["dataChangeConsent"]);
|
||||
$privacyPolicyConsent = intval($_POST["privacyPolicyConsent"]);
|
||||
$directDebitConsent = intval($_POST["directDebitConsent"]);
|
||||
$returnDebitConsent = intval($_POST["returnDebitConsent"]);
|
||||
$dataStorageConsent = intval($_POST["dataStorageConsent"]);
|
||||
$multimediaConsent = intval($_POST["multimediaConsent"]);
|
||||
$applicationconsent = $_POST["applicationConsent"] === "true";
|
||||
$datachangeconsent = $_POST["dataChangeConsent"] === "true";
|
||||
$privacypolicyconsent = $_POST["privacyPolicyConsent"] === "true";
|
||||
$directdebitconsent = $_POST["directDebitConsent"] === "true";
|
||||
$returndebitconsent = $_POST["returnDebitConsent"] === "true";
|
||||
$datastorageconsent = $_POST["dataStorageConsent"] === "true";
|
||||
$multimediaconsent = $_POST["multimediaConsent"] === "true";
|
||||
|
||||
$registrationfrom = registrationDate()->format('Y-m-d');
|
||||
|
||||
$querystr = "SELECT * FROM li_registrations
|
||||
WHERE li_registrations.rid = ${rid}";
|
||||
|
||||
|
||||
$result = mysqli_query($connection, $querystr);
|
||||
if($result->num_rows !== 0) {
|
||||
$querystr = "UPDATE li_registrations SET firstname='${firstname}', lastname='${lastname}', birthday='${birthday}',
|
||||
|
@ -50,18 +52,20 @@
|
|||
zip='${zip}', city='${city}', phone='${phone}', email='${email}',
|
||||
accountholder='${accountHolder}', iban='${iban}', bic='${bic}', bank='${bank}',
|
||||
applicationconsent=${applicationconsent}, datachangeconsent=${datachangeconsent}, privacypolicyconsent=${privacypolicyconsent},
|
||||
returndebitconsent=${returndebitconsent}, datastorageconsent=${datastorageconsent}, multimediaconsent=${multimediaconsent},
|
||||
directdebitconsent=${directdebitconsent}, returndebitconsent=${returndebitconsent}, datastorageconsent=${datastorageconsent}, multimediaconsent=${multimediaconsent},
|
||||
WHERE rid=${rid}";
|
||||
} else {
|
||||
$querystr = "INSERT INTO li_registrations (firstname, lastname, birthday, gender, street, house, zip, city, phone, email,
|
||||
accountholder, iban, bic, bank,
|
||||
applicationconsent, datachangeconsent, privacypolicyconsent,
|
||||
returndebitconsent, datastorageconsent, multimediaconsent)
|
||||
applicationconsent, datachangeconsent, privacypolicyconsent, directdebitconsent,
|
||||
returndebitconsent, datastorageconsent, multimediaconsent, registrationfrom)
|
||||
|
||||
VALUES('{$firstname}', '{$lastname}', '{$birthday}', {$gender}, '{$street}', {$house}, '{$house_suffix}', '{$zip}', '{$city}', '{$phone}', '{$email}'.
|
||||
'${accountHolder}', '${iban}', '${bic}', '${bank}',
|
||||
${applicationconsent}, ${datachangeconsent}, ${privacypolicyconsent},
|
||||
${returndebitconsent}, ${datastorageconsent}, ${multimediaconsent})";
|
||||
VALUES('{$firstname}', '{$lastname}', '{$birthday}', {$gender}, '{$street}', {$house}, '{$zip}', '{$city}', '{$phone}', '{$email}',
|
||||
'{$accountholder}', '{$iban}', '{$bic}', '{$bank}',
|
||||
{$applicationconsent}, {$datachangeconsent}, {$privacypolicyconsent}, {$directdebitconsent},
|
||||
{$returndebitconsent}, {$datastorageconsent}, {$multimediaconsent}, '{$registrationfrom}')";
|
||||
|
||||
echo json_encode('{ "result": "' . $querystr . '" }');
|
||||
}
|
||||
|
||||
$result = mysqli_query($connection, $querystr);
|
||||
|
|
|
@ -43,4 +43,20 @@ function login( $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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -28,15 +28,15 @@
|
|||
<mat-label>Geburtstag</mat-label>
|
||||
<input
|
||||
matInput
|
||||
[matDatepicker]="birthdatePicker"
|
||||
formControlName="birthdate"
|
||||
[matDatepicker]="birthdayPicker"
|
||||
formControlName="birthday"
|
||||
placeholder="DD.MM.YYYY"
|
||||
required />
|
||||
<mat-datepicker-toggle
|
||||
matSuffix
|
||||
[for]="birthdatePicker"></mat-datepicker-toggle>
|
||||
[for]="birthdayPicker"></mat-datepicker-toggle>
|
||||
<mat-datepicker
|
||||
#birthdatePicker
|
||||
#birthdayPicker
|
||||
startView="multi-year"></mat-datepicker>
|
||||
</mat-form-field>
|
||||
|
||||
|
@ -67,7 +67,7 @@
|
|||
|
||||
<mat-form-field appearance="fill">
|
||||
<mat-label>Postleitzahl</mat-label>
|
||||
<input matInput formControlName="postalCode" required />
|
||||
<input matInput formControlName="zip" required />
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field appearance="fill">
|
||||
|
@ -81,6 +81,9 @@
|
|||
</mat-form-field>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flexContainerColumn whitebox big">
|
||||
<p>Sie melden sich zum {{registrationDate | date:'dd.MM.yyyy' }} an</p>
|
||||
</div>
|
||||
<div class="flexContainerColumn whitebox">
|
||||
<mat-checkbox formControlName="applicationConsent" required><span [innerHTML]="infoTextAufnahme"></span></mat-checkbox>
|
||||
<br style="margin-bottom: 20px;">
|
||||
|
@ -123,7 +126,7 @@
|
|||
|
||||
<mat-form-field appearance="fill">
|
||||
<mat-label>Name der Bank</mat-label>
|
||||
<input matInput formControlName="nameOfFinancialInstitute" required />
|
||||
<input matInput formControlName="bank" required />
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
.stepperContainer {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
max-width: 1024px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.mat-stepper-horizontal {
|
||||
|
@ -54,6 +56,15 @@
|
|||
p {
|
||||
text-align: justify;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.big {
|
||||
font-size: 1.9em;
|
||||
|
||||
p {
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
textarea {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
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 {StudentRegistration} from "../../../models/student-registration";
|
||||
import {RegisterService} from "../../../services/register/register.service";
|
||||
import {RegistrationsService} from "../../../services/registrations/registrations.service";
|
||||
|
||||
export const MY_DATE_FORMAT= {
|
||||
parse: {
|
||||
|
@ -70,16 +70,16 @@ export class StudentRegisterComponent implements OnInit {
|
|||
'Ein späterer rückwirkender Widerruf für aktuell stattfindende bzw. bereits stattgefundene ' +
|
||||
'Veranstaltungen ist ausgeschlossen.';
|
||||
|
||||
constructor(private _formBuilder: FormBuilder, private registerService: RegisterService) {}
|
||||
constructor(private _formBuilder: FormBuilder, private registrationsService: RegistrationsService) {}
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
this.firstFormGroup = this._formBuilder.group({
|
||||
firstName: ['', Validators.required],
|
||||
lastName: ['', Validators.required],
|
||||
birthdate: ['', Validators.required],
|
||||
birthday: ['', 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.
|
||||
city: ['', Validators.required],
|
||||
phone: ['', [Validators.required, Validators.pattern(/^(\+?\d{1,3})?[ ]*\d{9,}$/)]],
|
||||
|
@ -94,7 +94,7 @@ export class StudentRegisterComponent implements OnInit {
|
|||
accountHolder: ['', Validators.required],
|
||||
iban: ['', [Validators.required, ValidatorService.validateIban]],
|
||||
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],
|
||||
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() {
|
||||
let ibanValue = this.secondFormGroup.get("iban")?.value
|
||||
if(ibanValue.length >= 2) {
|
||||
|
@ -129,7 +144,7 @@ export class StudentRegisterComponent implements OnInit {
|
|||
// First Form Group
|
||||
firstName: this.firstFormGroup.get('firstName')?.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,
|
||||
street: this.firstFormGroup.get('street')?.value,
|
||||
house: this.firstFormGroup.get('house')?.value,
|
||||
|
@ -155,6 +170,6 @@ export class StudentRegisterComponent implements OnInit {
|
|||
multimediaConsent: this.thirdFormGroup.get('multimediaConsent')?.value
|
||||
};
|
||||
|
||||
this.registerService.set(studentRegistration);
|
||||
this.registrationsService.set(studentRegistration).subscribe();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
export interface StudentRegistration {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
birthdate: Date;
|
||||
birthday: Date;
|
||||
gender: number;
|
||||
street: string;
|
||||
house: number;
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue