From c04e1321eff1f78620651d12308a1f48167a98e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E2=96=88=E2=96=88=E2=96=88=E2=96=88=E2=96=88?= Date: Thu, 4 Jul 2024 14:46:38 -0400 Subject: [PATCH 1/2] Updating link to be more consistent with normal site standards --- src/src/app/app.routes.ts | 22 +++++++++++----------- src/src/app/view/home/home.component.ts | 24 ++++++++++++------------ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/src/app/app.routes.ts b/src/src/app/app.routes.ts index 76234de..938e24e 100644 --- a/src/src/app/app.routes.ts +++ b/src/src/app/app.routes.ts @@ -1,13 +1,13 @@ -import { Routes } from '@angular/router'; -import { NotFoundComponent } from "./view/not-found/not-found.component"; -import { LoginLandingComponent } from "./view/login-landing/login-landing.component"; -import { HomeComponent } from "./view/home/home.component"; -import { authGuard } from "./middleware/auth.guard"; -import { VmManagerComponent } from './view/vm-manager/vm-manager.component'; -import { LoginComponent } from './view/login/login.component'; -import { TwitchBotIndexComponent } from './view/twitch/twitch-bot-index/twitch-bot-index.component'; -import { TwitchBotConfigComponent } from './view/twitch/twitch-bot-config/twitch-bot-config.component'; -import { ImdbSearchComponent } from './view/imdb-search/imdb-search.component'; +import {Routes} from '@angular/router'; +import {NotFoundComponent} from "./view/not-found/not-found.component"; +import {LoginLandingComponent} from "./view/login-landing/login-landing.component"; +import {HomeComponent} from "./view/home/home.component"; +import {authGuard} from "./middleware/auth.guard"; +import {VmManagerComponent} from './view/vm-manager/vm-manager.component'; +import {LoginComponent} from './view/login/login.component'; +import {TwitchBotIndexComponent} from './view/twitch/twitch-bot-index/twitch-bot-index.component'; +import {TwitchBotConfigComponent} from './view/twitch/twitch-bot-config/twitch-bot-config.component'; +import {ImdbSearchComponent} from './view/imdb-search/imdb-search.component'; export const routes: Routes = [ {path: '', component: HomeComponent}, @@ -15,7 +15,7 @@ export const routes: Routes = [ {path: 'user/login', component: LoginLandingComponent}, {path: 'home', component: HomeComponent}, {path: 'vm-admin', component: VmManagerComponent, canActivate: [authGuard]}, - {path: 'twitch-bot/index', component: TwitchBotIndexComponent}, + {path: 'twitch-bot', component: TwitchBotIndexComponent}, {path: 'twitch-bot/config', component: TwitchBotConfigComponent}, {path: 'imdb-search', component: ImdbSearchComponent}, {path: '**', component: NotFoundComponent}, diff --git a/src/src/app/view/home/home.component.ts b/src/src/app/view/home/home.component.ts index 5008a41..e44730d 100644 --- a/src/src/app/view/home/home.component.ts +++ b/src/src/app/view/home/home.component.ts @@ -1,14 +1,14 @@ -import { Component, OnInit } from '@angular/core'; -import { LogoComponent } from "../../common/components/logo/logo.component"; -import { NullinsideService } from "../../service/nullinside.service"; -import { VM_ADMIN } from "../../common/constants"; -import { WebsiteApp } from "../../common/interface/website-app"; -import { Router } from '@angular/router'; -import { MatAnchor, MatButton } from '@angular/material/button'; -import { StandardBannerComponent } from '../../common/components/standard-banner/standard-banner.component'; -import { LoadingIconComponent } from "../../common/components/loading-icon/loading-icon.component"; -import { catchError, forkJoin, Observable, of } from "rxjs"; -import { UserRolesResponse } from "../../common/interface/user-roles-response"; +import {Component, OnInit} from '@angular/core'; +import {LogoComponent} from "../../common/components/logo/logo.component"; +import {NullinsideService} from "../../service/nullinside.service"; +import {VM_ADMIN} from "../../common/constants"; +import {WebsiteApp} from "../../common/interface/website-app"; +import {Router} from '@angular/router'; +import {MatAnchor, MatButton} from '@angular/material/button'; +import {StandardBannerComponent} from '../../common/components/standard-banner/standard-banner.component'; +import {LoadingIconComponent} from "../../common/components/loading-icon/loading-icon.component"; +import {catchError, forkJoin, Observable, of} from "rxjs"; +import {UserRolesResponse} from "../../common/interface/user-roles-response"; @Component({ selector: 'app-home', @@ -39,7 +39,7 @@ export class HomeComponent implements OnInit { { displayName: 'Twitch Bot', description: 'The nullinside anti-bot Twitch bot.', - url: 'twitch-bot/index', + url: 'twitch-bot', params: undefined } ]; From 7dc6e40e20296a944d39b8e36cd10bf501286d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E2=96=88=E2=96=88=E2=96=88=E2=96=88=E2=96=88?= Date: Thu, 4 Jul 2024 14:47:12 -0400 Subject: [PATCH 2/2] Forcing re-login for bookmarkers Closes #32 --- .../twitch-bot-config.component.ts | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/src/app/view/twitch/twitch-bot-config/twitch-bot-config.component.ts b/src/src/app/view/twitch/twitch-bot-config/twitch-bot-config.component.ts index 0d356bf..48d6292 100644 --- a/src/src/app/view/twitch/twitch-bot-config/twitch-bot-config.component.ts +++ b/src/src/app/view/twitch/twitch-bot-config/twitch-bot-config.component.ts @@ -2,7 +2,7 @@ import {Component, OnDestroy, OnInit} from '@angular/core'; import {LogoComponent} from '../../../common/components/logo/logo.component'; import {MatButton} from '@angular/material/button'; import {NullinsideTwitchBotService} from "../../../service/nullinside-twitch-bot.service"; -import {ActivatedRoute, ParamMap} from "@angular/router"; +import {ActivatedRoute, ParamMap, Router} from "@angular/router"; import {Errors} from "../../login-landing/errors"; import {HttpErrorResponse} from "@angular/common/http"; import {NullinsideService} from "../../../service/nullinside.service"; @@ -13,6 +13,7 @@ import {MatCheckbox} from "@angular/material/checkbox"; import {TwitchBotFaqComponent} from "../twitch-bot-faq/twitch-bot-faq.component"; import {MatSnackBar} from "@angular/material/snack-bar"; import {FormsModule} from "@angular/forms"; +import {Location} from "@angular/common"; @Component({ selector: 'app-twitch-bot-config', @@ -41,6 +42,8 @@ export class TwitchBotConfigComponent implements OnInit, OnDestroy { constructor(private twitchBotApi: NullinsideTwitchBotService, private api: NullinsideService, private snackBar: MatSnackBar, + private location: Location, + private router: Router, private route: ActivatedRoute) { } @@ -67,16 +70,30 @@ export class TwitchBotConfigComponent implements OnInit, OnDestroy { return; } + // Get the token, if there isn't one then they didn't get here by hitting the login button. Lets send them back + // to the login page if that's the case. It'll help us keep people synced on updates the permissions we request + // from their tokens. const token = params.get('token'); - if (token) { - localStorage.setItem('auth-token', token); - this.api.validateToken(token).subscribe({ - error: (_: HttpErrorResponse) => { - this.onLoginFailed(); - } - }); + if (!token) { + this.router.navigate(['twitch-bot']); + return; } + // Save the token and make sure its valid. + localStorage.setItem('auth-token', token); + this.api.validateToken(token).subscribe({ + error: (_: HttpErrorResponse) => { + this.onLoginFailed(); + } + }); + + // Kind of a workaround to remove the token from the query parameters in the url. The reason for this is + // if someone wants to bookmark the page we don't want to leave that in there. A different site layout will + // make this unnecessary. + const url = this.router.createUrlTree([], {relativeTo: this.route}).toString(); + this.location.go(url); + + // Check if the bot account is modded. If it isn't, we can offer to mod it. this.twitchBotApi.getIsMod().subscribe({ next: response => { this.botIsMod = response.isMod; @@ -88,6 +105,7 @@ export class TwitchBotConfigComponent implements OnInit, OnDestroy { } }); + // Get the person's existing configuration. this.twitchBotApi.getConfig().subscribe({ next: response => { this.botEnabled = response.isEnabled;