diff options
author | Patrick Brady <patrick.brady@att.com> | 2020-03-24 15:44:15 -0700 |
---|---|---|
committer | Patrick Brady <patrick.brady@att.com> | 2020-03-24 16:47:23 -0700 |
commit | 0141df20b1f533cd2acabdf7ea986aebab8d6868 (patch) | |
tree | 7df75e7fd455aeb0ccedeac6be801d4cab4d508d /src/app/vnfs/userlogin-form | |
parent | 179fea047479a44ef2fb0490c272f7f97127bbe9 (diff) |
Authentication support for cdt
-Adding a password box to cdt
-Adding a function to check login by making a request
to appc
-Moving username and authentication to session storage
from localstorage so that it is not saved in the browser
-Removing the hardcoded credentials from the cdt proxy
since these are coming from the cdt login form now
Change-Id: I8bd829a22d1b83829c1d53637dc1ad035d1030e9
Signed-off-by: Patrick Brady <patrick.brady@att.com>
Issue-ID: APPC-1854
Diffstat (limited to 'src/app/vnfs/userlogin-form')
3 files changed, 88 insertions, 15 deletions
diff --git a/src/app/vnfs/userlogin-form/userlogin-form.component.html b/src/app/vnfs/userlogin-form/userlogin-form.component.html index 3f18b72..069583e 100644 --- a/src/app/vnfs/userlogin-form/userlogin-form.component.html +++ b/src/app/vnfs/userlogin-form/userlogin-form.component.html @@ -1,7 +1,7 @@ <!-- ============LICENSE_START========================================== =================================================================== -Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved. =================================================================== Unless otherwise specified, all software contained herein is licensed @@ -32,6 +32,10 @@ limitations under the License. [(ngModel)]="userId" name="userId" value="" #user="ngModel" (ngModelChange)="validateUserName()"> <span class="error-message">{{errorMessage}}</span> </div> + <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> + <input type="password" placeholder="Enter password" class="mdl-textfield__input" id="password" required + [(ngModel)]="password" name="password" value="" (ngModelChange)="validatePassword()" > + </div> <div class="form-group text-right"> <button type="submit" [disabled]="invalid" @@ -43,4 +47,4 @@ limitations under the License. </div> </div> </div> -</div>
\ No newline at end of file +</div> diff --git a/src/app/vnfs/userlogin-form/userlogin-form.component.spec.ts b/src/app/vnfs/userlogin-form/userlogin-form.component.spec.ts index 712d1bf..bf8431b 100644 --- a/src/app/vnfs/userlogin-form/userlogin-form.component.spec.ts +++ b/src/app/vnfs/userlogin-form/userlogin-form.component.spec.ts @@ -1,7 +1,7 @@ /* ============LICENSE_START========================================== =================================================================== -Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved. Modification Copyright (C) 2018 IBM =================================================================== @@ -64,7 +64,7 @@ describe('userloginFormComponent', () => { fixture = TestBed.createComponent(userloginFormComponent); component = fixture.componentInstance; fixture.detectChanges(); - // localStorage['userId'] = "testUser" + // sessionStorage['userId'] = "testUser" component.userId = 'test Usr'; }); @@ -99,7 +99,7 @@ describe('userloginFormComponent', () => { expect(url.length).toBe(5); expect(url[0]).toEqual('/'); expect(url[1]).toEqual('h'); - expect(localStorage['userId']).toBe('test Usr'); + expect(sessionStorage['userId']).toBe('test Usr'); })); it('test validateUserName function', () => { diff --git a/src/app/vnfs/userlogin-form/userlogin-form.component.ts b/src/app/vnfs/userlogin-form/userlogin-form.component.ts index c62e9bb..7ed087e 100644 --- a/src/app/vnfs/userlogin-form/userlogin-form.component.ts +++ b/src/app/vnfs/userlogin-form/userlogin-form.component.ts @@ -1,7 +1,7 @@ /* ============LICENSE_START========================================== =================================================================== -Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved. =================================================================== Unless otherwise specified, all software contained herein is licensed @@ -23,19 +23,24 @@ import {Component, OnInit} from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import {EmitterService} from '../../shared/services/emitter.service'; +import { environment } from '../../../environments/environment'; +import { HttpUtilService } from '../../shared/services/httpUtil/http-util.service'; import {Router} from '@angular/router'; +import { NgProgress } from 'ngx-progressbar'; import {UtilityService} from '../../shared/services/utilityService/utility.service'; +import { Http, Response, Headers, RequestOptions } from '@angular/http'; @Component({selector: 'app-mvnfs-form', templateUrl: './userlogin-form.component.html', styleUrls: ['./userlogin-form.component.css']}) export class userloginFormComponent implements OnInit { userId: string = ''; + password: string = ''; returnUrl:string invalid = true; errorMessage = ''; - constructor(private router: Router, private utiltiy: UtilityService, private route: ActivatedRoute - ) { + constructor(private router: Router, private utiltiy: UtilityService, private route: ActivatedRoute, + private http: Http, private ngProgress: NgProgress) { } ngOnInit() { @@ -44,12 +49,57 @@ export class userloginFormComponent implements OnInit { getData() { - localStorage['userId'] = this.userId; - localStorage['apiToken'] = this.utiltiy.randomId(); - EmitterService - .get('userLogin') - .emit(this.userId); - this.router.navigateByUrl(this.returnUrl); + this.ngProgress.start(); + var getHeader = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON + var authStr = btoa(this.userId + ':' + this.password); + const options = { + headers: new Headers({ + 'Content-Type': 'application/json', + 'Authorization': 'Basic ' + authStr + }), + observe: 'response' + }; + const data = { + 'input': { + 'design-request': { + 'request-id': '1', + 'action': 'getDesigns', + 'payload': '{"userID": "","filter":"reference"}' + } + } + }; + const x = JSON.parse(data.input['design-request']['payload']); + x.userID = this.userId; + data.input['design-request']['payload'] = JSON.stringify(x); + console.log("auth " + btoa(this.userId + ':' + this.password)); + this.http.post(environment.getDesigns,data,options).subscribe(resp => { + console.log("status " + resp.status); + if(resp.status == 200){ + console.log('logged in'); + sessionStorage['userId'] = this.userId; + sessionStorage['apiToken'] = this.utiltiy.randomId(); + sessionStorage['auth'] = authStr; + EmitterService + .get('userLogin') + .emit(this.userId); + this.router.navigateByUrl(this.returnUrl); + } else { + console.log("Invalid user or password"); + this.invalid = true; + this.errorMessage = 'Invalid user or password'; + } + }, error => { + console.log(error); + if(error.status == 401){ + this.invalid = true; + this.errorMessage = 'Invalid user or password'; + } else { + this.invalid = true; + this.errorMessage = 'Incorrect login or connection error.'; + } + }); + console.log("After"); + } validateUserName(){ @@ -57,7 +107,7 @@ export class userloginFormComponent implements OnInit { this.errorMessage = ''; this.invalid = true; }else if(this.userId.startsWith(' ') || this.userId.endsWith(' ')){ - this.errorMessage = 'Leading and trailing space is not allowed'; + this.errorMessage = 'Leading and trailing space is not allowed in username'; this.invalid = true; } else if(this.userId.includes(' ')){ this.errorMessage = 'More than one space is not allowed in username'; @@ -70,5 +120,24 @@ export class userloginFormComponent implements OnInit { this.errorMessage = ''; } } + + validatePassword(){ + if (!this.password.trim() || this.password.length < 1) { + this.errorMessage = ''; + this.invalid = true; + }else if(this.password.startsWith(' ') || this.password.endsWith(' ')){ + this.errorMessage = 'Leading and trailing space is not allowed in password'; + this.invalid = true; + } else if(this.password.includes(' ')){ + this.errorMessage = 'More than one space is not allowed in password'; + this.invalid = true; + } else if(this.password.length > 50) { + this.errorMessage = 'Password should be of minimum one character and maximum 50 character'; + this.invalid = true; + }else { + this.invalid = false; + this.errorMessage = ''; + } + } } |