Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d245a3a

Browse files
change:Update overall Styling.
1 parent 5cd8aa0 commit d245a3a

File tree

11 files changed

+235
-86
lines changed

11 files changed

+235
-86
lines changed

‎src/app/app-routing.module.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { NgModule } from '@angular/core';
2-
import { RouterModule, Routes} from '@angular/router';
2+
import {mapToCanActivate, RouterModule, Routes} from '@angular/router';
33
import {LoginComponent} from "./component/login/login.component";
44
import {RegisterComponent} from "./component/register/register.component";
5+
import {AuthenticatedComponent} from "./component/authenticated/authenticated.component";
6+
import {AuthGuard} from "./guards/auth.guard";
7+
8+
9+
510

611

712
const routes: Routes = [
813
{ path: 'login', component: LoginComponent },
914
{ path: 'signup', component: RegisterComponent },
10-
{ path: '', redirectTo: '/login',pathMatch: 'full'}
15+
{ path: 'dashboard', component: AuthenticatedComponent,canActivate: [AuthGuard]}
1116
];
1217

1318
@NgModule({

‎src/app/app.component.css

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +0,0 @@
1-
.full-page-container {
2-
height: 100vh;
3-
width: 100vw;
4-
background-color: #f0f8ff;
5-
display: flex;
6-
justify-content: center;
7-
align-items: center;
8-
flex-direction: column;
9-
padding: 20px;
10-
box-sizing: border-box;
11-
}
12-
13-
.mat-drawer-content {
14-
background-color: #f5f5f5;
15-
}
16-
17-
input.form-control {
18-
background-color: #f0f8ff;
19-
border: 1px solid #ced4da;
20-
}
21-
22-
input.form-control:focus {
23-
background-color: white;
24-
border-color: #80bdff;
25-
box-shadow: 0 0 0 0.2rem rgba(128, 189, 255, 0.25);
26-
}
27-
28-
.card-login, .card-signup {
29-
width: 600px;
30-
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
<p>authenticated works!</p>
1+
<div class="hero">
2+
<div class="welcome">
3+
<h3 class="welcome-heading">WELCOME</h3>
4+
<h1 class="welcome-title mt-3">Mr. </h1>
5+
<h2 class="welcome-subtitle">This is an example of a JWT authentication system in Angular, showcasing the implementation and security features.</h2>
6+
<br />
7+
</div>
8+
</div>
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
<div class="full-page-container">
2-
<div class="" style="overflow-y: auto;" data-simplebar data-simplebar-force-enabled="true">
3-
<div class="container h-vh d-flex justify-content-center align-items-center flex-column">
4-
<div class="d-flex justify-content-center align-items-center mb-3">
5-
<span> <!-- SVG Logo here --> </span>
6-
<h2 class="ml-2 text-bg mb-0"><strong>Authenticate</strong></h2>
7-
</div>
8-
<div class="row w-100 justify-content-center">
9-
<div class="card card-login mb-3">
2+
<app-toast #toast></app-toast>
3+
<div class="d-flex justify-content-center align-items-center flex-column">
4+
<div class="justify-content-center">
5+
<div class="card card-login">
106
<div class="card-body">
11-
<form [formGroup]="loginForm" (ngSubmit)="login()">
7+
<h2 class="my-1 auth-form-title"><strong>Login</strong></h2>
8+
<br>
9+
<form [formGroup]="loginForm" (ngSubmit)="login()" class="auth-form-box">
1210
<div class="form-group">
1311
<label>Username</label>
1412
<div class="input-group input-group--inline">
@@ -32,19 +30,16 @@ <h2 class="ml-2 text-bg mb-0"><strong>Authenticate</strong></h2>
3230
</div>
3331
<small class="text-danger" *ngIf="f['password'].touched && f['password'].invalid">Password is required</small>
3432
</div>
33+
<br>
3534
<div class="text-center">
36-
<button type="submit" class="btn btn-primary" [disabled]="!loginForm.valid">Login</button>
35+
<button type="submit" class="auth-button" [disabled]="!loginForm.valid">Login</button>
36+
</div>
37+
<div class="d-flex justify-content-center register">
38+
<p class="mr-2">Don't have an account? <a routerLink="/signup">Sign Up</a></p>
3739
</div>
3840
</form>
3941
</div>
4042
</div>
4143
</div>
42-
43-
<div class="d-flex justify-content-center">
44-
<span class="mr-2">Don't have an account?</span>
45-
<a routerLink="/signup">Sign Up</a>
46-
</div>
4744
</div>
48-
49-
</div>
5045
</div>

‎src/app/component/login/login.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {AuthService} from "../../services/auth.service";
88
@Component({
99
selector: 'app-login',
1010
templateUrl: './login.component.html',
11-
styleUrls: ['./login.component.css','../../app.component.css']
11+
styleUrls: ['./login.component.css']
1212
})
1313
export class LoginComponent implements OnInit {
1414
@ViewChild('toast') toastComponent!: ToastComponent;

‎src/app/component/register/register.component.html

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
<app-toast #toast></app-toast>
21
<div class="full-page-container">
3-
<div class="">
4-
<div class="">
5-
<div class="container h-vh d-flex justify-content-center align-items-center flex-column">
6-
<div class="d-flex justify-content-center align-items-center mb-3">
7-
<span> <!-- SVG Logo here --> </span>
8-
<h2 class="ml-2 text-bg mb-0"><strong>Sign Up</strong></h2>
9-
</div>
10-
<div class="row w-100 justify-content-center">
11-
<div class="card card-signup mb-3">
2+
<app-toast #toast></app-toast>
3+
<div class="d-flex justify-content-center align-items-center flex-column">
4+
<div class="justify-content-center">
5+
<div class="card card-signup">
126
<div class="card-body">
13-
<form [formGroup]="registerForm" (ngSubmit)="register()">
7+
<h2 class="my-1 auth-form-title"><strong>Sign Up</strong></h2>
8+
<br>
9+
<form [formGroup]="registerForm" (ngSubmit)="register()" class="auth-form-box">
1410
<div class="row">
1511
<div class="form-group col-md-6">
1612
<label>First Name</label>
@@ -78,21 +74,16 @@ <h2 class="ml-2 text-bg mb-0"><strong>Sign Up</strong></h2>
7874
<small class="text-danger" *ngIf="f['password'].errors?.['minlength']">Password must be at least 6 characters</small>
7975
</div>
8076
</div>
77+
<br>
8178
<div class="text-center">
82-
<button type="submit" class="btn btn-primary" [disabled]="!registerForm.valid">Sign Up</button>
79+
<button type="submit" class="auth-button" [disabled]="!registerForm.valid">Sign Up</button>
80+
</div>
81+
<div class="d-flex justify-content-center register">
82+
<p class="">Already have an account? <a routerLink="/login">Log In</a></p>
8383
</div>
8484
</form>
8585
</div>
8686
</div>
8787
</div>
88-
<div class="d-flex justify-content-center">
89-
<span class="mr-2">Already have an account?</span>
90-
<a routerLink="/login">Log In</a>
91-
</div>
9288
</div>
93-
</div>
94-
<div class="footer">
95-
<!-- Footer content -->
96-
</div>
97-
</div>
9889
</div>
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,59 @@
1-
import {Component, OnInit, ViewChild} from '@angular/core';
1+
import {Component, OnInit, ViewChild} from '@angular/core';
22
import { FormGroup, FormControl, Validators } from '@angular/forms';
3-
import {Router} from "@angular/router";
4-
import {ToastComponent} from "../toast/toast.component";
5-
import {AuthService} from "../../services/auth.service";
3+
import {Router} from "@angular/router";
4+
import {ToastComponent} from "../toast/toast.component";
5+
import {AuthService} from "../../services/auth.service";
66

77
@Component({
88
selector: 'app-register',
99
templateUrl: './register.component.html',
10-
styleUrls: ['./register.component.css','../../app.component.css']
10+
styleUrls: ['./register.component.css']
1111
})
1212
export class RegisterComponent implements OnInit {
13+
// Form Group for registration
1314
registerForm: FormGroup;
15+
16+
// Reference to the ToastComponent for displaying messages
1417
@ViewChild('toast') toastComponent!: ToastComponent;
1518

1619
constructor(private authService: AuthService, private router: Router) {
20+
// Initialize the registration form with form controls
1721
this.registerForm = new FormGroup({
1822
firstname: new FormControl('', [Validators.required, Validators.minLength(2)]),
1923
lastname: new FormControl('', [Validators.required, Validators.minLength(2)]),
20-
company: new FormControl('',),
24+
company: new FormControl(''),
2125
email: new FormControl('', [Validators.required, Validators.email]),
2226
password: new FormControl('', [Validators.required, Validators.minLength(6)])
2327
});
2428
}
2529

30+
// Display toast messages for user feedback
2631
showToast(message: string, type: 'success' | 'danger' | 'info' | 'warning') {
2732
this.toastComponent.display(message, type);
2833
}
2934

3035
ngOnInit(): void {
36+
// Initialization logic if needed
3137
}
3238

39+
// Handle user registration
3340
register() {
41+
// Check if the registration form is valid
3442
if (this.registerForm.valid) {
43+
// Call the AuthService to register the user
3544
this.authService.register(this.registerForm.value).subscribe({
3645
next: (response) => {
37-
46+
// Redirect to login page upon successful registration
3847
this.router.navigate(['/login']);
3948
},
4049
error: (error) => {
41-
// Handle error here
50+
// Handle error here, if needed
51+
console.error('Registration error:', error);
4252
}
4353
});
4454
}
4555
}
4656

57+
// Getter to easily access form controls in the template
4758
get f() { return this.registerForm.controls; }
4859
}

‎src/app/guards/auth.guard.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router';
2+
import { Injectable } from '@angular/core';
3+
import { Observable } from 'rxjs';
4+
import { AuthService } from '../services/auth.service';
5+
6+
@Injectable({
7+
providedIn: 'root',
8+
})
9+
export class AuthGuard implements CanActivate {
10+
11+
constructor(private authService: AuthService, private router: Router) {}
12+
13+
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
14+
return new Observable<boolean>((observer) => {
15+
this.authService.getAuthenticatedUser().subscribe({
16+
next: (authenticated: boolean) => {
17+
if (authenticated) {
18+
observer.next(true); // User is authenticated, allow access
19+
observer.complete();
20+
} else {
21+
this.router.navigate(['/login']); // User is not authenticated, redirect to the login page
22+
observer.next(false);
23+
observer.complete();
24+
}
25+
},
26+
error: (error) => {
27+
this.router.navigate(['/login']); // An error occurred, redirect to the login page
28+
observer.next(false);
29+
observer.complete();
30+
},
31+
});
32+
});
33+
}
34+
}

‎src/assets/background.jpg

1.4 MB
Loading[フレーム]

‎src/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
</head>
1313
<body>
1414
<app-root></app-root>
15+
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
1516
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.min.js" integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+" crossorigin="anonymous"></script>
1617
</body>
1718
</html>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /