diff --git a/src/app/component/login/login.component.html b/src/app/component/login/login.component.html
index f681a9d..e83fc54 100644
--- a/src/app/component/login/login.component.html
+++ b/src/app/component/login/login.component.html
@@ -1,7 +1,7 @@
-
+
Accedi
@@ -27,5 +27,31 @@
+
+
diff --git a/src/app/component/login/login.component.ts b/src/app/component/login/login.component.ts
index 93f098b..ddc84fc 100644
--- a/src/app/component/login/login.component.ts
+++ b/src/app/component/login/login.component.ts
@@ -3,29 +3,71 @@ import {Router} from "@angular/router";
import {TranslateService} from "../../service/language/translate.service";
import {ReadTranslateJsonService} from "../../service/language/readTranslateJson.service";
import {cookieService} from "../../service/cookie.service";
+import {UserService} from "../../service/http/user.service";
+import {UserEntity} from "../../interface/UserEntity";
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
-export class LoginComponent implements OnInit{
+export class LoginComponent implements OnInit {
+
+ newUser: { username: string; password: string; } = {username: '', password: ''};
+ username: string = '';
+ users: UserEntity[] | undefined;
+ login: boolean = true;
+ errorCreateUser: boolean = false;
+ errorLogin: boolean = false;
constructor(
private router: Router,
private translateService: TranslateService,
private readTranslationJsonService: ReadTranslateJsonService,
+ private userService: UserService,
private cookieService: cookieService,
) {
}
ngOnInit(): void {
-
-
+ if (this.cookieService.getUsername() != null) {
+ this.router.navigate(['/home']);
+ }
}
- submit(username: string, password: string) {
-
+ createNewUser(username: string, password: string) {
+ this.userService.getUsers().subscribe(users => {
+ this.users = users;
+ for (let i = 0; i < this.users.length; i++) {
+ if (this.users[i].username == username) {
+ this.errorCreateUser = true;
+ }
+ }
+ this.newUser.username = username;
+ this.newUser.password = password;
+ this.userService.createUser(this.newUser).subscribe(user => {
+ this.cookieService.setUsername(username);
+ this.router.navigate(['/management']);
+ });
+ });
}
+ loginFunction(username: string, password: string) {
+ this.userService.getUser(username).subscribe(user => {
+ if (user.password == password) {
+ this.cookieService.setUsername(username);
+ this.router.navigate(['/management']);
+ } else {
+ this.errorLogin = true;
+ }
+ });
+ }
+
+ switch() {
+ if (this.login) {
+ this.login = false;
+ } else {
+ this.login = true;
+ }
+ }
}
diff --git a/src/app/interface/UserEntity.ts b/src/app/interface/UserEntity.ts
index 49fd05f..43e8afd 100644
--- a/src/app/interface/UserEntity.ts
+++ b/src/app/interface/UserEntity.ts
@@ -1,8 +1,6 @@
export interface UserEntity {
id?: number;
- name: string;
username: string;
password: string;
-
-
+ admin?: boolean;
}