From d7bd80b4d694ca594810bf95c45ca9fe64b686ba Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 17 Oct 2019 17:30:16 +0200 Subject: [PATCH 1/2] 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/2] 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