From d7bd80b4d694ca594810bf95c45ca9fe64b686ba Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 17 Oct 2019 17:30:16 +0200 Subject: [PATCH 1/5] added error messages for login, after login: nav changes and home gets opend --- .../app-scaffold/app-scaffold.component.ts | 9 +++++++-- src/app/components/login/login.component.html | 1 + src/app/components/login/login.component.ts | 18 +++++++++++++++--- src/app/services/login/login.service.ts | 14 +++++++++++--- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/app/components/app-scaffold/app-scaffold.component.ts b/src/app/components/app-scaffold/app-scaffold.component.ts index e173656..b2b9801 100644 --- a/src/app/components/app-scaffold/app-scaffold.component.ts +++ b/src/app/components/app-scaffold/app-scaffold.component.ts @@ -1,5 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { LoginComponent } from '../login/login.component'; +import { DatasharingService } from '../../services/datasharing.service'; @Component({ selector: 'app-scaffold', @@ -8,10 +9,14 @@ import { LoginComponent } from '../login/login.component'; }) export class AppScaffoldComponent implements OnInit { - - constructor() { } + loggedIn: boolean = false; + constructor(private data: DatasharingService) { } ngOnInit() { + this.data.currentUserInfo.subscribe(user => { + this.loggedIn = user.loggedIn; + console.log('he´s comming through!'); + }) } } diff --git a/src/app/components/login/login.component.html b/src/app/components/login/login.component.html index 00341e7..b7a3663 100644 --- a/src/app/components/login/login.component.html +++ b/src/app/components/login/login.component.html @@ -12,6 +12,7 @@ +

{{errorMessage}}


You aren´t part of greenvironment yet? - join us here diff --git a/src/app/components/login/login.component.ts b/src/app/components/login/login.component.ts index 40d6725..40e0a7a 100644 --- a/src/app/components/login/login.component.ts +++ b/src/app/components/login/login.component.ts @@ -1,6 +1,8 @@ import { Component, OnInit } from '@angular/core'; import { Login } from 'src/app/models/login'; import { LoginService } from 'src/app/services/login/login.service'; +import { RouterLink } from '@angular/router'; +import {Router} from '@angular/router'; @Component({ selector: 'app-login', @@ -9,17 +11,27 @@ import { LoginService } from 'src/app/services/login/login.service'; }) export class LoginComponent implements OnInit { login: Login + errorOccurred: boolean = false; + errorMessage: string; - constructor(private loginService: LoginService) { + constructor(private loginService: LoginService,private router: Router) { this.login = {passwordHash: null, email: null}; } + public loginError(error : any){ + console.log(error.errors[0].message); + this.errorOccurred = true; + this.errorMessage = error.errors[0].message; + } + onClickSubmit(pEmail: string, pPasswordHash: string) { - console.log('email: ' + pEmail); + console.log('try to login with mail adress:' + pEmail); + this.errorOccurred = false; + this.errorMessage = " "; this.login.email = pEmail this.login.passwordHash = pPasswordHash - this.loginService.login(this.login) + this.loginService.login(this.login, error => this.loginError(error.json())); } ngOnInit() {} diff --git a/src/app/services/login/login.service.ts b/src/app/services/login/login.service.ts index 8276696..8924676 100644 --- a/src/app/services/login/login.service.ts +++ b/src/app/services/login/login.service.ts @@ -4,15 +4,16 @@ import { Login } from '../../models/login'; import { User } from 'src/app/models/user'; import { DatasharingService } from '../datasharing.service'; import { userInfo } from 'os'; +import {Router} from '@angular/router'; @Injectable({ providedIn: 'root' }) export class LoginService { - constructor(private http: Http, private data: DatasharingService) { } + constructor(private http: Http, private data: DatasharingService,private router: Router) { } - public login(login : Login) { + public login(login : Login, errorCb: any) { //let url = './graphql' let url = 'https://greenvironment.net/graphql' @@ -23,8 +24,15 @@ export class LoginService { return this.http.post(url, this.buildJson(login)) .subscribe(response => { console.log(response.text()); + this.loginSuccess(); this.updateUserInfo(response.json()) - }); + }, errorCb + ); + } + public loginSuccess(){ + console.log('alles supi dupi'); + //do routing + this.router.navigateByUrl(''); } public updateUserInfo(response : any){ From b0fe6b7dc9bb2f076c0da6e5c6e0180bbca0a6ed Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 18 Oct 2019 14:24:08 +0200 Subject: [PATCH 2/5] added password hash --- package-lock.json | 5 +++++ package.json | 15 ++++++++------- src/app/components/login/login.component.ts | 4 +++- src/app/components/register/register.component.ts | 7 ++++++- src/app/models/login.ts | 2 ++ 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0a6c5de..86c7311 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9443,6 +9443,11 @@ "tslib": "^1.9.3" } }, + "ts-md5": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/ts-md5/-/ts-md5-1.2.6.tgz", + "integrity": "sha512-VFW6O4CTZsgTPDBhF31i83hPhfwd9Dcp5RnbfGOIJPDRro9IhvXMYd8xBycD0yXqHZiAvv+iDG8F+UFrPEyQ5w==" + }, "ts-node": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz", diff --git a/package.json b/package.json index c877d22..a943834 100644 --- a/package.json +++ b/package.json @@ -23,16 +23,17 @@ "@angular/platform-browser-dynamic": "~7.0.0", "@angular/router": "~7.0.0", "apollo-angular": "^1.7.0", - "core-js": "^2.5.4", - "ngx-socket-io": "^2.0.0", - "rxjs": "~6.3.3", - "zone.js": "~0.8.26", "apollo-angular-link-http": "^1.6.0", - "apollo-link": "^1.2.11", - "apollo-client": "^2.6.0", "apollo-cache-inmemory": "^1.3.2", + "apollo-client": "^2.6.0", + "apollo-link": "^1.2.11", + "core-js": "^2.5.4", + "graphql": "^14.3.1", "graphql-tag": "^2.10.0", - "graphql": "^14.3.1" + "ngx-socket-io": "^2.0.0", + "rxjs": "~6.3.3", + "ts-md5": "^1.2.6", + "zone.js": "~0.8.26" }, "devDependencies": { "@angular/cli": "~7.0.4", diff --git a/src/app/components/login/login.component.ts b/src/app/components/login/login.component.ts index 40e0a7a..75fbb95 100644 --- a/src/app/components/login/login.component.ts +++ b/src/app/components/login/login.component.ts @@ -3,6 +3,7 @@ import { Login } from 'src/app/models/login'; import { LoginService } from 'src/app/services/login/login.service'; import { RouterLink } from '@angular/router'; import {Router} from '@angular/router'; +import {Md5} from 'ts-md5/dist/md5'; @Component({ selector: 'app-login', @@ -29,7 +30,8 @@ export class LoginComponent implements OnInit { this.errorOccurred = false; this.errorMessage = " "; this.login.email = pEmail - this.login.passwordHash = pPasswordHash + const md5 = new Md5(); + this.login.passwordHash = md5.appendStr(pPasswordHash).end() as string this.loginService.login(this.login, error => this.loginError(error.json())); } diff --git a/src/app/components/register/register.component.ts b/src/app/components/register/register.component.ts index 1b60d8d..8182ede 100644 --- a/src/app/components/register/register.component.ts +++ b/src/app/components/register/register.component.ts @@ -1,6 +1,8 @@ import { Component, OnInit } from '@angular/core'; import {RegisterService} from '../../services/register/register.service'; import {Registration} from '../../models/registration'; +import {Router} from '@angular/router'; +import {Md5} from 'ts-md5/dist/md5'; @Component({ selector: 'registration', @@ -9,6 +11,8 @@ import {Registration} from '../../models/registration'; }) export class RegisterComponent implements OnInit { registration: Registration + errorOccurred: boolean = false; + errorMessage: string; constructor(private registerService: RegisterService) { this.registration = {username: null, passwordHash: null, email: null}; @@ -22,7 +26,8 @@ export class RegisterComponent implements OnInit { console.log('password same'); this.registration.username = pUsername this.registration.email = pEmail - this.registration.passwordHash = pPasswordHash + const md5 = new Md5(); + this.registration.passwordHash = md5.appendStr(pPasswordHash).end() as string this.registerService.register(this.registration) } else{console.log('password NOT same'); } diff --git a/src/app/models/login.ts b/src/app/models/login.ts index 30aeb8f..f44e6e0 100644 --- a/src/app/models/login.ts +++ b/src/app/models/login.ts @@ -1,3 +1,5 @@ +import { Hash } from "crypto"; + export interface Login { email: string; passwordHash: string From 5e32897269fae875b860d7e54a8e0b1f528662b0 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 22 Oct 2019 11:04:37 +0200 Subject: [PATCH 3/5] registerService saves the user data and shows error messages too --- .../register/register.component.html | 3 +- .../components/register/register.component.ts | 37 ++++++++++++----- src/app/services/register/register.service.ts | 41 +++++++++++++++++-- 3 files changed, 65 insertions(+), 16 deletions(-) diff --git a/src/app/components/register/register.component.html b/src/app/components/register/register.component.html index 4683ee6..a737235 100644 --- a/src/app/components/register/register.component.html +++ b/src/app/components/register/register.component.html @@ -15,10 +15,11 @@ repeat password: -
+
+

{{errorMessage}}


You are already part of greenvironment? - login diff --git a/src/app/components/register/register.component.ts b/src/app/components/register/register.component.ts index 8182ede..b659e5a 100644 --- a/src/app/components/register/register.component.ts +++ b/src/app/components/register/register.component.ts @@ -3,6 +3,7 @@ import {RegisterService} from '../../services/register/register.service'; import {Registration} from '../../models/registration'; import {Router} from '@angular/router'; import {Md5} from 'ts-md5/dist/md5'; +import { parseWebDriverCommand } from 'blocking-proxy/built/lib/webdriver_commands'; @Component({ selector: 'registration', @@ -18,19 +19,33 @@ export class RegisterComponent implements OnInit { 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); + public registerError(error : any){ + console.log(error.errors[0].message); + this.errorOccurred = true; + this.errorMessage = error.errors[0].message; + } - if(pPasswordHash == pPasswordHashRepeat){ - console.log('password same'); - this.registration.username = pUsername - this.registration.email = pEmail - const md5 = new Md5(); - this.registration.passwordHash = md5.appendStr(pPasswordHash).end() as string + onClickSubmit(pUsername: string, pEmail: string, pPasswordHash: string,pPasswordHashRepeat: string ) { + this.errorOccurred = false; + this.errorMessage = " "; + if(this.passwordSame(pPasswordHash,pPasswordHashRepeat)){ + this.registration.username = pUsername + this.registration.email = pEmail + const md5 = new Md5(); + this.registration.passwordHash = md5.appendStr(pPasswordHash).end() as string + this.registerService.register(this.registration, error => this.registerError(error.json())); + } + } - this.registerService.register(this.registration) - } else{console.log('password NOT same'); } + passwordSame(pwd: string,pwd2: string){ + if(pwd == pwd2){ + console.log('password same'); + return true; + } else{ + this.errorOccurred = true; + this.errorMessage = "not the same password"; + return false; + } } ngOnInit() {} diff --git a/src/app/services/register/register.service.ts b/src/app/services/register/register.service.ts index a750046..dc8c2bd 100644 --- a/src/app/services/register/register.service.ts +++ b/src/app/services/register/register.service.ts @@ -1,15 +1,18 @@ import { Injectable } from '@angular/core'; import {Http, URLSearchParams, Headers} from '@angular/http'; import { Registration } from '../../models/registration'; +import {Router} from '@angular/router'; +import { DatasharingService } from '../datasharing.service'; +import { User } from 'src/app/models/user'; @Injectable({ providedIn: 'root' }) export class RegisterService { - constructor(private http: Http) { } + constructor(private http: Http, private data: DatasharingService,private router: Router) { } - public register(registration: Registration) { + public register(registration: Registration, errorCb: any) { //let url = './graphql' let url = 'https://greenvironment.net/graphql' @@ -17,12 +20,42 @@ export class RegisterService { let headers = new Headers(); headers.set('Content-Type', 'application/json'); - return this.http.post(url, this.buildJson(registration)).subscribe(response => console.log(response.text())); + return this.http.post(url, this.buildJson(registration)) + .subscribe(response => { + console.log(response.text()); + this.registerSuccess(); + this.updateUserInfo(response.json()) + }, errorCb + ); + } + + public registerSuccess(){ + console.log('alles supi dupi'); + //do routing + this.router.navigateByUrl(''); + } + + public updateUserInfo(response : any){ + const user: User = new User(); + user.loggedIn = true; + user.userID = response.data.register.id; + user.username = response.data.register.name; + user.handle = response.data.register.handle; + user.email = response.data.register.email; + user.points = response.data.register.points; + user.level = response.data.register.level; + user.friendIDs = response.data.register.friends; + user.groupIDs = response.data.register.groups; + user.chatIDs = response.data.register.chats; + user.requestIDs = response.data.register.requests; + + this.data.changeUserInfo(user) + } public buildJson(registration: Registration): any { const body = {query: `mutation($username: String, $email: String, $pwHash: String) { - register(username: $username, email: $email, passwordHash: $pwHash) {id} + register(username: $username, email: $email, passwordHash: $pwHash) {id, name, handle, points, level, friends{id}, groups{id},chats{id}} }`, variables: { email: registration.email, pwHash: registration.passwordHash, From 0d96caa5b08ee575e5488980690d8ad630f3ee40 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 26 Oct 2019 18:45:27 +0200 Subject: [PATCH 4/5] added profile page, action and level list --- src/app/components/login/login.component.sass | 1 + .../components/profile/profile.component.html | 61 ++++++++++++++++-- .../components/profile/profile.component.sass | 31 ++++----- .../components/profile/profile.component.ts | 63 ++++++++++++++++++- src/app/models/actionlist.ts | 15 +++++ src/app/models/levellist.ts | 11 ++++ 6 files changed, 157 insertions(+), 25 deletions(-) create mode 100644 src/app/models/actionlist.ts create mode 100644 src/app/models/levellist.ts diff --git a/src/app/components/login/login.component.sass b/src/app/components/login/login.component.sass index 8e687e2..067cd7b 100644 --- a/src/app/components/login/login.component.sass +++ b/src/app/components/login/login.component.sass @@ -12,5 +12,6 @@ @include gridPosition(2, 2,2,2) grid-template: 15% 15% 15% 15% 15% 15% / 100% background-color: $cPrimaryBackground + padding: 1em input margin: 0.25em \ No newline at end of file diff --git a/src/app/components/profile/profile.component.html b/src/app/components/profile/profile.component.html index a633ef0..2c55d7c 100644 --- a/src/app/components/profile/profile.component.html +++ b/src/app/components/profile/profile.component.html @@ -1,4 +1,57 @@ - - - - + +
+
+

Profile

+ + + + + + + + + + + + + + + + + + + + +
name: {{user.username}}
handle: {{user.handle}}
profile ID: {{user.userID}}
points: {{user.points}}
level: {{user.level}}
+

What´s the level?

+

There are different levels you can reach through green behaviour. + Collect 100 points to level up! The levels are called: +

+
    +
  1. + {{level.name}} +
  2. +
+

How to level up?

+

There is an always growing list of things you can do, + to support your environment + and earn points to level up at the same time. + You can get a different amount of points + for differnet actions you can see in the list below: +

+ + + + + + + + + +
points action
{{action.points}}{{action.name}}
+
+
+

Profile not found :(

+
+
+ \ No newline at end of file diff --git a/src/app/components/profile/profile.component.sass b/src/app/components/profile/profile.component.sass index 402b19e..f3c16e2 100644 --- a/src/app/components/profile/profile.component.sass +++ b/src/app/components/profile/profile.component.sass @@ -1,25 +1,18 @@ @import '../../../styles/mixins.sass' @import '../../../styles/vars.sass' -#headerbar - @include gridPosition(1, 2, 1, 4) +#profile + background-color: $cSecondaryBackground + grid-template: 3% 94% 3% / 10% 80% 10% display: grid - grid-template: 100% /30% 10% 10% 10% 10% 10% 10% 10% - background-color: $cHeadPrimaryBackground - color: $cHeadFontColor + min-height: 100vh + max-height: 100vh -#chatcontainer - @include gridPosition(2, 3, 1, 2) - background-color: $cBoxBodyBackground +#profilecontainer + @include gridPosition(2, 2,2,2) + //grid-template: 15% 15% 15% 15% 15% 15% / 100% + background-color: $cPrimaryBackground + padding: 1em -#feedcontainer - @include gridPosition(2, 3, 2, 3) - display: grid - grid-template: 10% 90% /100% - background-color: $cSecondaryBackground - -#socialcontainer - @include gridPosition(2, 3, 3, 4) - display: grid - grid-template: 50% 50% /100% - background-color: $cBoxBodyBackground \ No newline at end of file +th + text-align: left \ No newline at end of file diff --git a/src/app/components/profile/profile.component.ts b/src/app/components/profile/profile.component.ts index 80073a2..593a073 100644 --- a/src/app/components/profile/profile.component.ts +++ b/src/app/components/profile/profile.component.ts @@ -1,4 +1,9 @@ import { Component, OnInit } from '@angular/core'; +import {Router} from '@angular/router'; +import {Http, URLSearchParams, Headers} from '@angular/http'; +import { User } from 'src/app/models/user'; +import { Actionlist } from 'src/app/models/actionlist'; +import { Levellist } from 'src/app/models/levellist'; @Component({ selector: 'app-profile', @@ -6,10 +11,64 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./profile.component.sass'] }) export class ProfileComponent implements OnInit { - - constructor() { } + actionlist: Actionlist = new Actionlist(); + levellist: Levellist = new Levellist(); + user: User = new User() + id : string + profileNotFound : boolean = false; + constructor(private router: Router,private http: Http) { } + ngOnInit() { + this.id = this.router.url.substr(this.router.url.lastIndexOf("/") + 1); + //let url = './graphql' + let url = 'https://greenvironment.net/graphql' + let headers = new Headers(); + headers.set('Content-Type', 'application/json'); + + return this.http.post(url, this.buildJson(this.id)) + .subscribe(response => { + console.log(response.text()); + this.updateUserInfo(response.json()); + } + ); + } + + public updateUserInfo(response : any){ + if(response.data.getUser != null){ + this.profileNotFound = false; + this.user.loggedIn = true; + this.user.userID = response.data.getUser.id; + this.user.username = response.data.getUser.name; + this.user.handle = response.data.getUser.handle; + this.user.points = response.data.getUser.points; + this.user.level = response.data.getUser.level; + this.user.friendIDs = response.data.getUser.friends; + } else{ + this.profileNotFound = true; + } } + public buildJson(id: string): any { + const body = {query: `query($userId: ID) { + getUser(userId:$userId){ + id + handle + name + profilePicture + points + level + friendCount + friends{ + id + } + posts{ + content + } + } + }`, variables: { + userId: this.id + }}; + return body; + } } diff --git a/src/app/models/actionlist.ts b/src/app/models/actionlist.ts new file mode 100644 index 0000000..cab24f6 --- /dev/null +++ b/src/app/models/actionlist.ts @@ -0,0 +1,15 @@ +export class Actionlist{ + actions: { id: number, name: string, points: number}[] = [ + { id: 0, name: "collect much trash",points: 25}, + { id: 1, name: "collect a bit trash",points: 5 }, + { id: 2, name: "trash seperation", points: 5 }, + { id: 3, name: "plant a tree", points: 2 }, + { id: 4, name: "beautify yout surroundings", points: 8 }, + { id: 5, name: "reduce waste", points: 5 }, + { id: 6, name: "reduce CO2 emission", points: 5 }, + { id: 7, name: "eat a vegetarian meal", points: 2 }, + { id: 8, name: "don´t use the car", points: 10 }, + { id: 9, name: "buy fair trade/ local product", points: 1 }, + { id: 10, name: "donate money to an environment organisation ", points: 3 }, + ]; +} \ No newline at end of file diff --git a/src/app/models/levellist.ts b/src/app/models/levellist.ts new file mode 100644 index 0000000..999f59e --- /dev/null +++ b/src/app/models/levellist.ts @@ -0,0 +1,11 @@ +export class Levellist{ + levels: {level: number, name: string, points: number}[] = [ + {level: 0, name: "Green Horn",points: 0}, + {level: 1, name: "Good Willed",points: 100 }, + {level: 2, name: "Helper", points: 200 }, + {level: 3, name: "World Saver", points: 300 }, + {level: 4, name: "Hero of the Green Country", points: 400 }, + {level: 5, name: "Champion of the Earth", points: 500 }, + {level: 6, name: "Intergallactic Superhero", points: 600 }, + ]; +} \ No newline at end of file From e15214816116c9c46fdae040408cc043d38b4862 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 27 Oct 2019 02:46:22 +0200 Subject: [PATCH 5/5] added getLevelName()-function, WIP: added SelfService to check if logged in --- .../app-scaffold/app-scaffold.component.html | 2 +- .../app-scaffold/app-scaffold.component.ts | 15 +++- src/app/components/home/home.component.html | 1 - src/app/components/home/home.component.sass | 15 ++-- .../components/profile/profile.component.html | 2 +- .../components/profile/profile.component.ts | 2 + src/app/models/levellist.ts | 14 ++++ .../services/selfservice/self.service.spec.ts | 12 ++++ src/app/services/selfservice/self.service.ts | 69 +++++++++++++++++++ 9 files changed, 116 insertions(+), 16 deletions(-) create mode 100644 src/app/services/selfservice/self.service.spec.ts create mode 100644 src/app/services/selfservice/self.service.ts diff --git a/src/app/components/app-scaffold/app-scaffold.component.html b/src/app/components/app-scaffold/app-scaffold.component.html index ea1e121..ed80193 100644 --- a/src/app/components/app-scaffold/app-scaffold.component.html +++ b/src/app/components/app-scaffold/app-scaffold.component.html @@ -1,6 +1,6 @@

Greenvironment

- + diff --git a/src/app/components/app-scaffold/app-scaffold.component.ts b/src/app/components/app-scaffold/app-scaffold.component.ts index b2b9801..cc28c79 100644 --- a/src/app/components/app-scaffold/app-scaffold.component.ts +++ b/src/app/components/app-scaffold/app-scaffold.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { LoginComponent } from '../login/login.component'; import { DatasharingService } from '../../services/datasharing.service'; +import { SelfService } from '../../services/selfservice/self.service'; @Component({ selector: 'app-scaffold', @@ -10,13 +11,23 @@ import { DatasharingService } from '../../services/datasharing.service'; export class AppScaffoldComponent implements OnInit { loggedIn: boolean = false; - constructor(private data: DatasharingService) { } + userId: number; + profileUrl: string; + + constructor(private data: DatasharingService,private selfservice: SelfService) { } ngOnInit() { this.data.currentUserInfo.subscribe(user => { this.loggedIn = user.loggedIn; - console.log('he´s comming through!'); + this.userId = user.userID; + this.profileUrl = '/profile/' + this.userId; + console.log(user.loggedIn); }) + if(this.loggedIn != true){ + console.log('user is not logged in'); + this.selfservice.checkIfLoggedIn; + }; + console.log('loggedIn is ' + this.loggedIn) } } diff --git a/src/app/components/home/home.component.html b/src/app/components/home/home.component.html index eeee9e5..8027381 100644 --- a/src/app/components/home/home.component.html +++ b/src/app/components/home/home.component.html @@ -1,5 +1,4 @@
- diff --git a/src/app/components/home/home.component.sass b/src/app/components/home/home.component.sass index ad9fbaa..b0d77dd 100644 --- a/src/app/components/home/home.component.sass +++ b/src/app/components/home/home.component.sass @@ -2,30 +2,23 @@ @import '../../../styles/vars.sass' #content - grid-template: 7.5% 92.5% / 25% 50% 25% + grid-template: 100%/ 25% 50% 25% display: grid min-height: 100vh max-height: 100vh -#headerbar - @include gridPosition(1, 2, 1, 4) - display: grid - grid-template: 100% /30% 10% 10% 10% 10% 10% 15% 5% - background-color: $cHeadPrimaryBackground - color: $cHeadFontColor - #chatcontainer - @include gridPosition(2, 3, 1, 2) + @include gridPosition(1, 3, 1, 2) background-color: $cBoxBodyBackground #feedcontainer - @include gridPosition(2, 3, 2, 3) + @include gridPosition(1, 3, 2, 3) display: grid grid-template: 10% 90% /100% background-color: $cSecondaryBackground #socialcontainer - @include gridPosition(2, 3, 3, 4) + @include gridPosition(1, 3, 3, 4) display: grid grid-template: 50% 50% /100% background-color: $cBoxBodyBackground \ No newline at end of file diff --git a/src/app/components/profile/profile.component.html b/src/app/components/profile/profile.component.html index 2c55d7c..b8344fe 100644 --- a/src/app/components/profile/profile.component.html +++ b/src/app/components/profile/profile.component.html @@ -20,7 +20,7 @@ {{user.points}} level: - {{user.level}} + {{user.level}} ({{rankname}})

What´s the level?

diff --git a/src/app/components/profile/profile.component.ts b/src/app/components/profile/profile.component.ts index 593a073..9c04ba0 100644 --- a/src/app/components/profile/profile.component.ts +++ b/src/app/components/profile/profile.component.ts @@ -15,6 +15,7 @@ export class ProfileComponent implements OnInit { levellist: Levellist = new Levellist(); user: User = new User() id : string + rankname: string; profileNotFound : boolean = false; constructor(private router: Router,private http: Http) { } @@ -43,6 +44,7 @@ export class ProfileComponent implements OnInit { this.user.handle = response.data.getUser.handle; this.user.points = response.data.getUser.points; this.user.level = response.data.getUser.level; + this.rankname = this.levellist.getLevelName(this.user.level); this.user.friendIDs = response.data.getUser.friends; } else{ this.profileNotFound = true; diff --git a/src/app/models/levellist.ts b/src/app/models/levellist.ts index 999f59e..5f15ad5 100644 --- a/src/app/models/levellist.ts +++ b/src/app/models/levellist.ts @@ -8,4 +8,18 @@ export class Levellist{ {level: 5, name: "Champion of the Earth", points: 500 }, {level: 6, name: "Intergallactic Superhero", points: 600 }, ]; + + getLevelName(lev:number): any{ + var name: string = 'not defined'; + console.log(lev); + this.levels.forEach(rank => { + console.log(rank.level); + if(lev == rank.level){ + console.log('found matching level'); + name = rank.name; + } + }); + return name + } + } \ No newline at end of file diff --git a/src/app/services/selfservice/self.service.spec.ts b/src/app/services/selfservice/self.service.spec.ts new file mode 100644 index 0000000..7e958ec --- /dev/null +++ b/src/app/services/selfservice/self.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { SelfService } from './self.service'; + +describe('Selfservice', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: SelfService = TestBed.get(SelfService); + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/selfservice/self.service.ts b/src/app/services/selfservice/self.service.ts new file mode 100644 index 0000000..e6623b6 --- /dev/null +++ b/src/app/services/selfservice/self.service.ts @@ -0,0 +1,69 @@ +import { Injectable, EventEmitter, Output } from '@angular/core'; +import {Http, URLSearchParams, Headers} from '@angular/http'; +import { Login } from '../../models/login'; +import { User } from 'src/app/models/user'; +import { DatasharingService } from '../datasharing.service'; +import { userInfo } from 'os'; +import {Router} from '@angular/router'; + +@Injectable({ + providedIn: 'root' +}) +export class SelfService { + + constructor(private http: Http, private data: DatasharingService,private router: Router) { } + + public checkIfLoggedIn() { + console.log('check if logged in...'); + //let url = './graphql' + let url = 'https://greenvironment.net/graphql' + + let headers = new Headers(); + headers.set('Content-Type', 'application/json'); + + return this.http.post(url, this.buildJson()) + .subscribe(response => { + console.log(response.text()); + this.stillLoggedIn(); + this.updateUserInfo(response.json()) + }, error => { + this.notLoggedIn() + console.log(error.text()) + } + ); + } + public stillLoggedIn(){ + console.log('user was logged in'); + } + + public notLoggedIn(){ + console.log('user was not logged in'); + //do routing + this.router.navigateByUrl('/login'); + } + + public updateUserInfo(response : any){ + const user: User = new User(); + user.loggedIn = true; + user.userID = response.data.login.id; + user.username = response.data.login.name; + user.handle = response.data.login.handle; + user.email = response.data.login.email; + user.points = response.data.login.points; + user.level = response.data.login.level; + user.friendIDs = response.data.login.friends; + user.groupIDs = response.data.login.groups; + user.chatIDs = response.data.login.chats; + user.requestIDs = response.data.login.requests; + + this.data.changeUserInfo(user) + } + + public buildJson(): any { + const body = {query: `query() { + getSelf(){id, name, handle, points, level, friends{id}, groups{id},chats{id}} + }`, variables: { + }}; + return body; + } +}//add ,receivedRequests{id} later