diff --git a/app/src/app/components/auth/username-creation/username-creation.component.ts b/app/src/app/components/auth/username-creation/username-creation.component.ts
index 1a014b3..e86e86b 100644
--- a/app/src/app/components/auth/username-creation/username-creation.component.ts
+++ b/app/src/app/components/auth/username-creation/username-creation.component.ts
@@ -1,8 +1,9 @@
import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
-import { ActivatedRoute } from '@angular/router';
import { GithubUser } from 'src/app/models/github-user.model';
-import { AuthGithubService } from 'src/app/services/auth-github.service';
+import { GoogleUser } from 'src/app/models/google-user.model';
+import { AuthGithubService } from 'src/app/services/auth/auth-github.service';
+import { AuthGoogleService } from 'src/app/services/auth/auth-google.service';
@Component({
selector: 'app-username-creation',
@@ -17,10 +18,12 @@ export class UsernameCreationComponent {
warning!: string
connected: boolean = false
loader: boolean = false
+ failure!: string
constructor(
private formBuilder: FormBuilder,
private authGithub: AuthGithubService,
+ private authGoogle: AuthGoogleService
) {
this.createUsernameForm = this.formBuilder.group({
username: ['', [Validators.required, Validators.pattern(/^[A-Za-z]+$/)]],
@@ -59,50 +62,90 @@ export class UsernameCreationComponent {
proceedWithUsernameCreation(username: string) {
this.username = username
const access_token = localStorage.getItem('token');
+ const origin = localStorage.getItem('come_from');
if (access_token) {
- if (localStorage.getItem('access_token')) {
- this.authGithub.githubToken(access_token!).subscribe((data: any) => {
-
- this.localUser(data)
- this.connected = true;
-
- const userData: GithubUser = {
- username: this.createUsernameForm.value.username.toLowerCase(),
- github_username: data.login,
- name: data.name || '',
- email: data.email || '',
- come_from: 'github',
- location: data.location || '',
- blog: data.blog || '',
- twitter_username: data.twitter_username || '',
- };
-
- this.authGithub.saveGithubUser(userData).subscribe(
- (data: any) => {
- localStorage.setItem('catch_him', 'false');
- localStorage.setItem('warning', 'false');
- window.location.href = this.username
- },
- (error: any) => {
- console.error(error);
- const errorMessage = error.error?.detail || 'An error occurred';
- this.error = errorMessage;
- }
- )
- })
+ if (origin == 'github') {
+ this.githubProceed(access_token)
+ }
+
+ if (origin == 'google') {
+ this.googleProceed()
}
+ } else {
+ this.failure = "An error occurred";
+ this.loader = false
}
}
+ githubProceed(access_token: string) {
+ localStorage.setItem('username', this.username);
+ this.authGithub.githubToken(access_token!).subscribe((data: any) => {
+
+ this.localUser(data)
+ this.connected = true;
+
+ const userData: GithubUser = {
+ username: this.createUsernameForm.value.username.toLowerCase(),
+ github_username: data.login,
+ name: data.name || '',
+ email: data.email || '',
+ come_from: 'github',
+ location: data.location || '',
+ blog: data.blog || '',
+ twitter_username: data.twitter_username || '',
+ };
+
+ this.authGithub.saveGithubUser(userData).subscribe(
+ (data: any) => {
+ localStorage.setItem('catch_him', 'false');
+ localStorage.setItem('warning', 'false');
+ window.location.href = this.username
+ },
+ (error: any) => {
+ console.error(error);
+ const errorMessage = error.error?.detail || 'An error occurred';
+ this.error = errorMessage;
+ }
+ )
+ })
+ }
+
+ googleProceed() {
+ localStorage.setItem('username', this.username);
+
+ const userData: GoogleUser = {
+ username: this.createUsernameForm.value.username.toLowerCase(),
+ name: localStorage.getItem('name') || '',
+ email: localStorage.getItem('email') || '',
+ come_from: localStorage.getItem('come_from') || '',
+ verified_email: localStorage.getItem('verified_email') || 'false',
+ creation_month: localStorage.getItem('creation_month') || '',
+ creation_year: localStorage.getItem('creation_year') || '',
+ };
+
+ this.authGoogle.saveGoogleUser(userData).subscribe(
+ (data: any) => {
+ localStorage.setItem('catch_him', 'false');
+ localStorage.setItem('warning', 'false');
+ window.location.href = this.username
+ },
+ (error: any) => {
+ console.error(error);
+ const errorMessage = error.error?.detail || 'An error occurred';
+ this.error = errorMessage;
+ }
+ )
+ }
+
+
localUser(data: any) {
localStorage.setItem('username', this.createUsernameForm.value.username.toLowerCase());
- localStorage.setItem('github_username', data.login);
+ if (data.login) localStorage.setItem('github_username', data.login);
localStorage.setItem('name', data.name);
localStorage.setItem('email', data.email);
localStorage.setItem('come_from', 'github');
localStorage.setItem('location', data.location);
- localStorage.setItem('blog', 'blog');
localStorage.setItem('twitter_username', data.twitter_username);
}
}
\ No newline at end of file
diff --git a/app/src/app/components/home/header/header.component.ts b/app/src/app/components/home/header/header.component.ts
index aecf6a8..ef3e072 100644
--- a/app/src/app/components/home/header/header.component.ts
+++ b/app/src/app/components/home/header/header.component.ts
@@ -1,9 +1,5 @@
import { Component } from '@angular/core';
-import { ActivatedRoute } from '@angular/router';
-import { BehaviorSubject, Subscription } from 'rxjs';
-import { GithubUser } from 'src/app/models/github-user.model';
-import { AuthGithubService } from 'src/app/services/auth-github.service';
-import { AuthService } from 'src/app/services/auth.service';
+import { Subscription } from 'rxjs';
import { MenuBurgerService } from 'src/app/services/menu-burger.service';
@Component({
@@ -27,8 +23,6 @@ export class HeaderComponent {
private menuSubscription: Subscription;
constructor(
- private authGithub: AuthGithubService,
- private route: ActivatedRoute,
private menuService: MenuBurgerService
) {
diff --git a/app/src/app/components/portal/github-portal/github-portal.component.ts b/app/src/app/components/portal/github-portal/github-portal.component.ts
index 06790b9..0bc8e8f 100644
--- a/app/src/app/components/portal/github-portal/github-portal.component.ts
+++ b/app/src/app/components/portal/github-portal/github-portal.component.ts
@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
-import { AuthGithubService } from 'src/app/services/auth-github.service';
+import { AuthGithubService } from 'src/app/services/auth/auth-github.service';
@Component({
selector: 'app-github-portal',
diff --git a/app/src/app/components/portal/google-portal/google-portal.component.html b/app/src/app/components/portal/google-portal/google-portal.component.html
new file mode 100644
index 0000000..aeeb65a
--- /dev/null
+++ b/app/src/app/components/portal/google-portal/google-portal.component.html
@@ -0,0 +1,3 @@
+
\ No newline at end of file
diff --git a/app/src/app/components/portal/google-portal/google-portal.component.ts b/app/src/app/components/portal/google-portal/google-portal.component.ts
new file mode 100644
index 0000000..4fedfe4
--- /dev/null
+++ b/app/src/app/components/portal/google-portal/google-portal.component.ts
@@ -0,0 +1,62 @@
+import { Component } from '@angular/core';
+import { ActivatedRoute } from '@angular/router';
+import { AuthGoogleService } from 'src/app/services/auth/auth-google.service';
+
+@Component({
+ selector: 'app-google-portal',
+ templateUrl: './google-portal.component.html',
+ styles: [
+ ]
+})
+export class GooglePortalComponent {
+ username: string = localStorage.getItem('username') || '';
+
+ constructor(
+ private authGoogle: AuthGoogleService,
+ private route: ActivatedRoute,
+ ) { }
+
+ onGoogleLogin() {
+ this.authGoogle.googleLogin().subscribe(response => {
+ // Ici, vous pouvez gérer la redirection vers l'URL de Google, si nécessaire.
+ // Par exemple, redirigez l'utilisateur vers la page de connexion Google.
+ window.location.href = response.url; // Redirection vers Google login
+ });
+ }
+
+ ngOnInit(): void {
+ localStorage.setItem('come_from', 'google');
+
+ if (!localStorage.getItem('token')) {
+ this.route.queryParams.subscribe(params => {
+ const code = params['code'];
+
+ if (code) {
+ this.authGoogle.googleCallback(code).subscribe((data: any) => {
+ localStorage.setItem('token', data.access_token);
+ localStorage.setItem('access_token', data.access_token);
+
+ if (!data.user.username || data.user.username == '') {
+ localStorage.setItem('catch_him', 'true');
+
+ localStorage.setItem('name', data.user.name);
+ localStorage.setItem('email', data.user.email);
+ localStorage.setItem('come_from', 'google');
+ localStorage.setItem('verified_email', data.user.verified_email);
+ localStorage.setItem('creation_month', data.user.creation_month);
+ localStorage.setItem('creation_year', data.user.creation_year);
+
+
+ window.location.href = 'username-creation';
+ } else {
+ window.location.href = data.user.username;
+ localStorage.setItem('username', data.user.username);
+ this.username = data.user.username;
+ }
+ });
+ }
+ });
+ }
+ }
+
+}
diff --git a/app/src/app/components/profile/display-profile/display-profile.component.ts b/app/src/app/components/profile/display-profile/display-profile.component.ts
index 7635ca6..08dd0f4 100644
--- a/app/src/app/components/profile/display-profile/display-profile.component.ts
+++ b/app/src/app/components/profile/display-profile/display-profile.component.ts
@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
-import { AuthGithubService } from 'src/app/services/auth-github.service';
-import { AuthService } from 'src/app/services/auth.service';
+import { AuthGithubService } from 'src/app/services/auth/auth-github.service';
+import { AuthService } from 'src/app/services/auth/auth.service';
import { EditService } from 'src/app/services/edit.service';
@Component({
@@ -11,17 +11,17 @@ import { EditService } from 'src/app/services/edit.service';
})
export class DisplayProfileComponent {
edit: boolean | undefined
- name: string = localStorage.getItem('name') || ""
- username: string = localStorage.getItem('username') || ""
- email: string = localStorage.getItem('email') || ""
- come_from: string = localStorage.getItem('come_from') || ""
- location: string = localStorage.getItem('location') || ""
- blog: string = localStorage.getItem('blog') || ""
- github_username: string = localStorage.getItem('github_username') || ""
- twitter_username: string = localStorage.getItem('twitter_username') || ""
- about: string = localStorage.getItem('about') || ""
- creation_month: string = localStorage.getItem('creation_month') || ""
- creation_year: string = localStorage.getItem('creation_year') || ""
+ name: string = this.getLocalStorageItem('name') || ""
+ username: string = this.getLocalStorageItem('username') || ""
+ email: string = this.getLocalStorageItem('email') || ""
+ come_from: string = this.getLocalStorageItem('come_from') || ""
+ location: string = this.getLocalStorageItem('location') || ""
+ blog: string = this.getLocalStorageItem('blog') || ""
+ github_username: string = this.getLocalStorageItem('github_username') || ""
+ twitter_username: string = this.getLocalStorageItem('twitter_username') || ""
+ about: string = this.getLocalStorageItem('about') || ""
+ creation_month: string = this.getLocalStorageItem('creation_month') || ""
+ creation_year: string = this.getLocalStorageItem('creation_year') || ""
arobase: string = "@"
loaded: boolean = false
@@ -93,7 +93,7 @@ export class DisplayProfileComponent {
localStorage.setItem('username', data.username);
localStorage.setItem('name', data.name);
localStorage.setItem('email', data.email);
- localStorage.setItem('come_from', 'github');
+ localStorage.setItem('come_from', data.come_from);
localStorage.setItem('location', data.location);
localStorage.setItem('blog', data.blog);
localStorage.setItem('twitter_username', data.twitter_username);
@@ -105,16 +105,22 @@ export class DisplayProfileComponent {
}
setVariables(data: any) {
- this.name = data.name;
- this.username = data.username;
- this.email = data.email;
- this.come_from = data.come_from;
- this.location = data.location;
- this.blog = data.blog;
- this.twitter_username = data.twitter_username;
- this.github_username = data.github_username;
- this.about = data.about;
- this.creation_month = data.creation_month;
- this.creation_year = data.creation_year;
+ this.name = data.name || this.name;
+ this.username = data.username || this.username;
+ this.email = data.email || this.email;
+ this.come_from = data.come_from || this.come_from;
+ this.location = data.location || this.location;
+ this.blog = data.blog || this.blog;
+ this.twitter_username = data.twitter_username || this.twitter_username;
+ this.github_username = data.github_username || this.github_username;
+ this.about = data.about || this.about;
+ this.creation_month = data.creation_month || this.creation_month;
+ this.creation_year = data.creation_year || this.creation_year;
+ }
+
+ private getLocalStorageItem(key: string): string {
+ // Récupère l'élément de localStorage et retourne une valeur par défaut si non trouvé
+ const value = localStorage.getItem(key);
+ return value !== null ? value : "";
}
}
\ No newline at end of file
diff --git a/app/src/app/guard/no-auth.guard.ts b/app/src/app/guard/no-auth.guard.ts
index fc73eff..f3df14c 100644
--- a/app/src/app/guard/no-auth.guard.ts
+++ b/app/src/app/guard/no-auth.guard.ts
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router';
import { Observable } from 'rxjs';
-import { AuthenticationService } from '../services/token.service';
+import { AuthenticationService } from '../services/auth/token.service';
@Injectable({
providedIn: 'root',
diff --git a/app/src/app/guard/profile.guard.ts b/app/src/app/guard/profile.guard.ts
index 5abb171..99f2449 100644
--- a/app/src/app/guard/profile.guard.ts
+++ b/app/src/app/guard/profile.guard.ts
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
-import { AuthenticationService } from '../services/token.service';
+import { AuthenticationService } from '../services/auth/token.service';
@Injectable({
providedIn: 'root',
diff --git a/app/src/app/models/google-user.model.ts b/app/src/app/models/google-user.model.ts
new file mode 100644
index 0000000..e28204c
--- /dev/null
+++ b/app/src/app/models/google-user.model.ts
@@ -0,0 +1,9 @@
+export interface GoogleUser {
+ username ?: string;
+ name: string;
+ email: string;
+ come_from: string;
+ verified_email: string;
+ creation_month: string;
+ creation_year: string;
+}
\ No newline at end of file
diff --git a/app/src/app/services/auth-github.service.ts b/app/src/app/services/auth/auth-github.service.ts
similarity index 95%
rename from app/src/app/services/auth-github.service.ts
rename to app/src/app/services/auth/auth-github.service.ts
index 445a8cc..8c3c7d9 100644
--- a/app/src/app/services/auth-github.service.ts
+++ b/app/src/app/services/auth/auth-github.service.ts
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
-import { GithubUser } from '../models/github-user.model';
+import { GithubUser } from '../../models/github-user.model';
import { environment } from 'src/environments/environment.development';
@Injectable({
diff --git a/app/src/app/services/auth/auth-google.service.ts b/app/src/app/services/auth/auth-google.service.ts
new file mode 100644
index 0000000..c78ce24
--- /dev/null
+++ b/app/src/app/services/auth/auth-google.service.ts
@@ -0,0 +1,27 @@
+import { Injectable } from '@angular/core';
+import { HttpClient } from '@angular/common/http';
+import { Observable } from 'rxjs';
+import { environment } from 'src/environments/environment.development';
+import { GoogleUser } from 'src/app/models/google-user.model';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class AuthGoogleService {
+ constructor(private http: HttpClient) { }
+
+ saveGoogleUser(user: GoogleUser): Observable
{
+ const url = `${environment.apiUrl}/api/google-save-user`;
+ return this.http.post(url, user);
+ }
+
+ googleLogin(): Observable {
+ const url = `${environment.apiUrl}/api/google-login`;
+ return this.http.get(url, { observe: 'response', responseType: 'json' as 'json' });
+ }
+
+ googleCallback(code: string): Observable {
+ const url = `${environment.apiUrl}/api/google-portal?code=${code}`;
+ return this.http.get(url);
+ }
+}
\ No newline at end of file
diff --git a/app/src/app/services/auth.service.ts b/app/src/app/services/auth/auth.service.ts
similarity index 82%
rename from app/src/app/services/auth.service.ts
rename to app/src/app/services/auth/auth.service.ts
index 3415ed6..c04c7ab 100644
--- a/app/src/app/services/auth.service.ts
+++ b/app/src/app/services/auth/auth.service.ts
@@ -1,10 +1,10 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
-import { AuthCreateUser } from '../models/create-user.model';
-import { AuthReceiveLoginUser, AuthSendLoginUser } from '../models/login-user.model';
-import { UserProfile } from '../models/user-info.model';
import { environment } from 'src/environments/environment.development';
+import { AuthCreateUser } from 'src/app/models/create-user.model';
+import { AuthReceiveLoginUser, AuthSendLoginUser } from 'src/app/models/login-user.model';
+import { UserProfile } from 'src/app/models/user-info.model';
@Injectable({
providedIn: 'root'
diff --git a/app/src/app/services/token.service.ts b/app/src/app/services/auth/token.service.ts
similarity index 100%
rename from app/src/app/services/token.service.ts
rename to app/src/app/services/auth/token.service.ts