added user variables to AppComonent & login functionality

master
Max 5 years ago
parent 838487a9fc
commit 6536389eb8

@ -1 +1,2 @@
<app-scaffold id="headerbar"></app-scaffold>
<router-outlet></router-outlet> <router-outlet></router-outlet>

@ -34,3 +34,10 @@
display: grid display: grid
min-height: 100vh min-height: 100vh
max-height: 100vh max-height: 100vh
#headerbar
@include gridPosition(1, 1, 1, 4)
display: grid
grid-template: 100% /30% 10% 10% 10% 10% 10% 15% 5%
background-color: $cHeadPrimaryBackground
color: $cHeadFontColor

@ -8,5 +8,19 @@ import { Component, OnInit } from '@angular/core';
export class AppComponent implements OnInit { export class AppComponent implements OnInit {
constructor() { } constructor() { }
loggedIn : boolean = false;
userID : number;
username : string;
handle : string;
email : string;
points : number;
level : number;
friendIDs : number[];
groupIDs : number[];
chatIDs : number[];
requestIDs : number[];
ngOnInit() { } ngOnInit() { }
} }

@ -1,10 +1,10 @@
<h1>Greenvironment</h1> <h1>Greenvironment</h1>
<button id="tab-home" routerLink="">Home</button> <button id="tab-home" routerLink="">Home</button>
<button id="tab-profile" routerLink="/profile">Profile</button> <button id="tab-profile" routerLink="/profile" *ngIf="loggedIn">Profile</button>
<button id="tab-rank">Rank</button> <button id="tab-rank" *ngIf="loggedIn">Rank</button>
<button id="tab-about" routerLink="/about">About</button> <button id="tab-about" routerLink="/about">About</button>
<button id="tab-imprint" routerLink="/imprint">Imprint</button> <button id="tab-imprint" routerLink="/imprint">Imprint</button>
<div id="dropdown"> <div id="dropdown" *ngIf="loggedIn">
<div> <div>
<span><i class="fa fa-caret-down" aria-hidden="true"></i></span> <span><i class="fa fa-caret-down" aria-hidden="true"></i></span>
<span> Niklas Lampe</span> <span> Niklas Lampe</span>
@ -13,4 +13,4 @@
Hallo Hallo
</div> </div>
</div> </div>
<button id="logoutbutton"><span><i class="fa fa-sign-out-alt fa-2x" aria-hidden="true"></i></span></button> <button id="logoutbutton" *ngIf="loggedIn"><span><i class="fa fa-sign-out-alt fa-2x" aria-hidden="true"></i></span></button>

@ -1,12 +1,14 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { LoginComponent } from '../login/login.component';
@Component({ @Component({
selector: 'app-scaffold', selector: 'app-scaffold',
templateUrl: './app-scaffold.component.html', templateUrl: './app-scaffold.component.html',
styleUrls: ['./app-scaffold.component.sass'] styleUrls: ['./app-scaffold.component.sass']
}) })
export class AppScaffoldComponent implements OnInit {
export class AppScaffoldComponent implements OnInit {
constructor() { } constructor() { }
ngOnInit() { ngOnInit() {

@ -1,6 +1,5 @@
<div id="login"> <div id="login">
<app-scaffold id="headerbar"></app-scaffold>
<div id="logincontainer"> <div id="logincontainer">
<table style="width:100%"> <table style="width:100%">
<tr> <tr>

@ -13,11 +13,4 @@
grid-template: 15% 15% 15% 15% 15% 15% / 100% grid-template: 15% 15% 15% 15% 15% 15% / 100%
background-color: $cPrimaryBackground background-color: $cPrimaryBackground
input input
margin: 0.25em margin: 0.25em
#headerbar
@include gridPosition(1, 1, 1, 4)
display: grid
grid-template: 100% /30% 10% 10% 10% 10% 10% 15% 5%
background-color: $cHeadPrimaryBackground
color: $cHeadFontColor

@ -9,7 +9,8 @@ import { LoginService } from 'src/app/services/login/login.service';
}) })
export class LoginComponent implements OnInit { export class LoginComponent implements OnInit {
login: Login login: Login
user: User
constructor(private loginService: LoginService) { constructor(private loginService: LoginService) {
this.login = {passwordHash: null, email: null}; this.login = {passwordHash: null, email: null};
} }
@ -21,6 +22,7 @@ export class LoginComponent implements OnInit {
this.loginService.login(this.login) this.loginService.login(this.login)
} }
ngOnInit() {} ngOnInit() {}
} }

@ -1,5 +1,4 @@
<div id="register"> <div id="register">
<app-scaffold id="headerbar"></app-scaffold>
<div id="registercontainer"> <div id="registercontainer">
<table style="width:100%"> <table style="width:100%">
<tr> <tr>

@ -16,9 +16,3 @@
input input
margin: 0.25em margin: 0.25em
#headerbar
@include gridPosition(1, 1, 1, 4)
display: grid
grid-template: 100% /30% 10% 10% 10% 10% 10% 15% 5%
background-color: $cHeadPrimaryBackground
color: $cHeadFontColor

@ -0,0 +1,15 @@
export interface User {
loggedIn : boolean;
userID : number;
username : string;
handle : string;
email : string;
points : number;
level : number;
friendIDs : number[];
groupIDs : number[];
chatIDs : number[];
requestIDs : number[];
}

@ -1,4 +1,4 @@
import { Injectable } from '@angular/core'; import { Injectable, EventEmitter, Output } from '@angular/core';
import {Http, URLSearchParams, Headers} from '@angular/http'; import {Http, URLSearchParams, Headers} from '@angular/http';
import { Login } from '../../models/login'; import { Login } from '../../models/login';
@ -9,6 +9,8 @@ export class LoginService {
constructor(private http: Http) { } constructor(private http: Http) { }
@Output() showChatEvent = new EventEmitter<Chatinfo>();
public login(login : Login) { public login(login : Login) {
//let url = './graphql' //let url = './graphql'
@ -17,16 +19,25 @@ export class LoginService {
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, this.buildJson(login)).subscribe(response => console.log(response.text())); return this.http.post(url, this.buildJson(login))
.subscribe(response => {
console.log(response.text());
this.saveUserData(response.json())
});
}
public saveUserData(text : any){
app = text.name;
} }
public buildJson(login: Login): any { public buildJson(login: Login): any {
const body = {query: `mutation($email: String, $pwHash: String) { const body = {query: `mutation($email: String, $pwHash: String) {
login(email: $email, passwordHash: $pwHash) {id} login(email: $email, passwordHash: $pwHash) {id, name, handle, points, level, friends{id}, groups{id},chats{id}}
}`, variables: { }`, variables: {
email: login.email, email: login.email,
pwHash: login.passwordHash, pwHash: login.passwordHash,
}}; }};
return body; return body;
} }
} }//add ,receivedRequests{id} later

Loading…
Cancel
Save