Skip to content
Snippets Groups Projects
Commit 0952a5eb authored by mechtelm's avatar mechtelm
Browse files

superuser: validate password length 7; login: errorhandling fix

parent ec480c5d
No related branches found
No related tags found
No related merge requests found
Showing with 43 additions and 35 deletions
{
"name": "itc-ng",
"version": "2.0.0-beta.5",
"version": "2.0.1",
"scripts": {
"ng": "ng",
"start": "ng serve",
......
......@@ -53,6 +53,9 @@ export class LoginComponent implements OnInit, OnDestroy {
const errCode = authData as number;
if (errCode === 400) {
this.problemText = 'Anmeldedaten sind nicht gültig. Bitte nocheinmal versuchen!';
} else if (errCode === 202 || errCode === 204) {
this.problemText = 'Anmeldedaten sind gültig, aber es sind keine Arbeitsbereiche oder Tests freigegeben.';
} else {
this.problemText = 'Problem bei der Anmeldung.';
// app.interceptor will show error message
......
......@@ -49,39 +49,42 @@ export class AuthInterceptor implements HttpInterceptor {
let goToLoginPage = false;
let label = 'Unbekanntes Verbindungsproblem';
switch (httpError.status) {
case 400: {
case 202:
case 204:
case 207:
case 400:
ignoreError = true;
// apiError.info = ?? TODO - from request body
// apiError.info contains error = body
break;
}
case 401: {
case 401:
goToLoginPage = true;
label = 'Bitte für diese Aktion erst anmelden!';
break;
}
case 403: {
case 403:
label = 'Für diese Funktion haben Sie keine Berechtigung.';
break;
}
case 404: {
case 404:
label = 'Daten/Objekt nicht gefunden.';
break;
}
case 410: {
case 410:
goToLoginPage = true;
label = 'Anmeldung abgelaufen. Bitte erneut anmelden!';
break;
}
case 422: {
case 422:
ignoreError = true;
// apiError.info = ?? TODO - from request body
label = 'Die übermittelten Objekte sind fehlerhaft!';
break;
}
case 500: {
case 500:
label = 'Allgemeines Server-Problem.';
break;
}
}
if (!ignoreError) {
if (goToLoginPage) {
......
......@@ -38,7 +38,7 @@ export class BackendService {
if (errCode === 400) {
return this.http
.put<AuthData>(this.serverUrl + 'session/login', {name, password})
.pipe(catchError(errCode => of(errCode)));
.pipe(catchError((err: ApiError) => of(err.code)));
} else {
return of(errCode);
}
......
......@@ -29,19 +29,11 @@ export class BackendService {
addUser(name: string, password: string): Observable<Boolean> {
return this.http
.put<Boolean>(this.serverUrl + 'user', {n: name, p: password})
.pipe(catchError((err: ApiError) => {
console.warn(`addUser Api-Error: ${err.code} ${err.info} `);
return of(false)
}));
}
changePassword(userId: number, password: string): Observable<Boolean> {
return this.http
.patch<Boolean>(this.serverUrl + `user/${userId}/password`, {p: password})
.pipe(catchError((err: ApiError) => {
console.warn(`changePassword Api-Error: ${err.code} ${err.info} `);
return of(false)
}));
}
setSuperUserStatus(userId: number, changeToSuperUser: boolean, password: string): Observable<number> {
......
......@@ -5,6 +5,7 @@
<div class="infobox">
<p>Ändern des Kennwortes für Nutzer/in "{{ data }}".</p>
</div>
<p>Achtung: Mindestlänge für Kennwort 7 Zeichen</p>
<p>
<mat-form-field class="full-width">
<input matInput type="password" formControlName="pw" placeholder="Kennwort">
......
......@@ -9,7 +9,7 @@ import {FormGroup, Validators, FormControl} from '@angular/forms';
export class NewpasswordComponent {
newpasswordform = new FormGroup({
pw: new FormControl('', [Validators.required, Validators.minLength(3)])
pw: new FormControl('', [Validators.required, Validators.minLength(7)])
});
constructor(
......
......@@ -7,6 +7,7 @@
<input matInput formControlName="name" placeholder="Name" autocomplete="off">
</mat-form-field>
</p>
<p>Achtung: Mindestlänge für Kennwort 7 Zeichen</p>
<p>
<mat-form-field class="full-width">
<input matInput type="password" formControlName="pw" placeholder="Kennwort" autocomplete="off">
......
......@@ -9,6 +9,6 @@ import {FormControl, FormGroup, Validators} from '@angular/forms';
export class NewuserComponent {
newuserform = new FormGroup({
name: new FormControl('', [Validators.required, Validators.minLength(3)]),
pw: new FormControl('', [Validators.required, Validators.minLength(3)])
pw: new FormControl('', [Validators.required, Validators.minLength(7)])
});
}
......@@ -17,6 +17,9 @@ import {
import { MainDataService } from 'src/app/maindata.service';
import {IdRoleData, UserData} from "../superadmin.interfaces";
import {SuperadminPasswordRequestComponent} from "../superadmin-password-request/superadmin-password-request.component";
import {catchError} from "rxjs/operators";
import {ApiError} from "../../app.interfaces";
import {of} from "rxjs";
@Component({
......@@ -78,14 +81,17 @@ export class UsersComponent implements OnInit {
if (result !== false) {
this.mds.setSpinnerOn();
this.bs.addUser((<FormGroup>result).get('name').value,
(<FormGroup>result).get('pw').value).subscribe(
(<FormGroup>result).get('pw').value)
.pipe(catchError((err: ApiError) => {
this.snackBar.open(`Konnte Nutzer nicht hinzufügen: ${err.code} ${err.info} `, 'Fehler', {duration: 5000});
return of(false)
})).subscribe(
respOk => {
if (respOk !== false) {
this.snackBar.open('Nutzer hinzugefügt', '', {duration: 1000});
this.updateObjectList();
} else {
this.mds.setSpinnerOff();
this.snackBar.open('Konnte Nutzer nicht hinzufügen', 'Fehler', {duration: 1000});
}
});
}
......@@ -179,13 +185,15 @@ export class UsersComponent implements OnInit {
if (result !== false) {
this.mds.setSpinnerOn();
this.bs.changePassword(selectedRows[0]['id'],
(<FormGroup>result).get('pw').value).subscribe(
(<FormGroup>result).get('pw').value)
.pipe(catchError((err: ApiError) => {
this.snackBar.open(`Konnte Kennwort nicht ändern: ${err.code} ${err.info} `, 'Fehler', {duration: 5000});
return of(false)
})).subscribe(
respOk => {
this.mds.setSpinnerOff();
if (respOk !== false) {
this.snackBar.open('Kennwort geändert', '', {duration: 1000});
} else {
this.snackBar.open('Konnte Kennwort nicht ändern', 'Fehler', {duration: 1000});
}
});
}
......
......@@ -5,6 +5,6 @@ export const environment = {
testcenterUrl: '/',
appName: 'IQB-Testcenter',
appPublisher: 'IQB - Institut zur Qualitätsentwicklung im Bildungswesen',
appVersion: '2.0.0-beta.5 - 30.4.2020',
appVersion: '2.0.1 - 13.5.2020',
apiVersionExpected: '3.0.1'
};
......@@ -5,6 +5,6 @@ export const environment = {
testcenterUrl: '/api/',
appName: 'IQB-Testcenter',
appPublisher: 'IQB - Institut zur Qualitätsentwicklung im Bildungswesen',
appVersion: '2.0.0-beta.5 - 30.4.2020',
appVersion: '2.0.1 - 13.5.2020',
apiVersionExpected: '3.0.1'
};
......@@ -10,7 +10,7 @@ export const environment = {
// testcenterUrl: 'http://localhost/api/',
appName: 'IQB-Testcenter',
appPublisher: 'IQB - Institut zur Qualitätsentwicklung im Bildungswesen',
appVersion: '2.0.0-beta.5 - 30.4.2020',
appVersion: '2.0.1 - 13.5.2020',
apiVersionExpected: '3.0.1'
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment