added functionality of the register service yey

master
Max 5 years ago
parent 953c6060b7
commit 811767d050

@ -1,4 +1,4 @@
<!--<app-login id="login"></app-login>-->
<!--<registration id="register"></registration>-->
<app-imprint id="imprint"></app-imprint>
<registration id="register"></registration>
<!--<app-imprint id="imprint"></app-imprint>-->
<!--<app-about id="about"></app-about>-->

@ -2,6 +2,7 @@ import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { DocumentListComponent } from './components/document-list/document-list.component';
@ -39,6 +40,7 @@ const config: SocketIoConfig = { url: 'http://localhost:4444', options: {} };
],
imports: [
BrowserModule,
HttpModule,
FormsModule,
SocketIoModule.forRoot(config)
],

@ -2,22 +2,22 @@
<table style="width:100%">
<tr>
<td>username: </td>
<td><input type="inputBox" name="username"><br></td>
<td><input #username type="text" name="username" username.value=''><br></td>
</tr>
<tr>
<td>email:</td>
<td><input type="text" name="email"><br></td>
<td><input #email type="text" name="email"><br></td>
</tr>
<tr>
<td>password:</td>
<td> <input type="text" name="password"><br></td>
<td> <input #password type="text" name="password"><br></td>
</tr>
<tr>
<td>repeat password:</td>
<td> <input type="text" name="repeatpassword"><br></td>
<td> <input #repeatpassword type="text" name="repeatpassword"><br></td>
</tr>
</table>
<button type="registerbutton">Register</button>
<button type="registerbutton" (click)="onClickSubmit(username.value,email.value,password.value, repeatpassword.value)">Register</button>
<br>
<a href="/login">You are already part of greenvironment? - login</a>
</div>
</div>

@ -6,29 +6,29 @@ import {Registration} from '../../models/registration';
selector: 'registration',
templateUrl: './register.component.html',
styleUrls: ['./register.component.sass']
})/*
})
export class RegisterComponent implements OnInit {
registration: Registration
registration: Registration
constructor(private registerService: RegisterService) {}
constructor(private registerService: RegisterService) {
this.registration = {username: null, passwordHash: null, email: null};
}
onClickSubmit(pUsername: string, pEmail: string, pPasswordHash: string,pPasswordHashRepeat: string ) {
console.log('username: ' + pUsername);
console.log('email: ' + pEmail);
onClickSubmit(pUsername: string, pEmail: string, pPasswordHash: string) {
if(pPasswordHash == pPasswordHashRepeat){
console.log('password same');
this.registration.username = pUsername
this.registration.email = pEmail
this.registration.passwordHash = pPasswordHash
this.registerService.register(this.registration)
} else{console.log('password NOT same'); }
}
ngOnInit() {}
}
*/
export class RegisterComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}

@ -11,20 +11,24 @@ export class RegisterService {
public register(registration: Registration) {
let url = './graphql'
//let url = './graphql'
let url = 'https://greenvironment.net/graphql'
let headers = new Headers();
headers.set('Content-Type', 'application/json');
return this.http.post(url, headers, this.buildJson(registration));
return this.http.post(url, this.buildJson(registration)).subscribe(response => console.log(response.text()));
}
public buildJson(registration: Registration): String {
const body = 'mutation {'
+ 'register(username: ' + registration.username + ', email: ' + registration.email
+ 'passwordHash: ' + registration.passwordHash + ') {'
'id} }'
return body
public buildJson(registration: Registration): any {
const body = {query: `mutation($username: String, $email: String, $pwHash: String) {
register(username: $username, email: $email, passwordHash: $pwHash) {id}
}`, variables: {
email: registration.email,
pwHash: registration.passwordHash,
username: registration.username,
}};
return body;
}
}

Loading…
Cancel
Save