Merge branch 'max_dev' of Software_Engineering_I/greenvironment-frontend into master

added login and register function
error messages
password hash
master
Max_ES 5 years ago committed by Gitea
commit 95d2eff92a

5
package-lock.json generated

@ -9443,6 +9443,11 @@
"tslib": "^1.9.3" "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": { "ts-node": {
"version": "7.0.1", "version": "7.0.1",
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz",

@ -23,16 +23,17 @@
"@angular/platform-browser-dynamic": "~7.0.0", "@angular/platform-browser-dynamic": "~7.0.0",
"@angular/router": "~7.0.0", "@angular/router": "~7.0.0",
"apollo-angular": "^1.7.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-angular-link-http": "^1.6.0",
"apollo-link": "^1.2.11",
"apollo-client": "^2.6.0",
"apollo-cache-inmemory": "^1.3.2", "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-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": { "devDependencies": {
"@angular/cli": "~7.0.4", "@angular/cli": "~7.0.4",

@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { LoginComponent } from '../login/login.component'; import { LoginComponent } from '../login/login.component';
import { DatasharingService } from '../../services/datasharing.service';
@Component({ @Component({
selector: 'app-scaffold', selector: 'app-scaffold',
@ -8,10 +9,14 @@ import { LoginComponent } from '../login/login.component';
}) })
export class AppScaffoldComponent implements OnInit { export class AppScaffoldComponent implements OnInit {
loggedIn: boolean = false;
constructor() { } constructor(private data: DatasharingService) { }
ngOnInit() { ngOnInit() {
this.data.currentUserInfo.subscribe(user => {
this.loggedIn = user.loggedIn;
console.log('he´s comming through!');
})
} }
} }

@ -12,6 +12,7 @@
</tr> </tr>
</table> </table>
<button type="loginbutton" (click)="onClickSubmit(email.value,password.value)">Login</button> <button type="loginbutton" (click)="onClickSubmit(email.value,password.value)">Login</button>
<p *ngIf="errorOccurred">{{errorMessage}}</p>
<br> <br>
<a href="/register">You aren´t part of greenvironment yet? - join us here</a> <a href="/register">You aren´t part of greenvironment yet? - join us here</a>
</div> </div>

@ -1,6 +1,9 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Login } from 'src/app/models/login'; import { Login } from 'src/app/models/login';
import { LoginService } from 'src/app/services/login/login.service'; 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({ @Component({
selector: 'app-login', selector: 'app-login',
@ -9,17 +12,28 @@ import { LoginService } from 'src/app/services/login/login.service';
}) })
export class LoginComponent implements OnInit { export class LoginComponent implements OnInit {
login: Login login: Login
errorOccurred: boolean = false;
errorMessage: string;
constructor(private loginService: LoginService) { constructor(private loginService: LoginService,private router: Router) {
this.login = {passwordHash: null, email: null}; 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) { 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.email = pEmail
this.login.passwordHash = pPasswordHash const md5 = new Md5();
this.login.passwordHash = md5.appendStr(pPasswordHash).end() as string
this.loginService.login(this.login) this.loginService.login(this.login, error => this.loginError(error.json()));
} }
ngOnInit() {} ngOnInit() {}

@ -1,6 +1,8 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {RegisterService} from '../../services/register/register.service'; import {RegisterService} from '../../services/register/register.service';
import {Registration} from '../../models/registration'; import {Registration} from '../../models/registration';
import {Router} from '@angular/router';
import {Md5} from 'ts-md5/dist/md5';
@Component({ @Component({
selector: 'registration', selector: 'registration',
@ -9,6 +11,8 @@ import {Registration} from '../../models/registration';
}) })
export class RegisterComponent implements OnInit { export class RegisterComponent implements OnInit {
registration: Registration registration: Registration
errorOccurred: boolean = false;
errorMessage: string;
constructor(private registerService: RegisterService) { constructor(private registerService: RegisterService) {
this.registration = {username: null, passwordHash: null, email: null}; this.registration = {username: null, passwordHash: null, email: null};
@ -22,7 +26,8 @@ export class RegisterComponent implements OnInit {
console.log('password same'); console.log('password same');
this.registration.username = pUsername this.registration.username = pUsername
this.registration.email = pEmail 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) this.registerService.register(this.registration)
} else{console.log('password NOT same'); } } else{console.log('password NOT same'); }

@ -1,3 +1,5 @@
import { Hash } from "crypto";
export interface Login { export interface Login {
email: string; email: string;
passwordHash: string passwordHash: string

@ -4,15 +4,16 @@ import { Login } from '../../models/login';
import { User } from 'src/app/models/user'; import { User } from 'src/app/models/user';
import { DatasharingService } from '../datasharing.service'; import { DatasharingService } from '../datasharing.service';
import { userInfo } from 'os'; import { userInfo } from 'os';
import {Router} from '@angular/router';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class LoginService { 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 = './graphql'
let url = 'https://greenvironment.net/graphql' let url = 'https://greenvironment.net/graphql'
@ -23,8 +24,15 @@ export class LoginService {
return this.http.post(url, this.buildJson(login)) return this.http.post(url, this.buildJson(login))
.subscribe(response => { .subscribe(response => {
console.log(response.text()); console.log(response.text());
this.loginSuccess();
this.updateUserInfo(response.json()) this.updateUserInfo(response.json())
}); }, errorCb
);
}
public loginSuccess(){
console.log('alles supi dupi');
//do routing
this.router.navigateByUrl('');
} }
public updateUserInfo(response : any){ public updateUserInfo(response : any){

Loading…
Cancel
Save