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>--> <!--<app-login id="login"></app-login>-->
<!--<registration id="register"></registration>--> <registration id="register"></registration>
<app-imprint id="imprint"></app-imprint> <!--<app-imprint id="imprint"></app-imprint>-->
<!--<app-about id="about"></app-about>--> <!--<app-about id="about"></app-about>-->

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

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

@ -6,29 +6,29 @@ import {Registration} from '../../models/registration';
selector: 'registration', selector: 'registration',
templateUrl: './register.component.html', templateUrl: './register.component.html',
styleUrls: ['./register.component.sass'] styleUrls: ['./register.component.sass']
})/* })
export class RegisterComponent implements OnInit { 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.username = pUsername
this.registration.email = pEmail this.registration.email = pEmail
this.registration.passwordHash = pPasswordHash this.registration.passwordHash = pPasswordHash
this.registerService.register(this.registration) this.registerService.register(this.registration)
} else{console.log('password NOT same'); }
} }
ngOnInit() {} ngOnInit() {}
} }
*/
export class RegisterComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}

@ -11,20 +11,24 @@ export class RegisterService {
public register(registration: Registration) { public register(registration: Registration) {
let url = './graphql' //let url = './graphql'
let url = 'https://greenvironment.net/graphql'
let headers = new Headers(); let headers = new Headers();
headers.set('Content-Type', 'application/json'); 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 { public buildJson(registration: Registration): any {
const body = 'mutation {' const body = {query: `mutation($username: String, $email: String, $pwHash: String) {
+ 'register(username: ' + registration.username + ', email: ' + registration.email register(username: $username, email: $email, passwordHash: $pwHash) {id}
+ 'passwordHash: ' + registration.passwordHash + ') {' }`, variables: {
'id} }' email: registration.email,
return body pwHash: registration.passwordHash,
username: registration.username,
}};
return body;
} }
} }

Loading…
Cancel
Save