Skip to content

Commit

Permalink
Move wca auth/login to Cadastrar page
Browse files Browse the repository at this point in the history
  • Loading branch information
diogojs committed Aug 27, 2024
1 parent 8a04027 commit 9e3e25e
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 85 deletions.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
<app-root></app-root>
</main>
</div>
<script src="polyfills-SCHOHYNV.js" type="module"></script><script src="main-ARAQC6G5.js" type="module"></script></body>
<script src="polyfills-SCHOHYNV.js" type="module"></script><script src="main-ALGAWJX7.js" type="module"></script></body>
</html>
8 changes: 8 additions & 0 deletions docs/main-ALGAWJX7.js

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions docs/main-ARAQC6G5.js

This file was deleted.

8 changes: 7 additions & 1 deletion website/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
"sourceMap": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.development.ts"
}
]
}
},
"defaultConfiguration": "production"
Expand Down
6 changes: 5 additions & 1 deletion website/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component } from '@angular/core';
import { RouterLink, RouterLinkActive, RouterOutlet } from '@angular/router';
import { RouterOutlet } from '@angular/router';
import { AuthenticationService } from './services/authentication.service';

@Component({
selector: 'app-root',
Expand All @@ -10,4 +11,7 @@ import { RouterLink, RouterLinkActive, RouterOutlet } from '@angular/router';
})
export class AppComponent {
title = 'website';

constructor(private authService: AuthenticationService) {
}
}
2 changes: 0 additions & 2 deletions website/src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Routes } from '@angular/router';
import { HomeRankingsComponent } from './home-rankings/home-rankings.component';
import { WCAAuthComponent } from './wca-auth/wca-auth.component';
import { UserRegistrationComponent } from './user-registration/user-registration.component';

export const routes: Routes = [
{ path: '', component: HomeRankingsComponent },
{ path: 'login', component: WCAAuthComponent },
{ path: 'register', component: UserRegistrationComponent },
];
3 changes: 1 addition & 2 deletions website/src/app/home-rankings/home-rankings.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<p>Home Rankings</p>
<button (click)="login()" *ngIf="!isLogged()">Login</button>
<p *ngIf="isLogged()">Logado como: {{ getCurrentWcaId() }}</p>
<p><a routerLink="register" routerLinkActive="true">Cadastrar competidor</a></p>
<section class="cubingEvents">
<div>Modalidade</div>
<button (click)="changeEventTo('333')">333</button>
Expand Down
24 changes: 1 addition & 23 deletions website/src/app/home-rankings/home-rankings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,10 @@ export class HomeRankingsComponent implements OnInit {
currentState: string = "";
currentKindOfResult: string = "single";

constructor(private authService: AuthenticationService) {}
constructor() {}

ngOnInit(): void {
// this.results = dataJson;
if (sessionStorage.getItem("is_getting_token") !== null) {
sessionStorage.removeItem("is_getting_token");
this.authService.requestToken();
}

this.results = {
"333":
[
Expand Down Expand Up @@ -172,21 +167,4 @@ export class HomeRankingsComponent implements OnInit {
this.currentKindOfResult = kind;
this.updateFilteredResults();
}

login(): void {
if (this.authService.isLogged()) {
return;
}
else {
this.authService.login();
}
}

isLogged(): boolean {
return this.authService.isLogged();
}

getCurrentWcaId(): string {
return sessionStorage.getItem("wca_id")!;
}
}
14 changes: 8 additions & 6 deletions website/src/app/services/authentication.service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { environment } from '../../environments/environment';

@Injectable({
providedIn: 'root'
})
export class AuthenticationService {
api_code: string = "";
token: string = "";
// access_token_url: string = "https://www.worldcubeassociation.org/oauth/token"
access_token_api: string = "/oauth/token";
access_token_api: string = "/oauth/token/";
data_url: string = "https://www.worldcubeassociation.org/api/v0/me"

constructor(
Expand All @@ -21,19 +21,21 @@ export class AuthenticationService {
let params = query['params'];
if (params) {
this.api_code = params['code'];
if (this.api_code) {
console.log(`api_code: ${this.api_code}`);
this.requestToken();
}
}
}
)
}

login(): void {
console.log("doing login");
if (this.api_code == "" || this.api_code == undefined) {
let redirectUrl = `https://www.worldcubeassociation.org/oauth/authorize?client_id=OS6jVGAcxX_MwpLawxS1hRq8IVNEfu-FAthO72ARdyw&redirect_uri=${window.location.origin + window.location.pathname}&response_type=code&scope=public`;
console.log("doing login");
let redirectUrl = `https://www.worldcubeassociation.org/oauth/authorize?client_id=OS6jVGAcxX_MwpLawxS1hRq8IVNEfu-FAthO72ARdyw&redirect_uri=${environment.APP_URL}&response_type=code&scope=public`;
sessionStorage.setItem("is_getting_token", "true");
window.location.href = redirectUrl;
} else {
this.requestToken();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
<p>user-registration works!</p>
<section *ngIf="!isLogged()">
<p>Você precisa logar na WCA para poder se cadastrar no Ranking.</p>
<button (click)="login()">Login</button>
</section>

<section class="cadastro" *ngIf="isLogged()">
<p>Logado como: {{ getCurrentWcaId() }}</p>
<div>
form<br>
dropdown com os estados<br>
<button>Cadastrar</button><br>
</div>
</section>
23 changes: 21 additions & 2 deletions website/src/app/user-registration/user-registration.component.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
import { HttpClient } from '@angular/common/http';
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { AuthenticationService } from '../services/authentication.service';
import { CommonModule } from '@angular/common';
//import wcaSecrets from '../../../wcaauth.json'

@Component({
selector: 'app-user-registration',
standalone: true,
imports: [],
imports: [CommonModule],
templateUrl: './user-registration.component.html',
styleUrl: './user-registration.component.scss'
})
export class UserRegistrationComponent {
constructor() { }
constructor(private authService: AuthenticationService) { }

login(): void {
if (this.authService.isLogged()) {
return;
}
else {
this.authService.login();
}
}

isLogged(): boolean {
return this.authService.isLogged();
}

getCurrentWcaId(): string {
return sessionStorage.getItem("wca_id")!;
}
}
3 changes: 0 additions & 3 deletions website/src/app/wca-auth/wca-auth.component.html

This file was deleted.

Empty file.
23 changes: 0 additions & 23 deletions website/src/app/wca-auth/wca-auth.component.spec.ts

This file was deleted.

12 changes: 0 additions & 12 deletions website/src/app/wca-auth/wca-auth.component.ts

This file was deleted.

4 changes: 4 additions & 0 deletions website/src/environments/environment.development.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const environment = {
production: false,
APP_URL: "http://localhost:4200"
};
4 changes: 4 additions & 0 deletions website/src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const environment = {
production: true,
APP_URL: "https://diogojs.github.io/wca_statistics/"
};

0 comments on commit 9e3e25e

Please sign in to comment.