Skip to content

Commit

Permalink
add passwort reset test
Browse files Browse the repository at this point in the history
  • Loading branch information
dysTOS committed Apr 6, 2024
1 parent 33b8746 commit 2db466e
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 98 deletions.
109 changes: 53 additions & 56 deletions src/app/pages/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
<div class="grid grid-nogutter">
<div class="col-12 login-header">
<h1>LOGIN</h1>
<h2>
Wenn du das erste Mal hier bist, drücke unten auf
"Registrierung".
</h2>
<h2>Wenn du das erste Mal hier bist, drücke unten auf "Registrierung".</h2>
<img src="assets\images\app_logo.png" />
</div>
<div class="col-12 pb-0 pt-0">
Expand All @@ -19,59 +16,59 @@ <h2>
type="email"
pInputText
[(ngModel)]="user.email"
[ngClass]="{
'ng-invalid ng-dirty': submitted && !user.email
}"
[ngClass]="{
'ng-invalid ng-dirty': submitted && !user.email
}"
required
autofocus
/>
@if (submitted && !user.email) {
<small class="p-error"
>Name ist erforderlich!</small
>
}
<label>E-Mail</label>
</span>
</div>
<div class="col-12">
<span class="p-float-label">
<input
type="password"
pInputText
[(ngModel)]="user.passwort"
[ngClass]="{
'ng-invalid ng-dirty': submitted && !user.passwort
}"
(keydown.enter)="onSubmit()"
required
/>
@if (submitted && !user.passwort) {
<small class="p-error"
>Passwort ist erforderlich!</small
>
}
<label>Passwort</label>
</span>
</div>
<!-- <div style="height: 400px"></div> -->
<div class="col-12 button-container">
<button
pButton
type="button"
label="Login"
[icon]="
isChecking ? 'pi pi-spin pi-spinner' : 'pi pi-sign-in'
"
(click)="onSubmit()"
></button>
<button
pButton
class="p-button p-button-outlined p-button-sm mt-3"
label="Registrierung"
icon="pi pi-user"
routerLink="/signup"
></button>
</div>
</div>
/>
@if (submitted && !user.email) {
<small class="p-error">Name ist erforderlich!</small>
}
<label>E-Mail</label>
</span>
</div>
<div class="col-12">
<span class="p-float-label">
<input
type="password"
pInputText
[(ngModel)]="user.passwort"
[ngClass]="{
'ng-invalid ng-dirty': submitted && !user.passwort
}"
(keydown.enter)="onSubmit()"
required
/>
@if (submitted && !user.passwort) {
<small class="p-error">Passwort ist erforderlich!</small>
}
<label>Passwort</label>
</span>
</div>
<!-- <div style="height: 400px"></div> -->
<div class="col-12 button-container">
<button
pButton
type="button"
label="Login"
[icon]="isChecking ? 'pi pi-spin pi-spinner' : 'pi pi-sign-in'"
(click)="onSubmit()"
></button>
<button
pButton
class="p-button p-button-outlined p-button-sm mt-3"
label="Registrierung"
icon="pi pi-user"
routerLink="/signup"
></button>
<button
pButton
class="p-button p-button-text p-button-sm mt-3"
label="Passwort vergessen"
(click)="onForgotPassword()"
></button>
</div>
</div>
</div>
</div>
11 changes: 10 additions & 1 deletion src/app/pages/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,16 @@ export class LoginComponent implements OnInit {
}
}

checkInput(): boolean {
public onForgotPassword() {
if (this.user.email == null) {
this.infoService.error('Bitte gib deine E-Mail Adresse ein und drücke dann auf "Passwort vergessen".');
return;
}

this.authService.forgotPassword(this.user.email).subscribe();
}

private checkInput(): boolean {
if (this.user.email && this.user.passwort) return true;
return false;
}
Expand Down
88 changes: 47 additions & 41 deletions src/app/services/api/auth-api.service.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,52 @@
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
import { HttpClient } from "@angular/common/http";
import { environment } from "src/environments/environment";
import { User } from "../../models/User";
import {
UserRegistrationInput,
UserLoginInput,
UserLoginOutput,
} from "src/app/interfaces/api-middleware";
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { User } from '../../models/User';
import { UserRegistrationInput, UserLoginInput, UserLoginOutput } from 'src/app/interfaces/api-middleware';

@Injectable({
providedIn: "root",
providedIn: 'root',
})
export class AuthAPIService {
private apiURL = environment.apiUrl;

constructor(private http: HttpClient) {}

// User registration
register(user: UserRegistrationInput): Observable<any> {
const url = this.apiURL + "register";
return this.http.post(url, user);
}

// Login
login(user: UserLoginInput): Observable<UserLoginOutput> {
const url = this.apiURL + "login";
return this.http.post<any>(url, user);
}

logout(): Observable<any> {
const url = this.apiURL + "logout";
return this.http.post<any>(url, {});
}

getCurrentUser(): Observable<UserLoginOutput> {
const url = this.apiURL + "user";
return this.http.post<any>(url, {});
}

deleteUser(user: User): Observable<any> {
const url = this.apiURL + "deleteuser";
return this.http.post<any>(url, user);
}
private apiURL = environment.apiUrl;

constructor(private http: HttpClient) {}

// User registration
public register(user: UserRegistrationInput): Observable<any> {
const url = this.apiURL + 'register';
return this.http.post(url, user);
}

// Login
public login(user: UserLoginInput): Observable<UserLoginOutput> {
const url = this.apiURL + 'login';
return this.http.post<any>(url, user);
}

public logout(): Observable<any> {
const url = this.apiURL + 'logout';
return this.http.post<any>(url, {});
}

public getCurrentUser(): Observable<UserLoginOutput> {
const url = this.apiURL + 'user';
return this.http.post<any>(url, {});
}

public deleteUser(user: User): Observable<any> {
const url = this.apiURL + 'deleteuser';
return this.http.post<any>(url, user);
}

public forgotPassword(email: string): Observable<any> {
const url = this.apiURL + 'forgot-password';
return this.http.post<any>(url, { email });
}

public resetPassword(token: string, email: string, password: string): Observable<any> {
const url = this.apiURL + 'reset-password';
return this.http.post<any>(url, { token, email, password });
}
}

0 comments on commit 2db466e

Please sign in to comment.