From 7a8499bff99995dbca5d975eee8a647f05614408 Mon Sep 17 00:00:00 2001 From: Rania Chowdhury Date: Wed, 27 Feb 2019 13:18:50 -0500 Subject: [PATCH] initial creation of login service and changes to authenticationand app module to set up --- src/app/app.module.ts | 4 +++- .../authentication.component.html | 3 ++- .../authentication.component.ts | 13 ++++++++++++- src/app/services/login.service.spec.ts | 12 ++++++++++++ src/app/services/login.service.ts | 19 +++++++++++++++++++ 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/app/services/login.service.spec.ts create mode 100644 src/app/services/login.service.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index d64a32c..d59b0af 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,6 +1,7 @@ import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; +import { HttpClientModule } from '@angular/common/http'; import { AppComponent } from './app.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; @@ -28,8 +29,9 @@ import { SignUpComponent } from './sign-up/sign-up.component'; imports: [ BrowserModule, BrowserAnimationsModule, + HttpClientModule, RouterModule.forRoot([ - + {path: 'dashboard', component: FrontpageComponent}, {path: '', component: AuthenticationComponent}, {path: 'generator-search', component: GeneratorSearchComponent}, diff --git a/src/app/authentication/authentication.component.html b/src/app/authentication/authentication.component.html index b21624b..36fb199 100644 --- a/src/app/authentication/authentication.component.html +++ b/src/app/authentication/authentication.component.html @@ -14,7 +14,8 @@ - + +


diff --git a/src/app/authentication/authentication.component.ts b/src/app/authentication/authentication.component.ts index 03188b8..03217fe 100644 --- a/src/app/authentication/authentication.component.ts +++ b/src/app/authentication/authentication.component.ts @@ -1,4 +1,9 @@ import { Component, OnInit } from '@angular/core'; +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { LoginService } from '../services/login.service' + +@Injectable() @Component({ selector: 'app-authentication', @@ -7,9 +12,15 @@ import { Component, OnInit } from '@angular/core'; }) export class AuthenticationComponent implements OnInit { - constructor() { } + constructor(private data: LoginService) { } ngOnInit() { + + this.data.authorizeUser().subscribe(data => + { + // this.users$ = data; + }); + } } diff --git a/src/app/services/login.service.spec.ts b/src/app/services/login.service.spec.ts new file mode 100644 index 0000000..024e696 --- /dev/null +++ b/src/app/services/login.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { LoginService } from './login.service'; + +describe('LoginService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: LoginService = TestBed.get(LoginService); + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/login.service.ts b/src/app/services/login.service.ts new file mode 100644 index 0000000..3b5dfee --- /dev/null +++ b/src/app/services/login.service.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http' +import { Observable } from 'rxjs/Observable'; + +@Injectable({ + providedIn: 'root' +}) +export class LoginService { + + constructor(private http: HttpClient) { } + + authorizeUser() { + return this.http.get('http://sd5-backend.engr.uconn.edu/auth') + } + + getUser() { + return this.http.get('http://sd5-backend.engr.uconn.edu/user/me') + } +}