Skip to content

Commit

Permalink
Update non-panel controllers to work with new services
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecDusheck committed Feb 20, 2019
1 parent 34beb54 commit 3b6c512
Show file tree
Hide file tree
Showing 38 changed files with 130 additions and 116 deletions.
16 changes: 8 additions & 8 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import {HomeComponent} from './controllers/main/home/home.component';
import {LoginComponent} from './controllers/main/login/login.component';
import {RegisterComponent} from './controllers/main/register/register.component';
import {LogoutComponent} from './controllers/main/logout/logout.component';
import {PanelHomeComponent} from './controllers/legacy/panel/panel-home/panel-home.component';
import {PanelCreateComponent} from './controllers/legacy/panel/panel-create/panel-create.component';
import {PanelMinecraftPluginsComponent} from './controllers/legacy/panel/panel-minecraft-plugins/panel-minecraft-plugins.component';
import {PanelPluginsComponent} from './controllers/legacy/panel/panel-plugins/panel-plugins.component';
import {PanelSubownersComponent} from './controllers/legacy/panel/panel-subowners/panel-subowners.component';
import {PanelSettingsComponent} from './controllers/legacy/panel/panel-settings/panel-settings.component';
import {PanelHomeComponent} from './controllers/panel/panel-home/panel-home.component';
import {PanelCreateComponent} from './controllers/panel/panel-create/panel-create.component';
import {PanelMinecraftPluginsComponent} from './controllers/panel/panel-minecraft-plugins/panel-minecraft-plugins.component';
import {PanelPluginsComponent} from './controllers/panel/panel-plugins/panel-plugins.component';
import {PanelSubownersComponent} from './controllers/panel/panel-subowners/panel-subowners.component';
import {PanelSettingsComponent} from './controllers/panel/panel-settings/panel-settings.component';
import {ProfileComponent} from './controllers/main/profile/profile.component';
import {ChangePasswordComponent} from './controllers/main/change-password/change-password.component';
import {PanelFilesComponent} from './controllers/legacy/panel/panel-files/panel-files.component';
import {PanelFileEditorComponent} from './controllers/legacy/panel/panel-file-editor/panel-file-editor.component';
import {PanelFilesComponent} from './controllers/panel/panel-files/panel-files.component';
import {PanelFileEditorComponent} from './controllers/panel/panel-file-editor/panel-file-editor.component';
import {DeauthGuardService} from './services/middleware/deauth-guard.service';
import {AuthGuardService} from './services/middleware/auth-guard.service';
import {ServerGuardService} from './services/middleware/server-guard.service';
Expand Down
18 changes: 9 additions & 9 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {HTTP_INTERCEPTORS, HttpClientModule} from '@angular/common/http';
import {LogoutComponent} from './controllers/main/logout/logout.component';
import {APIInterceptor} from './interceptors/apiinterceptor';
import {PanelHomeComponent} from './controllers/legacy/panel/panel-home/panel-home.component';
import {PanelCreateComponent} from './controllers/legacy/panel/panel-create/panel-create.component';
import {PanelMinecraftPluginsComponent} from './controllers/legacy/panel/panel-minecraft-plugins/panel-minecraft-plugins.component';
import {PanelHomeComponent} from './controllers/panel/panel-home/panel-home.component';
import {PanelCreateComponent} from './controllers/panel/panel-create/panel-create.component';
import {PanelMinecraftPluginsComponent} from './controllers/panel/panel-minecraft-plugins/panel-minecraft-plugins.component';
import {NotifierModule, NotifierOptions, NotifierService} from 'angular-notifier';
import {PanelFrameComponent} from './controllers/legacy/panel/panel-frame/panel-frame.component';
import {PanelSettingsComponent} from './controllers/legacy/panel/panel-settings/panel-settings.component';
import {PanelPluginsComponent} from './controllers/legacy/panel/panel-plugins/panel-plugins.component';
import {PanelSubownersComponent} from './controllers/legacy/panel/panel-subowners/panel-subowners.component';
import {PanelFrameComponent} from './controllers/panel/panel-frame/panel-frame.component';
import {PanelSettingsComponent} from './controllers/panel/panel-settings/panel-settings.component';
import {PanelPluginsComponent} from './controllers/panel/panel-plugins/panel-plugins.component';
import {PanelSubownersComponent} from './controllers/panel/panel-subowners/panel-subowners.component';
import {RecaptchaModule} from 'ng-recaptcha';
import {RecaptchaFormsModule} from 'ng-recaptcha/forms';
import {ProfileComponent} from './controllers/main/profile/profile.component';
import {ChangePasswordComponent} from './controllers/main/change-password/change-password.component';
import {PanelFilesComponent} from './controllers/legacy/panel/panel-files/panel-files.component';
import {PanelFileEditorComponent} from './controllers/legacy/panel/panel-file-editor/panel-file-editor.component';
import {PanelFilesComponent} from './controllers/panel/panel-files/panel-files.component';
import {PanelFileEditorComponent} from './controllers/panel/panel-file-editor/panel-file-editor.component';
import {ServiceLocator} from './service.injector';
import {AuthService} from './services/auth.service';
import {CurrentServerService} from './services/current-server.service';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {Router} from '@angular/router';
import {PasswordValidation} from '../../../../password-validation';
import {AuthenticationService} from '../../../../services/legacy/authentication.service';
import {AuthService} from '../../../services/auth.service';
import {PasswordValidation} from '../../../password-validation';

@Component({
selector: 'app-change-password',
Expand All @@ -16,7 +16,9 @@ export class ChangePasswordComponent implements OnInit {
submitted = false;
error: string;

constructor(private formBuilder: FormBuilder, private router: Router, private auth: AuthenticationService) {
constructor(private formBuilder: FormBuilder,
private router: Router,
private auth: AuthService) {
}

ngOnInit() {
Expand All @@ -29,28 +31,22 @@ export class ChangePasswordComponent implements OnInit {
});
}

onSubmit() {
onSubmit = async (): Promise<void> => {
this.submitted = true;
if (this.changeForm.invalid) {
return;
}
this.loading = true;
// this.auth.register(this.newUser).subscribe((data) => {
// if(this.returnUrl === undefined){
// this.router.navigateByUrl('/login'); //Good login! Return to dash w/o returnUrl
// }else{
// this.router.navigateByUrl('/login?returnUrl=' + this.returnUrl); //Good login! Return to dash /w returnUrl
// }
// }, (err) => {
// this.error = err;
// });
this.auth.changePassword(this.changeForm.controls.cPassword.value, this.changeForm.controls.password.value).subscribe(data => {

try {
await this.auth.changePassword(this.changeForm.controls.cPassword.value, this.changeForm.controls.password.value);
this.router.navigateByUrl('/account');
}, (err) => {
this.error = err;
this.loading = false;
this.submitted = false;
});
}
} catch (e) {
this.error = e;
}

this.loading = false;
this.submitted = false;
};

}
34 changes: 18 additions & 16 deletions src/app/controllers/main/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {ActivatedRoute, NavigationEnd, Router} from '@angular/router';
import {TokenPayload} from '../../../../core/models/legacy/token-payload';
import {AuthenticationService} from '../../../services/legacy/authentication.service';
import {SelectedServerService} from '../../../services/legacy/selected-server.service';
import {AuthService, TokenPayload} from '../../../services/auth.service';
import {CurrentServerService} from '../../../services/current-server.service';

@Component({
selector: 'app-login',
Expand All @@ -24,8 +23,11 @@ export class LoginComponent implements OnInit {
error: string;
returnUrlSet = false;

constructor(private formBuilder: FormBuilder, private route: ActivatedRoute,
private router: Router, private auth: AuthenticationService, private selectedServer: SelectedServerService) {
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
private auth: AuthService,
private currentServer: CurrentServerService) {
}

ngOnInit() {
Expand All @@ -47,23 +49,23 @@ export class LoginComponent implements OnInit {
});
}

onSubmit() {
onSubmit = async (): Promise<void> => {
this.submitted = true;
if (this.loginForm.invalid) {
return;
}
this.loading = true;
this.credentials.email = this.loginForm.controls.email.value;
this.credentials.password = this.loginForm.controls.password.value;
this.auth.login(this.credentials).subscribe(() => {
this.selectedServer.updateCache(false, () => {
this.router.navigateByUrl(this.returnUrl); // Good login! Return to dash.
});
}, (err) => {
this.loading = false;
this.submitted = false;
this.error = err;
});
}

try {
await this.auth.authorize(this.credentials);
await this.currentServer.updateCache(true);
await this.router.navigateByUrl(this.returnUrl);
} catch (e) {
this.error = e;
}
this.loading = false;
this.submitted = false;
};
}
16 changes: 8 additions & 8 deletions src/app/controllers/main/logout/logout.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Component, OnInit} from '@angular/core';
import {AuthenticationService} from '../../../../services/legacy/authentication.service';
import {Router} from '@angular/router';
import {SelectedServerService} from '../../../../services/legacy/selected-server.service';
import {AuthService} from '../../../services/auth.service';
import {CurrentServerService} from '../../../services/current-server.service';

@Component({
selector: 'app-logout',
Expand All @@ -10,20 +10,20 @@ import {SelectedServerService} from '../../../../services/legacy/selected-server
})
export class LogoutComponent implements OnInit {

constructor(private auth: AuthenticationService, private router: Router, private selectedServer: SelectedServerService) {
constructor(private auth: AuthService,
private router: Router,
private currentServer: CurrentServerService) {
}

ngOnInit() {

this.router.navigateByUrl('/login').then(() => {
// remove user from local storage to log user out
localStorage.removeItem('session');
this.auth.clearUser();
this.auth.user = undefined;

// Make sure we clear the server on logout
this.selectedServer.servers = undefined;
this.selectedServer.setCurrentServer(undefined, false);
this.currentServer.servers = undefined;
this.currentServer.currentServer = undefined;
});
}

}
3 changes: 2 additions & 1 deletion src/app/controllers/main/navbar/navbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
<a class="nav-link text-primary" routerLink="/register">Register</a>
</li>
<li *ngIf="login" class="nav-item dropdown">
<a aria-expanded="false" aria-haspopup="true" class="nav-link dropdown-toggle text-primary" data-toggle="dropdown"
<a aria-expanded="false" aria-haspopup="true" class="nav-link dropdown-toggle text-primary"
data-toggle="dropdown"
href="#" id="navbarAccountDropdown">
{{username}}
</a>
Expand Down
11 changes: 6 additions & 5 deletions src/app/controllers/main/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Component, OnInit} from '@angular/core';
import {AuthenticationService} from '../../core/services/authentication.service';
import {NavigationEnd, Router} from '@angular/router';
import {AuthService} from '../../../services/auth.service';

@Component({
selector: 'app-navbar',
Expand All @@ -14,14 +14,15 @@ export class NavbarComponent implements OnInit {
currentUrl: string;
shards: number;

constructor(private auth: AuthenticationService, private router: Router) {
constructor(private auth: AuthService,
private router: Router) {
this.router.events.subscribe((e) => {
if (e instanceof NavigationEnd) {
this.currentUrl = e.url;
this.login = this.auth.isLoggedIn();
this.login = this.auth.checkLoggedIn();
if (this.login) {
this.username = this.auth.getUser().username;
this.shards = this.auth.getUser().credits;
this.username = this.auth.user.username;
this.shards = this.auth.user.credits;
}
}
});
Expand Down
7 changes: 4 additions & 3 deletions src/app/controllers/main/profile/profile.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, OnInit} from '@angular/core';
import {AuthenticationService} from '../../../services/legacy/authentication.service';
import {AuthService} from '../../../services/auth.service';

@Component({
selector: 'app-profile',
Expand All @@ -11,11 +11,12 @@ export class ProfileComponent implements OnInit {
data: any;
loading = true;

constructor(private auth: AuthenticationService) {
constructor(private auth: AuthService) {
}

ngOnInit() {
this.auth.getUserData().subscribe(data => {
this.loading = false;
this.auth.getUserProfile().then(data => {
this.loading = false;
this.data = data;
});
Expand Down
30 changes: 16 additions & 14 deletions src/app/controllers/main/register/register.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {PasswordValidation} from '../../../password-validation';
import {TokenPayload} from '../../../../core/models/legacy/token-payload';
import {AuthenticationService} from '../../../services/legacy/authentication.service';
import {ActivatedRoute, Router} from '@angular/router';
import {AuthService, TokenPayload} from '../../../services/auth.service';

@Component({
selector: 'app-register',
Expand All @@ -23,8 +22,10 @@ export class RegisterComponent implements OnInit {
username: ''
};

constructor(private formBuilder: FormBuilder, private route: ActivatedRoute,
private router: Router, private auth: AuthenticationService) {
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
private auth: AuthService) {
}

ngOnInit() {
Expand All @@ -39,7 +40,7 @@ export class RegisterComponent implements OnInit {
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || undefined;
}

onSubmit() {
onSubmit = async (): Promise<void> => {
this.submitted = true;
if (this.registerForm.invalid) {
return;
Expand All @@ -48,16 +49,17 @@ export class RegisterComponent implements OnInit {
this.newUser.username = this.registerForm.controls.username.value;
this.newUser.email = this.registerForm.controls.email.value;
this.newUser.password = this.registerForm.controls.password.value;
this.auth.register(this.newUser).subscribe((data) => {

try {
await this.auth.register(this.newUser);
if (this.returnUrl === undefined) {
this.router.navigateByUrl('/login'); // Good login! Return to dash w/o returnUrl
await this.router.navigateByUrl('/login'); // Good login! Return to dash w/o returnUrl
} else {
this.router.navigateByUrl('/login?returnUrl=' + this.returnUrl); // Good login! Return to dash /w returnUrl
await this.router.navigateByUrl('/login?returnUrl=' + this.returnUrl); // Good login! Return to dash /w returnUrl
}
}, (err) => {
this.error = err;
this.loading = false;
});
}

} catch (e) {
this.error = e;
}
this.loading = false;
};
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {Router} from '@angular/router';
import {AuthService, ServerPayload} from '../../../../services/auth.service';
import {CurrentServerService} from '../../../../services/current-server.service';
import {AuthService, ServerPayload} from '../../../services/auth.service';
import {CurrentServerService} from '../../../services/current-server.service';

@Component({
selector: 'app-panel-create',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
<div *ngIf="error" class="invalid-feedback">
<div class="invalid bigerror">Failed to save file contents; {{ error }}</div>
</div>
<textarea [ngClass]="{ 'is-invalid': editSubmitted && editForm.controls['content'].errors }" class="form-control" class="form-control" formControlName="content"
<textarea [ngClass]="{ 'is-invalid': editSubmitted && editForm.controls['content'].errors }"
class="form-control" class="form-control" formControlName="content"
id="content"
rows="30"></textarea>
<div *ngIf="editSubmitted && editForm.controls['content'].errors" class="invalid-feedback">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Component} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {ResponsiveServerPage} from '../../../panel-controller.serverpage';
import {ResponsiveServerPage} from '../../panel-controller.serverpage';
import {ActivatedRoute} from '@angular/router';

@Component({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {Component, ElementRef, ViewChild} from '@angular/core';

import * as path from 'path-browserify';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {ResponsiveServerPage} from '../../../panel-controller.serverpage';
import {FileDetails, Server} from '../../../../models/server.model';
import {ResponsiveServerPage} from '../../panel-controller.serverpage';
import {FileDetails, Server} from '../../../models/server.model';

@Component({
selector: 'app-panel-files',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {Component} from '@angular/core';
import {NavigationEnd} from '@angular/router';
import {Subject} from 'rxjs';
import {ResponsiveServerPage} from '../../../panel-controller.serverpage';
import {ResponsiveServerPage} from '../../panel-controller.serverpage';

@Component({
selector: 'app-panel-frame',
Expand Down
Loading

0 comments on commit 3b6c512

Please sign in to comment.