Added dependency injection
This commit is contained in:
Generated
+3
-3
@@ -14269,9 +14269,9 @@
|
||||
"integrity": "sha512-ZYzRkETgBrdEGzL5JSKimvjI2CX7ioyZCkX2BpcfyjqI+079W0wHAyj5W4rIZMcDSOHgLZtgz1IdDi/vU77KEQ=="
|
||||
},
|
||||
"rpclibrary": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/rpclibrary/-/rpclibrary-1.5.1.tgz",
|
||||
"integrity": "sha512-EN6wlifkFmEQrHhtbalS0i90ZBNbLNFcrQ8hTrcJLBuNMFab49R8i5fruoDLDJM88iPcx6eWccI6zLHK7Qkl2A==",
|
||||
"version": "1.6.2",
|
||||
"resolved": "https://registry.npmjs.org/rpclibrary/-/rpclibrary-1.6.2.tgz",
|
||||
"integrity": "sha512-lQTU4XkB9CSHz7YgtAcpVfyR5XrmTRX4P4eQjK6DDUjqKSFvJb5ChXjHnt1BcaNWbJ2VqmhCNVbcoyunJ2u7Rg==",
|
||||
"requires": {
|
||||
"bsock": "^0.1.9",
|
||||
"http": "0.0.0",
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
"normalize.css": "6.0.0",
|
||||
"pace-js": "1.0.2",
|
||||
"roboto-fontface": "0.8.0",
|
||||
"rpclibrary": "^1.5.1",
|
||||
"rpclibrary": "^1.6.2",
|
||||
"rxjs": "6.5.2",
|
||||
"rxjs-compat": "6.3.0",
|
||||
"socicon": "3.0.5",
|
||||
|
||||
@@ -19,9 +19,7 @@ export class AppComponent implements OnInit {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.analytics.trackPageViews();
|
||||
this.loginSvc.getFeature('createUser').then( (f) => {
|
||||
|
||||
})
|
||||
|
||||
window['s'] = this.loginSvc
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<h1 id="title" class="title">Account application</h1>
|
||||
|
||||
<form (ngSubmit)="register()" #form="ngForm" aria-labelledby="title">
|
||||
<form (ngSubmit)="onSubmit()" #form="ngForm" aria-labelledby="title">
|
||||
|
||||
<div class="form-control-group">
|
||||
<label class="label" for="input-email">Email address:</label>
|
||||
@@ -36,7 +36,7 @@
|
||||
<label class="label" for="input-password">Password:</label>
|
||||
<input nbInput
|
||||
fullWidth
|
||||
[(ngModel)]="user.password"
|
||||
[(ngModel)]="user.pwhash"
|
||||
#password="ngModel"
|
||||
name="password"
|
||||
type="password"
|
||||
@@ -58,14 +58,30 @@
|
||||
<nb-card-body>
|
||||
<nb-checkbox [(ngModel)]="showApplication" name="amMember" #checkbox>I am already a member</nb-checkbox>
|
||||
<br />
|
||||
|
||||
<span *ngIf="showApplication">
|
||||
And my main is <input name="preMember" nbInput> with rank <nb-select placeholder="Rank">
|
||||
<nb-option *ngFor="let rank of ranks" [value]=rank >{{rank}}</nb-option>
|
||||
|
||||
And my main is <input name="preMember" [(ngModel)]="character.name" nbInput>, a
|
||||
<nb-select [(selected)]="character.spec" placeholder="Spec" (selectedChange)="onSelectSpec()">
|
||||
<nb-option *ngFor="let spec of specs" [value]="spec">{{spec}}</nb-option>
|
||||
</nb-select>
|
||||
<nb-select [(selected)]="character.class" placeholder="Class" (selectedChange)="onSelectClass()">
|
||||
<nb-option *ngFor="let class of classes" [value]="class">{{class}}</nb-option>
|
||||
</nb-select>
|
||||
with rank
|
||||
<nb-select [(selected)]="user.rank" placeholder="Rank">
|
||||
<nb-option *ngFor="let rank of ranks" [value]="rank" >{{rank}}</nb-option>
|
||||
</nb-select>
|
||||
</span>
|
||||
<span *ngIf="!showApplication">Hello my name is <input name="charName" nbInput>
|
||||
I am playing a level 60 <input name="charName" placeholder="Spec + Class" nbInput> and I would like to join tranquil because
|
||||
|
||||
<span *ngIf="!showApplication">Hello my name is <input name="charName" [(ngModel)]="character.name" nbInput>
|
||||
I am playing a level 60
|
||||
<nb-select [(selected)]="character.spec" placeholder="Spec" (selectedChange)="onSelectSpec()">
|
||||
<nb-option *ngFor="let spec of specs" [value]="spec">{{spec}}</nb-option>
|
||||
</nb-select>
|
||||
<nb-select [(selected)]="character.class" placeholder="Class" (selectedChange)="onSelectClass()">
|
||||
<nb-option *ngFor="let class of classes" [value]="class">{{class}}</nb-option>
|
||||
</nb-select>
|
||||
and I would like to join Tranquil because
|
||||
<textarea nbInput fullWidth placeholder="reason" style="min-height: 400px"></textarea>
|
||||
|
||||
</span>
|
||||
@@ -79,7 +95,7 @@
|
||||
size="giant"
|
||||
[disabled]="submitted || !form.valid"
|
||||
[class.btn-pulse]="submitted">
|
||||
Log In
|
||||
Register
|
||||
</button>
|
||||
</form>
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { LoginApiService } from '../../services/login-api';
|
||||
import { LoginApiService, hash } from '../../services/login-api';
|
||||
import { Router } from '@angular/router';
|
||||
import { _Rank } from '../../../../../../backend/Types/Types'
|
||||
import { _Rank, _Class, Class, User } from '../../../../../../backend/Types/Types'
|
||||
import { specs } from '../../../../../../backend/Types/PlayerSpecs'
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'register',
|
||||
@@ -9,9 +11,22 @@ import { _Rank } from '../../../../../../backend/Types/Types'
|
||||
})
|
||||
export class RegisterComponent implements OnInit{
|
||||
|
||||
user: any = {};
|
||||
showApplication = false
|
||||
user = {
|
||||
rank: "Guest"
|
||||
} as User
|
||||
|
||||
character: any = {
|
||||
class : "Warrior",
|
||||
spec : "Arms"
|
||||
}
|
||||
|
||||
|
||||
ranks = _Rank
|
||||
classes = _Class
|
||||
selectedClass : Class = "Warrior"
|
||||
selectedSpec = specs[this.selectedClass][0]
|
||||
specs = specs[this.selectedClass]
|
||||
showApplication = false
|
||||
|
||||
constructor(
|
||||
private router : Router,
|
||||
@@ -23,10 +38,32 @@ export class RegisterComponent implements OnInit{
|
||||
if(loggedin){
|
||||
this.router.navigateByUrl("/")
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
login(){
|
||||
this.loginApi.login(this.user.name, this.user.password)
|
||||
onSelectClass(){
|
||||
this.specs = specs[this.character.class]
|
||||
setTimeout(() => {
|
||||
this.character.spec = this.specs[0]
|
||||
}, 25)
|
||||
}
|
||||
|
||||
onSelectSpec(){
|
||||
}
|
||||
|
||||
async onSubmit(){
|
||||
this.user.pwhash = await hash(this.user.pwhash)
|
||||
const user = this.user
|
||||
this.user = {} as User
|
||||
const char = this.character
|
||||
this.character = {}
|
||||
|
||||
try{
|
||||
const usr = await this.loginApi.getUnprivilegedSocket().Authenticator.createUser(user)
|
||||
|
||||
}catch(e){
|
||||
alert("Error creating user"+e)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -65,11 +65,8 @@ export class LoginApiService{
|
||||
getCurrentUser = () : User | undefined => this.auth?this.auth.user:undefined
|
||||
|
||||
login = async (username: string, password: string) : Promise<RPCSocket & SomeOf<FrontcraftFeatureIfc>> => {
|
||||
const buf = str2arraybuf(password)
|
||||
const pwHash = await crypto.subtle.digest('SHA-256', buf);
|
||||
|
||||
const auth = await this.socket.Authenticator.login(username, buf2hex(pwHash))
|
||||
|
||||
const pwHash = await hash(password)
|
||||
const auth = await this.socket.Authenticator.login(username, pwHash)
|
||||
|
||||
if(!auth){
|
||||
await this.logout()
|
||||
@@ -129,6 +126,12 @@ function buf2hex(buffer) { // buffer is an ArrayBuffer
|
||||
return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
|
||||
}
|
||||
|
||||
export async function hash(value:string) : Promise<string>{
|
||||
const buf = str2arraybuf(value)
|
||||
const pwHash = await crypto.subtle.digest('SHA-256', buf);
|
||||
return buf2hex(pwHash)
|
||||
}
|
||||
|
||||
//angular depenency manager requires this
|
||||
export function initializeLoginSvc(svc: LoginApiService): () => Promise<any> {
|
||||
return svc.initialize
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
"moduleResolution": "node",
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"target": "es2015",
|
||||
"target": "es5",
|
||||
"typeRoots": [
|
||||
"node_modules/@types"
|
||||
],
|
||||
"lib": [
|
||||
"es2017",
|
||||
"es2019",
|
||||
"dom"
|
||||
],
|
||||
"plugins": [
|
||||
|
||||
Reference in New Issue
Block a user