Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/admin-panel/admin-panel.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="admin-panel">
<h2>Painel Administrativo</h2>
<button (click)="logout()">Sair</button>
</div>
15 changes: 15 additions & 0 deletions src/app/admin-panel/admin-panel.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component } from '@angular/core';
import { AuthService } from '../services/auth.service';

@Component({
selector: 'app-admin-panel',
templateUrl: './admin-panel.component.html',
styleUrls: ['./admin-panel.component.css']
})
export class AdminPanelComponent {
constructor(private authService: AuthService) {}

logout() {
this.authService.logout();
}
}
8 changes: 8 additions & 0 deletions src/app/login/login.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="login-container">
<h2>Login</h2>
<input type="text" [(ngModel)]="username" placeholder="Usuário">
<input type="password" [(ngModel)]="password" placeholder="Senha">
<button (click)="login()">Entrar</button>
<p *ngIf="errorMessage">{{ errorMessage }}</p>
</div>

24 changes: 24 additions & 0 deletions src/app/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from '../services/auth.service';

@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent {
username: string = '';
password: string = '';
errorMessage: string = '';

constructor(private authService: AuthService, private router: Router) {}

login() {
if (this.authService.login(this.username, this.password)) {
this.router.navigate(['/admin']);
} else {
this.errorMessage = 'Usuário ou senha inválidos!';
}
}
}
26 changes: 26 additions & 0 deletions src/app/services/auth.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root'
})
export class AuthService {
private isAuthenticated = false;

login(username: string, password: string): boolean {
if (username === 'admin' && password === 'admin123') {
this.isAuthenticated = true;
localStorage.setItem('user', JSON.stringify({ username }));
return true;
}
return false;
}

logout(): void {
this.isAuthenticated = false;
localStorage.removeItem('user');
}

isLoggedIn(): boolean {
return localStorage.getItem('user') !== null;
}
}
17 changes: 17 additions & 0 deletions src/app/services/theme.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root'
})
export class ThemeService {
private darkTheme = false;

toggleTheme(): void {
this.darkTheme = !this.darkTheme;
document.body.classList.toggle('dark-mode', this.darkTheme);
}

isDarkTheme(): boolean {
return this.darkTheme;
}
}
5 changes: 5 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@
body{
background-color: #1F1147;
}

.dark-mode {
background-color: #121212;
color: white;
}