From fdbca461a931db7b4de1611c367444b0b07a3730 Mon Sep 17 00:00:00 2001
From: chia-yh <0.chiayuhong.0@gmail.com>
Date: Tue, 11 Jul 2023 15:14:44 +0800
Subject: [PATCH 01/20] Add minimal login component
---
src/app/auth/login/login.component.css | 18 +++++++++++++++
src/app/auth/login/login.component.html | 4 ++++
src/app/auth/login/login.component.ts | 30 +++++++++++++++++++++++++
3 files changed, 52 insertions(+)
create mode 100644 src/app/auth/login/login.component.css
create mode 100644 src/app/auth/login/login.component.html
create mode 100644 src/app/auth/login/login.component.ts
diff --git a/src/app/auth/login/login.component.css b/src/app/auth/login/login.component.css
new file mode 100644
index 00000000..dec75881
--- /dev/null
+++ b/src/app/auth/login/login.component.css
@@ -0,0 +1,18 @@
+.login-button {
+ background: #f7fcfe;
+ line-height: 45px;
+ border: 1px solid currentColor;
+ width: 100%;
+}
+
+.logo {
+ align-items: center;
+ display: inline-flex;
+ margin: 0 3px 3px 3px;
+}
+
+.github-logo {
+ font-size: 20px;
+ width: 20px;
+ height: 20px;
+}
diff --git a/src/app/auth/login/login.component.html b/src/app/auth/login/login.component.html
new file mode 100644
index 00000000..244d4e60
--- /dev/null
+++ b/src/app/auth/login/login.component.html
@@ -0,0 +1,4 @@
+
diff --git a/src/app/auth/login/login.component.ts b/src/app/auth/login/login.component.ts
new file mode 100644
index 00000000..1163b15a
--- /dev/null
+++ b/src/app/auth/login/login.component.ts
@@ -0,0 +1,30 @@
+import { Component, OnInit } from '@angular/core';
+import { AuthService, AuthState } from '../../core/services/auth.service';
+import { ErrorHandlingService } from '../../core/services/error-handling.service';
+import { LoggingService } from '../../core/services/logging.service';
+
+@Component({
+ selector: 'app-auth-login',
+ templateUrl: './login.component.html',
+ styleUrls: ['./login.component.css']
+})
+
+export class LoginComponent implements OnInit {
+ constructor(
+ private authService: AuthService,
+ private errorHandlingService: ErrorHandlingService,
+ private logger: LoggingService
+ ) {}
+
+ ngOnInit() {}
+
+ startLoginProcess() {
+ this.logger.info('LoginComponent: Beginning login process');
+ try {
+ this.authService.startOAuthProcess();
+ } catch (error) {
+ this.errorHandlingService.handleError(error);
+ this.authService.changeAuthState(AuthState.NotAuthenticated);
+ }
+ }
+}
From 03137a31d8f82f8cc1ec8157654cd160338f8c2b Mon Sep 17 00:00:00 2001
From: chia-yh <0.chiayuhong.0@gmail.com>
Date: Wed, 12 Jul 2023 11:57:21 +0800
Subject: [PATCH 02/20] Change auth process to login before selecting repo
---
src/app/app.module.ts | 13 ++++-
src/app/auth/auth.component.html | 17 ++++--
src/app/auth/auth.component.ts | 15 ++++++
src/app/auth/auth.module.ts | 10 +++-
.../confirm-login/confirm-login.component.ts | 35 +------------
src/app/auth/login/login.component.html | 2 +-
.../session-selection.component.ts | 12 +----
src/app/core/services/auth.service.ts | 52 ++++++++++++++++++-
.../factories/factory.auth.service.ts | 15 +++++-
9 files changed, 117 insertions(+), 54 deletions(-)
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 7a330a7a..2e5653f8 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -72,7 +72,18 @@ import { SharedModule } from './shared/shared.module';
{
provide: AuthService,
useFactory: AuthServiceFactory,
- deps: [Router, NgZone, GithubService, UserService, IssueService, PhaseService, GithubEventService, Title, LoggingService]
+ deps: [
+ Router,
+ NgZone,
+ GithubService,
+ UserService,
+ IssueService,
+ PhaseService,
+ GithubEventService,
+ Title,
+ ErrorHandlingService,
+ LoggingService
+ ]
},
{
provide: IssueService,
diff --git a/src/app/auth/auth.component.html b/src/app/auth/auth.component.html
index ee113cc7..7fded9ca 100644
--- a/src/app/auth/auth.component.html
+++ b/src/app/auth/auth.component.html
@@ -1,13 +1,17 @@
+
Confirm Login Account
- Session on {{ currentSessionOrg }}
+
@@ -24,3 +28,8 @@
+
+
diff --git a/src/app/auth/auth.component.ts b/src/app/auth/auth.component.ts
index a30274e5..c9a04eb5 100644
--- a/src/app/auth/auth.component.ts
+++ b/src/app/auth/auth.component.ts
@@ -25,6 +25,8 @@ export class AuthComponent implements OnInit, OnDestroy {
currentUserName: string;
urlEncodedSessionName: string;
urlEncodedRepo: string;
+ sessionSetupState: boolean;
+ sessionSetupStateSubscription: Subscription;
sessionInformation: string;
constructor(
@@ -51,6 +53,7 @@ export class AuthComponent implements OnInit, OnDestroy {
}
this.initAccessTokenSubscription();
this.initAuthStateSubscription();
+ this.initSessionSetupStateSubscription();
this.createProfileFromUrlQueryParams();
this.getRepoFromUrlQueryParams();
if (oauthCode) {
@@ -134,6 +137,10 @@ export class AuthComponent implements OnInit, OnDestroy {
return this.authState === AuthState.ConfirmOAuthUser;
}
+ isSettingUpSession(): boolean {
+ return this.sessionSetupState;
+ }
+
get currentSessionOrg(): string {
if (!this.sessionInformation) {
// Retrieve org details of session information from local storage
@@ -158,6 +165,14 @@ export class AuthComponent implements OnInit, OnDestroy {
});
}
+ private initSessionSetupStateSubscription() {
+ this.sessionSetupStateSubscription = this.authService.sessionSetupState.subscribe((state) => {
+ this.ngZone.run(() => {
+ this.sessionSetupState = state;
+ });
+ });
+ }
+
private initAccessTokenSubscription() {
this.accessTokenSubscription = this.authService.accessToken
.pipe(
diff --git a/src/app/auth/auth.module.ts b/src/app/auth/auth.module.ts
index 901bc391..46d81bbf 100644
--- a/src/app/auth/auth.module.ts
+++ b/src/app/auth/auth.module.ts
@@ -4,12 +4,20 @@ import { SharedModule } from '../shared/shared.module';
import { AuthRoutingModule } from './auth-routing.module';
import { AuthComponent } from './auth.component';
import { ConfirmLoginComponent } from './confirm-login/confirm-login.component';
+import { LoginComponent } from './login/login.component';
import { JsonParseErrorDialogComponent } from './profiles/json-parse-error-dialog/json-parse-error-dialog.component';
import { ProfilesComponent } from './profiles/profiles.component';
import { SessionSelectionComponent } from './session-selection/session-selection.component';
@NgModule({
imports: [AuthRoutingModule, SharedModule, CommonModule],
- declarations: [AuthComponent, ProfilesComponent, JsonParseErrorDialogComponent, ConfirmLoginComponent, SessionSelectionComponent]
+ declarations: [
+ AuthComponent,
+ ProfilesComponent,
+ JsonParseErrorDialogComponent,
+ LoginComponent,
+ ConfirmLoginComponent,
+ SessionSelectionComponent
+ ]
})
export class AuthModule {}
diff --git a/src/app/auth/confirm-login/confirm-login.component.ts b/src/app/auth/confirm-login/confirm-login.component.ts
index 95df775e..a41a0d95 100644
--- a/src/app/auth/confirm-login/confirm-login.component.ts
+++ b/src/app/auth/confirm-login/confirm-login.component.ts
@@ -1,9 +1,6 @@
import { Component, Input, OnInit } from '@angular/core';
import { Router } from '@angular/router';
-import { Observable, of } from 'rxjs';
-import { mergeMap } from 'rxjs/operators';
import { Phase } from '../../core/models/phase.model';
-import { Repo } from '../../core/models/repo.model';
import { AuthService, AuthState } from '../../core/services/auth.service';
import { ErrorHandlingService } from '../../core/services/error-handling.service';
import { GithubService } from '../../core/services/github.service';
@@ -23,12 +20,9 @@ export class ConfirmLoginComponent implements OnInit {
constructor(
private authService: AuthService,
- private phaseService: PhaseService,
private userService: UserService,
private errorHandlingService: ErrorHandlingService,
- private githubEventService: GithubEventService,
private logger: LoggingService,
- private router: Router,
public githubService: GithubService
) {}
@@ -44,42 +38,16 @@ export class ConfirmLoginComponent implements OnInit {
this.authService.startOAuthProcess();
}
- /**
- * Handles the clean up required after authentication and setting up of user data is completed.
- */
- handleAuthSuccess() {
- this.authService.setTitleWithPhaseDetail();
- this.router.navigateByUrl(Phase.issuesViewer);
- this.authService.changeAuthState(AuthState.Authenticated);
- }
-
/**
* Will complete the process of logging in the given user.
*/
completeLoginProcess(): void {
this.authService.changeAuthState(AuthState.AwaitingAuthentication);
- this.phaseService.initializeCurrentRepository();
- this.logger.info(`ConfirmLoginComponent: Current repo is ${this.phaseService.currentRepo}`);
this.userService
.createUserModel(this.username)
- .pipe(
- mergeMap(() => {
- const currentRepo = this.phaseService.currentRepo;
- if (Repo.isInvalidRepoName(currentRepo)) {
- return of(false);
- }
- return this.githubService.isRepositoryPresent(currentRepo.owner, currentRepo.name);
- }),
- mergeMap((isValidRepository) => {
- if (!isValidRepository) {
- return new Observable();
- }
- return this.githubEventService.setLatestChangeEvent();
- })
- )
.subscribe(
() => {
- this.handleAuthSuccess();
+ this.authService.changeSessionSetupState(true);
},
(error) => {
this.authService.changeAuthState(AuthState.NotAuthenticated);
@@ -87,6 +55,5 @@ export class ConfirmLoginComponent implements OnInit {
this.logger.info(`ConfirmLoginComponent: Completion of login process failed with an error: ${error}`);
}
);
- this.handleAuthSuccess();
}
}
diff --git a/src/app/auth/login/login.component.html b/src/app/auth/login/login.component.html
index 244d4e60..afcde449 100644
--- a/src/app/auth/login/login.component.html
+++ b/src/app/auth/login/login.component.html
@@ -1,4 +1,4 @@
-