Skip to content

Commit

Permalink
Merge pull request #142 from PoojaKanagaraj06/navbarrmv
Browse files Browse the repository at this point in the history
Removed navbar at index page and removed NoDueSystem
  • Loading branch information
GVishnudhasan authored Nov 3, 2024
2 parents 070362b + 916c8d0 commit 44be2f0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 22 deletions.
4 changes: 2 additions & 2 deletions client/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<app-navbar></app-navbar>
<router-outlet></router-outlet>
<app-navbar *ngIf="isLoggedIn"></app-navbar>
<app-login (loginEvent)="onLoginEvent($event)"></app-login>
10 changes: 7 additions & 3 deletions client/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
styleUrls: ['./app.component.css'],
})
export class AppComponent {
title = 'No Due Management System';
}
isLoggedIn = false;

onLoginEvent(isLoggedIn: boolean): void {
this.isLoggedIn = isLoggedIn;
}
}
2 changes: 1 addition & 1 deletion client/src/app/components/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h3>Welcome to Online No Due Management System - KSRIET || This Project is Desig
<img src="./assets/mobile_header.png" alt="" class="img-responsive mobile-header">
</header>
<div class="col-md-12">
<h2>No Due Management System</h2>

<div class="card card-container">
<h1 style="text-align: center;">Login</h1>
<img id="profile-img" src="//ssl.gstatic.com/accounts/ui/avatar_2x.png" class="profile-img-card" />
Expand Down
26 changes: 13 additions & 13 deletions client/src/app/components/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { AuthService } from 'src/app/services/auth.service';
import { StorageService } from 'src/app/services/storage.service';
import { Router } from '@angular/router';
Expand All @@ -19,13 +19,14 @@ export class LoginComponent implements OnInit {
isText: boolean = false;
eyeIcon: string = 'fa-eye-slash';
isLoggedIn = false;
@Output() loginEvent = new EventEmitter<boolean>();
isLoginFailed = false;
errorMessage = '';
roles: string[] = [];
email: string = '';
name: string = '';

togglePasswordVisibility(){
togglePasswordVisibility() {
this.showPassword = !this.showPassword;
}

Expand All @@ -48,10 +49,9 @@ export class LoginComponent implements OnInit {
this.authService.login(email, password).subscribe({
next: (data) => {
this.storageService.saveUser(data);

this.isLoginFailed = false;
this.isLoggedIn = true;
Swal.fire("Thank You...",'Login Successfully','success')
Swal.fire("Thank You...", 'Login Successfully', 'success');
this.roles = this.storageService.getUser().roles;

if (this.roles.includes('ROLE_ADMIN')) {
Expand All @@ -61,25 +61,25 @@ export class LoginComponent implements OnInit {
} else {
this.router.navigate(['/student-board']);
}
this.loginEvent.emit(this.isLoggedIn);
},
error: (err) => {
this.errorMessage = err.error.message;
console.error('Login error:', err);
console.error('Error status:', err.status);
console.error('Error message:', err.error?.message);
console.error('Full error object:', err);
this.errorMessage = err.error?.message || 'An error occurred during login';
this.isLoginFailed = true;
Swal.fire("Error", this.errorMessage, 'error');
},
});
}

/*hideShowPass() {
this.isText = !this.isText;
this.isText ? (this.eyeIcon = 'fa-eye') : (this.eyeIcon = 'fa-eye-slash');
this.isText ? (this.type = 'text') : (this.type = 'password');
}*/

reloadPage(): void {
window.location.reload();
}

goto(){
goto(): void {
const user_role = this.storageService.getUser().roles;
console.log(user_role[0], user_role[0].split('_')[1].toLowerCase());
const role = user_role[0].split('_')[1].toLowerCase();
Expand All @@ -99,4 +99,4 @@ export class LoginComponent implements OnInit {
},
});
}
}
}
12 changes: 10 additions & 2 deletions client/src/app/components/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { Component } from '@angular/core';

import { AuthService } from '../../services/auth.service';
import { OnInit } from '@angular/core';
@Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html',
styleUrls: ['./navbar.component.css']
})
export class NavbarComponent {
export class NavbarComponent implements OnInit {
isNavbarOpen = false;
isLoggedIn = false;

constructor(private authService: AuthService) {}

ngOnInit() {
this.isLoggedIn = this.authService.isLoggedIn();
}

toggleNavbar() {
this.isNavbarOpen = !this.isNavbarOpen;
Expand Down
6 changes: 5 additions & 1 deletion client/src/app/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export class AuthService {
);
}

logout(): Observable<any> {
logout(): Observable<any> {
return this.http.post(AUTH_API + 'signout', {}, httpOptions);
}

isLoggedIn(): boolean {
return !!localStorage.getItem('auth-token');
}
}

0 comments on commit 44be2f0

Please sign in to comment.