diff --git a/src/app/app.component.html b/src/app/app.component.html index 0680b43..56ef914 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1 +1,2 @@ + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 7ff1ac2..52418a7 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,4 +1,6 @@ import { Component } from '@angular/core'; +import {CookieService} from "ngx-cookie-service"; +import {Router} from "@angular/router"; @Component({ selector: 'app-root', @@ -7,4 +9,19 @@ import { Component } from '@angular/core'; }) export class AppComponent { title = 'm-152'; + + + constructor( + private cookieService: CookieService, + private router: Router, + ) { + } + + clearAllCookies() { + const allCookies = this.cookieService.getAll(); + for (const cookieName in allCookies) { + this.cookieService.delete(cookieName); + } + this.router.navigate(['/login']); + } } diff --git a/src/app/component/login/login.component.html b/src/app/component/login/login.component.html index e83fc54..eab37ca 100644 --- a/src/app/component/login/login.component.html +++ b/src/app/component/login/login.component.html @@ -1,57 +1,44 @@
-
+
-

Accedi

+

Accedi

+

Registrati

-
+
- - + +
+ class="w-full px-4 py-2 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-600 focus:border-transparent" + [(ngModel)]="newUser.password">
- +
-
-
- -

Registrati

- -
- -
- - -
- -
- - -
- -
- -
- -
+ + Register + Login +
+
diff --git a/src/app/component/login/login.component.ts b/src/app/component/login/login.component.ts index ddc84fc..825a47a 100644 --- a/src/app/component/login/login.component.ts +++ b/src/app/component/login/login.component.ts @@ -30,23 +30,22 @@ export class LoginComponent implements OnInit { } ngOnInit(): void { - if (this.cookieService.getUsername() != null) { - this.router.navigate(['/home']); - } + } - createNewUser(username: string, password: string) { + createNewUser(createUser: UserEntity) { + console.log(createUser.username+" "+createUser.password); this.userService.getUsers().subscribe(users => { this.users = users; for (let i = 0; i < this.users.length; i++) { - if (this.users[i].username == username) { + if (this.users[i].username == createUser.username) { this.errorCreateUser = true; } } - this.newUser.username = username; - this.newUser.password = password; + this.newUser.username = createUser.username; + this.newUser.password = createUser.password; this.userService.createUser(this.newUser).subscribe(user => { - this.cookieService.setUsername(username); + this.cookieService.setUsername(createUser.username); this.router.navigate(['/management']); }); }); @@ -63,6 +62,14 @@ export class LoginComponent implements OnInit { }); } + submit() { + if (this.login) { + this.loginFunction(this.newUser.username, this.newUser.password); + } else { + this.createNewUser(this.newUser); + } + } + switch() { if (this.login) { this.login = false; diff --git a/src/app/service/http/user.service.ts b/src/app/service/http/user.service.ts index 7974fc9..01f40d7 100644 --- a/src/app/service/http/user.service.ts +++ b/src/app/service/http/user.service.ts @@ -30,7 +30,9 @@ export class UserService { } createUser(user: UserEntity) { + console.log("create "+user); return this.http.post(USER, user); + } updateUser(user: UserEntity, id: number) {