2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
5 ===================================================================
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19 ============LICENSE_END============================================
22 import {Component, OnInit} from '@angular/core';
24 import { ActivatedRoute } from '@angular/router';
25 import {EmitterService} from '../../shared/services/emitter.service';
26 import { environment } from '../../../environments/environment';
27 import { HttpUtilService } from '../../shared/services/httpUtil/http-util.service';
28 import {Router} from '@angular/router';
29 import { NgProgress } from 'ngx-progressbar';
30 import {UtilityService} from '../../shared/services/utilityService/utility.service';
31 import { Http, Response, Headers, RequestOptions } from '@angular/http';
33 @Component({selector: 'app-mvnfs-form', templateUrl: './userlogin-form.component.html', styleUrls: ['./userlogin-form.component.css']})
34 export class userloginFormComponent implements OnInit {
37 password: string = '';
42 constructor(private router: Router, private utiltiy: UtilityService, private route: ActivatedRoute,
43 private http: Http, private ngProgress: NgProgress) {
47 this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/home';
52 this.ngProgress.start();
53 var getHeader = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON
54 var authStr = btoa(this.userId + ':' + this.password);
56 headers: new Headers({
57 'Content-Type': 'application/json',
58 'Authorization': 'Basic ' + authStr
66 'action': 'getDesigns',
67 'payload': '{"userID": "","filter":"reference"}'
71 const x = JSON.parse(data.input['design-request']['payload']);
72 x.userID = this.userId;
73 data.input['design-request']['payload'] = JSON.stringify(x);
74 console.log("auth " + btoa(this.userId + ':' + this.password));
75 this.http.post(environment.getDesigns,data,options).subscribe(resp => {
76 console.log("status " + resp.status);
77 if(resp.status == 200){
78 console.log('logged in');
79 sessionStorage['userId'] = this.userId;
80 sessionStorage['apiToken'] = this.utiltiy.randomId();
81 sessionStorage['auth'] = authStr;
85 this.router.navigateByUrl(this.returnUrl);
87 console.log("Invalid user or password");
89 this.errorMessage = 'Invalid user or password';
93 if(error.status == 401){
95 this.errorMessage = 'Invalid user or password';
98 this.errorMessage = 'Incorrect login or connection error.';
101 console.log("After");
106 if (!this.userId.trim() || this.userId.length < 1) {
107 this.errorMessage = '';
109 }else if(this.userId.startsWith(' ') || this.userId.endsWith(' ')){
110 this.errorMessage = 'Leading and trailing space is not allowed in username';
112 } else if(this.userId.includes(' ')){
113 this.errorMessage = 'More than one space is not allowed in username';
115 } else if(this.userId.length > 50) {
116 this.errorMessage = 'Username should be of minimum one character and maximum 50 character';
119 this.invalid = false;
120 this.errorMessage = '';
125 if (!this.password.trim() || this.password.length < 1) {
126 this.errorMessage = '';
128 }else if(this.password.startsWith(' ') || this.password.endsWith(' ')){
129 this.errorMessage = 'Leading and trailing space is not allowed in password';
131 } else if(this.password.includes(' ')){
132 this.errorMessage = 'More than one space is not allowed in password';
134 } else if(this.password.length > 50) {
135 this.errorMessage = 'Password should be of minimum one character and maximum 50 character';
138 this.invalid = false;
139 this.errorMessage = '';