Merge branch 'max_dev' of Software_Engineering_I/greenvironment-frontend into master
commit
a11a5c4473
@ -1 +1,2 @@
|
|||||||
|
<app-scaffold id="headerbar"></app-scaffold>
|
||||||
<router-outlet></router-outlet>
|
<router-outlet></router-outlet>
|
@ -0,0 +1,4 @@
|
|||||||
|
export interface Login {
|
||||||
|
email: string;
|
||||||
|
passwordHash: string
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
export class User {
|
||||||
|
loggedIn : boolean
|
||||||
|
userID : number
|
||||||
|
username : string
|
||||||
|
handle : string
|
||||||
|
email : string
|
||||||
|
points : number
|
||||||
|
level : number
|
||||||
|
|
||||||
|
friendIDs : number[]
|
||||||
|
groupIDs : number[]
|
||||||
|
chatIDs : number[]
|
||||||
|
|
||||||
|
requestIDs : number[]
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { DatasharingService } from './datasharing.service';
|
||||||
|
|
||||||
|
describe('DatasharingService', () => {
|
||||||
|
beforeEach(() => TestBed.configureTestingModule({}));
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
const service: DatasharingService = TestBed.get(DatasharingService);
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,18 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { BehaviorSubject } from 'rxjs';
|
||||||
|
import { User } from '../models/user';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class DatasharingService {
|
||||||
|
|
||||||
|
private userInfoSource = new BehaviorSubject<User>(new User())
|
||||||
|
currentUserInfo = this.userInfoSource.asObservable();
|
||||||
|
|
||||||
|
constructor() { }
|
||||||
|
|
||||||
|
changeUserInfo(pUserInfo: User) {
|
||||||
|
this.userInfoSource.next(pUserInfo)
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,57 @@
|
|||||||
import { Injectable } from '@angular/core';
|
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';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class LoginService {
|
export class LoginService {
|
||||||
|
|
||||||
constructor() { }
|
constructor(private http: Http, private data: DatasharingService) { }
|
||||||
|
|
||||||
|
public login(login : Login) {
|
||||||
|
|
||||||
|
//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(login))
|
||||||
|
.subscribe(response => {
|
||||||
|
console.log(response.text());
|
||||||
|
this.updateUserInfo(response.json())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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(login: Login): any {
|
||||||
|
const body = {query: `mutation($email: String, $pwHash: String) {
|
||||||
|
login(email: $email, passwordHash: $pwHash) {id, name, handle, points, level, friends{id}, groups{id},chats{id}}
|
||||||
|
}`, variables: {
|
||||||
|
email: login.email,
|
||||||
|
pwHash: login.passwordHash,
|
||||||
|
}};
|
||||||
|
return body;
|
||||||
}
|
}
|
||||||
|
}//add ,receivedRequests{id} later
|
||||||
|
Loading…
Reference in New Issue