Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
Updates docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
djperrefort committed Mar 27, 2024
1 parent 66b748b commit 7c9e2dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/app/authentication/components/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,35 @@ export class LoginComponent implements OnInit {

constructor(private apiService: ApiService, private router: Router) {}

/**
* If the user is already authenticated, redirect them to the home page.
*/
ngOnInit(): void {
if (this.apiService.isAuthenticated()) {
this.handleSuccessfulLogin();
}
}

/**
* Passes user provided credentials to th backend API and handle the authentication result.
*/
onSubmit(): void {
this.apiService.login(this.username, this.password).subscribe({
next: () => {this.handleSuccessfulLogin()},
error: () => {this.handleUnsuccessfulLogin()}
})
}

/**
* Redirects the user to the home page upon successful login.
*/
handleSuccessfulLogin(): void {
this.router.navigateByUrl('');

Check failure on line 41 in src/app/authentication/components/login/login.component.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/app/authentication/components/login/login.component.ts#L41

Unsafe call of an `any` typed value.

Check failure on line 41 in src/app/authentication/components/login/login.component.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/app/authentication/components/login/login.component.ts#L41

Unsafe member access .navigateByUrl on an `any` value.
}

/**
* Updates page content to alert the user their login was unsuccessful.
*/
handleUnsuccessfulLogin(): void {
alert('Could not authenticate.');
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/authentication/components/logout/logout.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export class LogoutComponent implements OnInit{

constructor(private apiService: ApiService) {}

/**
* Automatically log the user out on page loa
*/
ngOnInit(): void {
this.apiService.logout()
}
Expand Down

0 comments on commit 7c9e2dc

Please sign in to comment.