- Becomes valid when promoted to Raider
+
+
+
+
+
+ |
+
+
+
+
-
-
- Trial
-
-
-
+
+ |
+
+
diff --git a/src/frontend/src/app/frontcraft/pages/raid/raid.component.ts b/src/frontend/src/app/frontcraft/pages/raid/raid.component.ts
index c969697..fd99314 100644
--- a/src/frontend/src/app/frontcraft/pages/raid/raid.component.ts
+++ b/src/frontend/src/app/frontcraft/pages/raid/raid.component.ts
@@ -1,12 +1,13 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router, NavigationStart } from '@angular/router';
-import { ApiService as ApiService } from '../../services/login-api';
+import { ClientApiService as ClientApiService } from '../../services/client-login-api';
import { RaidData, Raid, Signup, Character, Spec, Item, SRToken } from '../../../../../../backend/Types/Types';
import { NbWindowService, NbToastrService, NbDialogService } from '@nebular/theme';
import { FrontcraftCharacerpickerComponent } from './characterpicker.component';
import { getClassColor, SpecT } from '../../../../../../backend/Types/PlayerSpecs';
import { FrontcraftBuyTokenComponent } from '../shop/buytoken.component';
import { allItems } from '../../../../../../backend/Types/Items';
+import { IApiService } from '../../services/ApiService';
@Component({
selector: 'raid',
@@ -45,7 +46,7 @@ export class FrontcraftRaidComponent implements OnInit, OnDestroy{
uuid
constructor(
- private api: ApiService,
+ private api: IApiService,
private route: ActivatedRoute,
private router: Router,
private dialogService : NbDialogService,
diff --git a/src/frontend/src/app/frontcraft/pages/raids/createraid.compontent.ts b/src/frontend/src/app/frontcraft/pages/raids/createraid.compontent.ts
index 98dc41a..2bf9e91 100644
--- a/src/frontend/src/app/frontcraft/pages/raids/createraid.compontent.ts
+++ b/src/frontend/src/app/frontcraft/pages/raids/createraid.compontent.ts
@@ -1,8 +1,9 @@
import { Component, OnInit } from '@angular/core';
-import { ApiService } from '../../services/login-api';
+import { ClientApiService } from '../../services/client-login-api';
import { Raid, RaidData } from '../../../../../../backend/Types/Types';
import { NbWindowRef, NbDialogRef } from '@nebular/theme';
import { Tiers, _Tiers } from '../../../../../../backend/Types/Items';
+import { IApiService } from '../../services/ApiService';
const ONE_MINUTE = 60000
const ONE_HOUR = 60 * ONE_MINUTE
@@ -27,7 +28,7 @@ export class FrontcraftCreateRaidsComponent implements OnInit {
constructor(
protected dialogRef: NbDialogRef
,
- private api: ApiService
+ private api: IApiService
) {}
loadNext(cardData) {
diff --git a/src/frontend/src/app/frontcraft/pages/raids/raids.component.ts b/src/frontend/src/app/frontcraft/pages/raids/raids.component.ts
index d8405f5..802e01e 100644
--- a/src/frontend/src/app/frontcraft/pages/raids/raids.component.ts
+++ b/src/frontend/src/app/frontcraft/pages/raids/raids.component.ts
@@ -1,8 +1,9 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
-import { ApiService } from '../../services/login-api';
+import { ClientApiService } from '../../services/client-login-api';
import { NbWindowService, NbDialogService } from '@nebular/theme';
import { FrontcraftCreateRaidsComponent } from './createraid.compontent';
import { Router, NavigationStart } from '@angular/router';
+import { IApiService } from '../../services/ApiService';
@Component({
selector: 'raids',
@@ -19,7 +20,7 @@ export class FrontcraftRaidsComponent implements OnInit, OnDestroy{
uuid
constructor(
- private api: ApiService,
+ private api: IApiService,
private router: Router,
private dialogService: NbDialogService
) {
diff --git a/src/frontend/src/app/frontcraft/pages/rules/rules.component.html b/src/frontend/src/app/frontcraft/pages/rules/rules.component.html
index a7b6eb8..60bf97c 100644
--- a/src/frontend/src/app/frontcraft/pages/rules/rules.component.html
+++ b/src/frontend/src/app/frontcraft/pages/rules/rules.component.html
@@ -60,14 +60,21 @@
-
-
-
- 0">+{{rule.modifier}} {{rule.race}} {{rule.specname}} {{rule.class}}
-
-
({{rule.description}})
-
-
+
+
+ |
+
+ |
+
+
+ |
+ 0">+{{rule.modifier}} {{rule.race}} {{rule.specname}} {{rule.class}}
+ |
+
+ ({{rule.description}})
+ |
+
+
diff --git a/src/frontend/src/app/frontcraft/pages/rules/rules.component.ts b/src/frontend/src/app/frontcraft/pages/rules/rules.component.ts
index cdc0afc..f6c3d81 100644
--- a/src/frontend/src/app/frontcraft/pages/rules/rules.component.ts
+++ b/src/frontend/src/app/frontcraft/pages/rules/rules.component.ts
@@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core';
-import { ApiService as ApiService } from '../../services/login-api';
import { getClassColor } from '../../../../../../backend/Types/PlayerSpecs';
+import { IApiService } from '../../services/ApiService';
@Component({
selector: 'rules',
@@ -12,7 +12,7 @@ export class FrontcraftRulesComponent implements OnInit{
rules = {}
constructor(
- private api: ApiService,
+ private api: IApiService,
){
}
diff --git a/src/frontend/src/app/frontcraft/pages/shop/buytoken.component.ts b/src/frontend/src/app/frontcraft/pages/shop/buytoken.component.ts
index b413197..33dfec9 100644
--- a/src/frontend/src/app/frontcraft/pages/shop/buytoken.component.ts
+++ b/src/frontend/src/app/frontcraft/pages/shop/buytoken.component.ts
@@ -1,10 +1,11 @@
import { Component, OnInit, ContentChild, AfterContentInit, ViewChild, AfterViewInit, Input, Output, EventEmitter } from '@angular/core';
-import { ApiService as ApiService } from '../../services/login-api';
+import { ClientApiService as ClientApiService } from '../../services/client-login-api';
import { FrontcraftItemSelectComponent } from './itemselector.component';
import { NbWindowService, NbWindowRef, NbToastrService, NbDialogService, NbDialogRef } from '@nebular/theme';
import { Item, Character, SRToken, Signup } from '../../../../../../backend/Types/Types';
import { getClassColor } from '../../../../../../backend/Types/PlayerSpecs';
import { _Tiers, allItems, Tiers } from '../../../../../../backend/Types/Items';
+import { IApiService } from '../../services/ApiService';
@Component({
selector: 'buyToken',
@@ -88,7 +89,7 @@ import { _Tiers, allItems, Tiers } from '../../../../../../backend/Types/Items';
constructor(
private toastr: NbToastrService,
protected dialogRef: NbDialogRef,
- private api : ApiService
+ private api : IApiService
){}
async ngOnInit() {
diff --git a/src/frontend/src/app/frontcraft/pages/shop/item.component.ts b/src/frontend/src/app/frontcraft/pages/shop/item.component.ts
index 6e5290f..4e66349 100644
--- a/src/frontend/src/app/frontcraft/pages/shop/item.component.ts
+++ b/src/frontend/src/app/frontcraft/pages/shop/item.component.ts
@@ -1,6 +1,4 @@
import { Component, OnInit, Input, } from '@angular/core';
-import { ApiService as ApiService } from '../../services/login-api';
-import { NbToastrService, } from '@nebular/theme';
import { Item, } from '../../../../../../backend/Types/Types';
import { _Tiers, } from '../../../../../../backend/Types/Items';
diff --git a/src/frontend/src/app/frontcraft/pages/shop/itemselector.component.ts b/src/frontend/src/app/frontcraft/pages/shop/itemselector.component.ts
index d93d02f..ca5d986 100644
--- a/src/frontend/src/app/frontcraft/pages/shop/itemselector.component.ts
+++ b/src/frontend/src/app/frontcraft/pages/shop/itemselector.component.ts
@@ -1,6 +1,7 @@
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
-import { ApiService } from '../../services/login-api';
+import { ClientApiService } from '../../services/client-login-api';
import { Item, Character } from '../../../../../../backend/Types/Types';
+import { IApiService } from '../../services/ApiService';
@Component({
selector: 'itemselect',
@@ -18,7 +19,7 @@ export class FrontcraftItemSelectComponent implements OnInit{
@Output() onSelect = new EventEmitter- ();
constructor(
- private api: ApiService,
+ private api: IApiService,
){}
async ngOnInit(){
diff --git a/src/frontend/src/app/frontcraft/pages/shop/shop.component.ts b/src/frontend/src/app/frontcraft/pages/shop/shop.component.ts
index 75e72cf..9cb320d 100644
--- a/src/frontend/src/app/frontcraft/pages/shop/shop.component.ts
+++ b/src/frontend/src/app/frontcraft/pages/shop/shop.component.ts
@@ -1,9 +1,7 @@
-import { Component, OnInit, ContentChild, AfterContentInit, ViewChild, AfterViewInit, Input, Output, EventEmitter } from '@angular/core';
-import { ApiService as ApiService } from '../../services/login-api';
-import { FrontcraftItemSelectComponent } from './itemselector.component';
-import { NbWindowService, NbWindowRef, NbToastrService, NbDialogService, NbDialogRef } from '@nebular/theme';
-import { Item, Character, SRToken, Signup } from '../../../../../../backend/Types/Types';
-import { getClassColor } from '../../../../../../backend/Types/PlayerSpecs';
+import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
+import { ClientApiService as ClientApiService } from '../../services/client-login-api';
+import { NbDialogService } from '@nebular/theme';
+import { Item, Character, Signup } from '../../../../../../backend/Types/Types';
import { _Tiers, allItems } from '../../../../../../backend/Types/Items';
@Component({
@@ -20,8 +18,6 @@ export class FrontcraftShopComponent implements OnInit{
allItems = allItems
constructor(
- private api: ApiService,
- private dialogService : NbDialogService
){
}
diff --git a/src/frontend/src/app/frontcraft/pages/shop/wowhead.component.ts b/src/frontend/src/app/frontcraft/pages/shop/wowhead.component.ts
index eb99e8f..5980fa4 100644
--- a/src/frontend/src/app/frontcraft/pages/shop/wowhead.component.ts
+++ b/src/frontend/src/app/frontcraft/pages/shop/wowhead.component.ts
@@ -1,6 +1,4 @@
import { Component, OnInit, Input } from '@angular/core';
-import { ApiService as ApiService } from '../../services/login-api';
-import { NbToastrService } from '@nebular/theme';
import { Item } from '../../../../../../backend/Types/Types';
import { _Tiers } from '../../../../../../backend/Types/Items';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
diff --git a/src/frontend/src/app/frontcraft/pages/user/user.component.ts b/src/frontend/src/app/frontcraft/pages/user/user.component.ts
index 40a02d3..beca29e 100644
--- a/src/frontend/src/app/frontcraft/pages/user/user.component.ts
+++ b/src/frontend/src/app/frontcraft/pages/user/user.component.ts
@@ -1,11 +1,11 @@
import { Component, OnInit } from '@angular/core';
-import { ApiService, hash } from '../../services/login-api';
-import { Router, ActivatedRoute } from '@angular/router';
+import { ActivatedRoute } from '@angular/router';
import { User, Spec, Character } from '../../../../../../backend/Types/Types';
import { getClassColor } from '../../../../../../backend/Types/PlayerSpecs';
import { _Tiers } from '../../../../../../backend/Types/Items';
import { _Rank } from '../../../../../../backend/Types/Types';
import { NbToastrService } from '@nebular/theme';
+import { hash, IApiService } from '../../services/ApiService';
@Component({
selector: 'user-component',
@@ -19,12 +19,16 @@ export class FrontcraftUserComponent implements OnInit{
ranks = _Rank
myProfile = false
manageUser
- user:User = {} as any
+ user:User = {
+ rank: 'Guest',
+ username: 'Guest',
+ pwhash: ""
+ }
characters : (Character & Spec)[] = []
constructor(
private route: ActivatedRoute,
- private api : ApiService,
+ private api : IApiService,
private toastr: NbToastrService
){}
diff --git a/src/frontend/src/app/frontcraft/permissions/changePermissions/changePermissions.component.ts b/src/frontend/src/app/frontcraft/permissions/changePermissions/changePermissions.component.ts
index a26c326..7a78365 100644
--- a/src/frontend/src/app/frontcraft/permissions/changePermissions/changePermissions.component.ts
+++ b/src/frontend/src/app/frontcraft/permissions/changePermissions/changePermissions.component.ts
@@ -1,8 +1,9 @@
import { Component, OnInit } from '@angular/core';
-import { ApiService as ApiService } from '../../services/login-api';
+import { ClientApiService as ClientApiService } from '../../services/client-login-api';
import { Router } from '@angular/router';
import { _Rank, _Class, _Race, RPCPermission } from '../../../../../../backend/Types/Types'
import { NbToastrService } from '@nebular/theme';
+import { IApiService } from '../../services/ApiService';
@Component({
@@ -15,8 +16,7 @@ export class ChangePermissionsComponent implements OnInit{
ranks = _Rank
constructor(
- private router : Router,
- private api : ApiService,
+ private api : IApiService,
private toastr: NbToastrService
){}
@@ -32,9 +32,6 @@ export class ChangePermissionsComponent implements OnInit{
perm[key] = value
- console.log(perm);
-
-
await modify.setPermission(perm).catch(e => {
})
diff --git a/src/frontend/src/app/frontcraft/permissions/permissions-layout.component.ts b/src/frontend/src/app/frontcraft/permissions/permissions-layout.component.ts
index 9ad350b..6726450 100644
--- a/src/frontend/src/app/frontcraft/permissions/permissions-layout.component.ts
+++ b/src/frontend/src/app/frontcraft/permissions/permissions-layout.component.ts
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
-import { ApiService } from '../services/login-api';
+import { ClientApiService } from '../services/client-login-api';
import { Router } from '@angular/router';
@Component({
@@ -13,7 +13,6 @@ import { Router } from '@angular/router';
export class PermissionsComponent implements OnInit{
constructor(
- private loginSvc : ApiService,
private router: Router
){}
diff --git a/src/frontend/src/app/frontcraft/permissions/permissions-routing.module.ts b/src/frontend/src/app/frontcraft/permissions/permissions-routing.module.ts
deleted file mode 100644
index 5022ddf..0000000
--- a/src/frontend/src/app/frontcraft/permissions/permissions-routing.module.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { NgModule } from '@angular/core';
-import { RouterModule, Routes } from '@angular/router';
-import { PermissionsComponent } from './permissions-layout.component';
-import { ChangePermissionsComponent } from './changePermissions/changePermissions.component';
-
-export const routes: Routes = [
- {
- path: '',
- component: PermissionsComponent,
- children: [
- {
- path: '**',
- component: ChangePermissionsComponent,
- },
- ]
- }
-];
-
-@NgModule({
- imports: [RouterModule.forChild(routes)],
- exports: [RouterModule],
-})
-export class PermissionsRoutingModule {
-}
\ No newline at end of file
diff --git a/src/frontend/src/app/frontcraft/permissions/permissions.module.ts b/src/frontend/src/app/frontcraft/permissions/permissions.module.ts
index 961c1d1..524f3fb 100644
--- a/src/frontend/src/app/frontcraft/permissions/permissions.module.ts
+++ b/src/frontend/src/app/frontcraft/permissions/permissions.module.ts
@@ -15,13 +15,11 @@ import {
} from '@nebular/theme';
import { PermissionsComponent } from './permissions-layout.component';
import { ThemeModule } from '../../@theme/theme.module';
-import { PermissionsRoutingModule } from './permissions-routing.module';
import { ChangePermissionsComponent } from './changePermissions/changePermissions.component';
@NgModule({
imports: [
NbToggleModule,
- PermissionsRoutingModule,
CommonModule,
FormsModule,
RouterModule,
diff --git a/src/frontend/src/app/frontcraft/services/ApiService.ts b/src/frontend/src/app/frontcraft/services/ApiService.ts
new file mode 100644
index 0000000..ee8875a
--- /dev/null
+++ b/src/frontend/src/app/frontcraft/services/ApiService.ts
@@ -0,0 +1,23 @@
+import { Auth, FrontcraftIfc, FrontcraftFeatureIfc, User, SomeOf } from '../../../../../backend/Types/Types';
+import { saltedHash } from '../../../../../backend/Util/hash';
+import { RPCSocket } from 'rpclibrary';
+
+export class IApiService{
+ getUnprivilegedSocket: () => RPCSocket & FrontcraftIfc
+ getAuth: () => Auth | undefined
+ checkLogin: () => Promise
+ initialize: () => Promise
+ getCurrentUser: () => User | undefined
+ login: (username: string, password: string) => Promise>
+ connectShoutbox: (callback:Function) => Promise
+ kick: () => Promise
+ logout: () => Promise
+ get: (feature : K) => K extends keyof FrontcraftIfc?FrontcraftIfc[K]:
+ K extends keyof FrontcraftFeatureIfc?(FrontcraftFeatureIfc[K] | void):
+ never
+}
+
+export async function hash(value:string) : Promise{
+ return saltedHash(value, "")
+}
+
diff --git a/src/frontend/src/app/frontcraft/services/login-api.ts b/src/frontend/src/app/frontcraft/services/client-login-api.ts
similarity index 72%
rename from src/frontend/src/app/frontcraft/services/login-api.ts
rename to src/frontend/src/app/frontcraft/services/client-login-api.ts
index efa0068..a5edbbb 100644
--- a/src/frontend/src/app/frontcraft/services/login-api.ts
+++ b/src/frontend/src/app/frontcraft/services/client-login-api.ts
@@ -1,31 +1,29 @@
-import { Injectable, Injector, NgZone } from "@angular/core";
+import { Injectable } from "@angular/core";
import {RPCSocket} from 'rpclibrary/js/src/Frontend'
-
import { Auth, User, _Class, FrontcraftFeatureIfc, SomeOf, FrontcraftIfc, } from '../../../../../backend/Types/Types'
-import { CookieService } from 'ngx-cookie-service';
-import { Router } from '@angular/router';
import { ShoutMessage } from '../../../../../backend/Components/Shoutbox/Interface';
-import { saltedHash } from '../../../../../backend/Util/hash';
-import { NbToastrService } from '@nebular/theme';
+import { hash, IApiService } from './ApiService';
+
+declare const Cookies
@Injectable()
-export class ApiService{
+export class ClientApiService implements IApiService{
private socket:RPCSocket & FrontcraftIfc;
private auth:Auth
private privSocket: RPCSocket & SomeOf
- constructor(
- private injector: Injector,
- private cookieSvc : CookieService,
- private ngZone : NgZone,
- private toastr: NbToastrService
- ){}
+ constructor(){
+ window['s'] = this
+ }
getUnprivilegedSocket = () : RPCSocket & FrontcraftIfc => this.socket
private getPrivilegedSocket = async (auth:Auth) : Promise> => {
- if(this.privSocket) return this.privSocket
- if(auth == null) throw new Error("Bad Auth")
+ if(this.privSocket) {
+ return this.privSocket
+ }
+ if(auth == null)
+ throw new Error("Bad Auth")
try{
const sock = new RPCSocket(
@@ -38,24 +36,24 @@ export class ApiService{
})
sock.hook('getUserData', () => auth)
- sock.hook('navigate', (where:string) => {
- this.ngZone.run( () => {
- this.injector.get(Router).navigateByUrl(where)
- })
- })
sock.on('close', async () => {
+ console.log("priv#close");
+
//handled via unprivileged socket
})
sock.on('error', async (e) => {
+ console.log("priv#error", e);
+
//handled via unprivileged socket
})
const authSock = await sock.connect>(auth.token.value)
this.auth = auth
this.privSocket = authSock
- this.cookieSvc.set('token', JSON.stringify(auth))
+ Cookies.set('token', JSON.stringify(auth))
+// document.cookie = JSON.stringify(auth)
return authSock
}catch(e){
if(this.privSocket) this.privSocket.destroy()
@@ -86,13 +84,11 @@ export class ApiService{
try{
auth = await this.socket.UserManager.login(username, pwHash)
}catch(e){
- this.toastr.danger("Login failed", "Error")
return
}
if(!auth){
await this.logout()
- this.toastr.danger("Login failed", "Error")
throw new Error("Login failed")
}
@@ -105,8 +101,8 @@ export class ApiService{
return sock
}
- async connectShoutbox(handler) : Promise{
- const res = await this.get('Shoutbox').subscribe(handler)
+ async connectShoutbox(callback:Function) : Promise{
+ const res = await this.get('Shoutbox').subscribe(callback)
return async (msg: ShoutMessage) => await this.get('Shoutbox').shout(res.uuid, msg)
}
@@ -116,25 +112,21 @@ export class ApiService{
}
logout = async () => {
- this.cookieSvc.set('token', undefined)
+ Cookies.remove('token')
if(this.auth){
try{
await this.socket.UserManager.logout(this.auth.user.username, this.auth.token.value)
}catch(e){
- //socket is dead
+ console.warn(e);
}
}
if(this.privSocket) this.privSocket.destroy()
this.privSocket = null
this.auth = null
-
- this.ngZone.run(() => {
- this.injector.get(Router).navigate(['/auth']);
- })
}
- initialize = async () : Promise => {
+ initialize = async (force = false) : Promise => {
if(this.socket){
this.socket.destroy()
this.socket = null
@@ -143,9 +135,7 @@ export class ApiService{
try{
let conn = new RPCSocket(20000, window.location.hostname)
conn.on('close', async () => {
- })
-
-
+ })
this.socket = await conn.connect()
}catch(e){
@@ -155,9 +145,9 @@ export class ApiService{
}
try{
- const cookie = JSON.parse(this.cookieSvc.get('token'))
+ const cookie = JSON.parse(Cookies.get('token'))
- if(cookie != null) {
+ if(cookie != null && cookie != "") {
try{
const auth = await this.socket.UserManager.getAuth(cookie.token.value)
if(!auth) return this.socket
@@ -168,6 +158,7 @@ export class ApiService{
}
}
}catch(e){
+ Cookies.remove('token')
}
}
@@ -180,13 +171,4 @@ export class ApiService{
await this.logout()
return false
}
-}
-
-export async function hash(value:string) : Promise{
- return saltedHash(value, "")
-}
-
-//angular depenency manager requires this
-export function initializeLoginSvc(svc: ApiService): () => Promise {
- return ()=>svc.initialize?svc.initialize():undefined
}
\ No newline at end of file
diff --git a/src/frontend/src/app/frontcraft/services/server-login-api.ts b/src/frontend/src/app/frontcraft/services/server-login-api.ts
new file mode 100644
index 0000000..9916e66
--- /dev/null
+++ b/src/frontend/src/app/frontcraft/services/server-login-api.ts
@@ -0,0 +1,99 @@
+import { Injectable } from "@angular/core";
+import {RPCSocket} from 'rpclibrary/js/src/Frontend'
+import { Auth, User, _Class, FrontcraftFeatureIfc, SomeOf, FrontcraftIfc, } from '../../../../../backend/Types/Types'
+import { hash, IApiService } from './ApiService';
+
+declare const Cookies
+
+@Injectable()
+export class ServerApiService implements IApiService{
+ private socket:RPCSocket & FrontcraftIfc;
+ private auth:Auth
+ private privSocket: RPCSocket & SomeOf
+
+ constructor(){}
+
+ getUnprivilegedSocket = () : RPCSocket & FrontcraftIfc => this.socket
+
+ get = (feature : K) : K extends keyof FrontcraftIfc?FrontcraftIfc[K]:
+ K extends keyof FrontcraftFeatureIfc?(FrontcraftFeatureIfc[K] | void):
+ never => {
+ //@ts-ignore
+ return this.socket[feature]
+ }
+
+ getCurrentUser = () : User | undefined => {
+ return this.auth?this.auth.user:undefined
+ }
+
+ login = async (username: string, password: string) : Promise> => {
+ const pwHash = await hash(password)
+ let auth
+ try{
+ auth = await this.socket.UserManager.login(username, pwHash)
+ }catch(e){
+ return
+ }
+
+ if(!auth){
+ await this.logout()
+ throw new Error("Login failed")
+ }
+
+ //attach error handler now so failed logins dont trigger reloads
+ this.socket.on('error', async (err) => {
+ console.log(err);
+ })
+
+ }
+
+ async connectShoutbox(callback:Function) : Promise{
+ return console.log
+ }
+
+ kick = async () => {
+ }
+
+ logout = async () => {
+ Cookies.remove('token')
+ if(this.auth){
+ try{
+ await this.socket.UserManager.logout(this.auth.user.username, this.auth.token.value)
+ }catch(e){
+ console.warn(e);
+ }
+ }
+
+ if(this.privSocket) this.privSocket.destroy()
+ this.privSocket = null
+ this.auth = null
+ }
+
+ initialize = async () : Promise => {
+ if(this.socket){
+ this.socket.destroy()
+ this.socket = null
+ }
+
+ try{
+ let conn = new RPCSocket(20000, window.location.hostname)
+ conn.on('close', async () => {
+ })
+
+ this.socket = await conn.connect()
+ }catch(e){
+ console.log(e);
+ throw new Error("Websocket cannot connect")
+ }
+ }
+
+ getAuth = () => this.auth
+
+ async checkLogin() : Promise{
+ if(!this.auth) return false
+ const valid = this.socket.UserManager.checkToken(this.auth.token.value, this.auth.user.rank)
+ if(valid) return true
+ await this.logout()
+ return false
+ }
+}
\ No newline at end of file
diff --git a/src/frontend/src/main.server.ts b/src/frontend/src/main.server.ts
new file mode 100644
index 0000000..e429066
--- /dev/null
+++ b/src/frontend/src/main.server.ts
@@ -0,0 +1,9 @@
+import { enableProdMode } from '@angular/core';
+
+enableProdMode()
+
+export { AppServerModule } from './app/app.server.module';
+import { IApiService } from './app/frontcraft/services/ApiService';
+export { IApiService }
+export { ServerApiService } from './app/frontcraft/services/server-login-api';
+
diff --git a/src/frontend/src/main.ts b/src/frontend/src/main.ts
index 8fd0e9d..c8b31f0 100644
--- a/src/frontend/src/main.ts
+++ b/src/frontend/src/main.ts
@@ -6,12 +6,23 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
-import { AppModule } from './app/app.module';
+import { FrontcraftAppModule } from './app/app.module';
import { environment } from './environments/environment';
+import { IApiService } from "./app/frontcraft/services/ApiService"
+import { ClientApiService } from './app/frontcraft/services/client-login-api';
if (environment.production) {
enableProdMode();
}
-platformBrowserDynamic().bootstrapModule(AppModule)
- .catch(err => console.error(err));
+const serviceObj = new ClientApiService()
+serviceObj.initialize().then(_ => {
+ platformBrowserDynamic([
+ {
+ provide: IApiService,
+ deps: [],
+ useValue: serviceObj
+ }
+ ]).bootstrapModule(FrontcraftAppModule)
+ .catch(err => console.error(err));
+})
diff --git a/src/frontend/src/tsconfig.app.json b/src/frontend/src/tsconfig.app.json
deleted file mode 100644
index 86333d8..0000000
--- a/src/frontend/src/tsconfig.app.json
+++ /dev/null
@@ -1,26 +0,0 @@
-{
- "extends": "../tsconfig.json",
- "compilerOptions": {
- "outDir": "../out-tsc/app",
- "baseUrl": "./",
- "paths": {
- "@angular/*": [
- "../node_modules/@angular/*"
- ],
- "@nebular/*": [
- "../node_modules/@nebular/*"
- ]
- }
- },
- "exclude": [
- "test.ts",
- "**/*.spec.ts",
- "../node_modules/@nebular/**/*.spec.ts",
- "../node_modules/rpclibrary/js/**/*"
- ],
- "include": [
- "../src/*.ts",
- "../src/**/*.ts",
- "../node_modules/@nebular/**/*.ts"
- ]
-}
diff --git a/src/frontend/tsconfig.app.json b/src/frontend/tsconfig.app.json
new file mode 100644
index 0000000..4dd64eb
--- /dev/null
+++ b/src/frontend/tsconfig.app.json
@@ -0,0 +1,24 @@
+{
+ "extends": "./tsconfig.json",
+ "compilerOptions": {
+ "outDir": "./out-tsc/app",
+ "paths": {
+ "@angular/*": [
+ "./node_modules/@angular/*"
+ ],
+ "@nebular/*": [
+ "./node_modules/@nebular/*"
+ ]
+ }
+ },
+ "exclude": [
+ "test.ts",
+ "**/*.spec.ts",
+ "./node_modules/@nebular/**/*.spec.ts",
+ "./node_modules/rpclibrary/js/**/*"
+ ],
+ "include": [
+ "./src/*.ts",
+ "./src/**/*.ts",
+ ]
+}
diff --git a/src/frontend/tsconfig.json b/src/frontend/tsconfig.json
index 370415c..67c0d79 100644
--- a/src/frontend/tsconfig.json
+++ b/src/frontend/tsconfig.json
@@ -1,15 +1,14 @@
{
"compileOnSave": false,
"compilerOptions": {
- "importHelpers": true,
- "module": "commonjs",
- "outDir": "./dist/out-tsc",
- "sourceMap": true,
- "declaration": false,
+ "outDir": "./out-tsc",
+ "baseUrl": "./",
+ "declaration": true,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
- "target": "es5",
+ "importHelpers": true,
+ "target": "es2015",
"typeRoots": [
"node_modules/@types"
],
@@ -20,5 +19,8 @@
"plugins": [
{ "name": "tslint-language-service"}
]
- }
+ },
+ "angularCompilerOptions": {
+ "enableIvy": false,
+ },
}
diff --git a/src/frontend/tsconfig.server.json b/src/frontend/tsconfig.server.json
new file mode 100644
index 0000000..992b1b2
--- /dev/null
+++ b/src/frontend/tsconfig.server.json
@@ -0,0 +1,15 @@
+{
+ "extends": "./tsconfig.app.json",
+ "compilerOptions": {
+ "outDir": "./out-tsc/app-server",
+ "module": "commonjs",
+ "types": ["node"]
+ },
+ "files": [
+ "src/main.server.ts",
+ "server.ts"
+ ],
+ "angularCompilerOptions": {
+ "entryModule": "./src/app/app.server.module#AppServerModule"
+ }
+}
diff --git a/src/frontend/webpack.server.config.js b/src/frontend/webpack.server.config.js
new file mode 100644
index 0000000..b5b0e84
--- /dev/null
+++ b/src/frontend/webpack.server.config.js
@@ -0,0 +1,36 @@
+const path = require('path');
+const webpack = require('webpack');
+
+module.exports = {
+ entry: { server: './server.ts' },
+ resolve: { extensions: ['.js', '.ts'] },
+ mode: 'none',
+ target: 'node',
+ externals: [/(node_modules|main(\\|\/)..*(\\|\/).js)/],
+ output: {
+ path: path.join(__dirname, `dist`),
+ filename: '[name].js',
+ libraryTarget: 'commonjs'
+ },
+ module: {
+ rules: [
+ { test: /\.ts$/, loader: 'ts-loader', exclude: /^(?!.*\.spec\.ts$).*\.ts$/ },
+ {
+ test: /(\\|\/)@angular(\\|\/)core(\\|\/).+\.js$/,
+ parser: { system: true }
+ }
+ ]
+ },
+ plugins: [
+ new webpack.ContextReplacementPlugin(
+ /(.+)?angular(\\|\/)core(.+)?/,
+ path.join(__dirname, 'src'), // location of your src
+ {} // a map of your routes
+ ),
+ new webpack.ContextReplacementPlugin(
+ /(.+)?express(\\|\/)(.+)?/,
+ path.join(__dirname, 'src'),
+ {}
+ )
+ ]
+};
\ No newline at end of file
diff --git a/tsconfig.json b/tsconfig.json
index b39aea6..3b91d38 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -9,18 +9,12 @@
"strict": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
-
+ "baseUrl": "./",
"outDir": "./lib",
- //"types": ["node"],
+ "types": ["node", "mocha"],
"strictNullChecks": false
},
- "include": ["src/backend/**/*"],
- "exclude": [
- "./src/frontend/**/*",
- "./node_modules/**/*",
- "./src/frontend/node_modules/**/*",
- "./test",
- ],
+ "include": ["src", "test"],
"angularCompilerOptions": {
"enableIvy": false,
"entryModule": "./src/backend/Admin/app.server.module#AppServerModule"