Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
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},
{path: 'user/auth', component: LoginComponent},
{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},
Expand Down
24 changes: 12 additions & 12 deletions src/src/app/view/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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
}
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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',
Expand Down Expand Up @@ -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) {
}

Expand All @@ -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;
Expand All @@ -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;
Expand Down