--- /dev/null
+/* Copyright (c) 2019 AT&T Intellectual Property. #\r
+# #\r
+# Licensed under the Apache License, Version 2.0 (the "License"); #\r
+# you may not use this file except in compliance with the License. #\r
+# You may obtain a copy of the License at #\r
+# #\r
+# http://www.apache.org/licenses/LICENSE-2.0 #\r
+# #\r
+# Unless required by applicable law or agreed to in writing, software #\r
+# distributed under the License is distributed on an "AS IS" BASIS, #\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #\r
+# See the License for the specific language governing permissions and #\r
+# limitations under the License. #\r
+##############################################################################*/\r
+\r
+\r
+import { Component, OnInit } from '@angular/core';\r
+import { Router, ActivatedRoute } from '@angular/router';\r
+import { routerTransition } from '../router.animations';\r
+import { HttpClient } from '@angular/common/http';\r
+import { AppGlobals } from '../app.global';\r
+import { UserService } from '../shared/services/user.service';\r
+import { CookieService } from 'ngx-cookie-service';\r
+import { AuthService } from 'app/shared/services/auth.service';\r
+import { AlertModalComponent } from '../shared/modules/alert-modal/alert-modal.component';\r
+import { MatDialog } from '@angular/material';\r
+\r
+\r
+\r
+@Component({\r
+ selector: 'app-login',\r
+ templateUrl: './login.component.html',\r
+ providers: [],\r
+ styleUrls: ['./login.component.scss'],\r
+ animations: [routerTransition()]\r
+})\r
+export class LoginComponent implements OnInit {\r
+ public User;\r
+ public authResult;\r
+ public returnUrl;\r
+ public loginFailed = false;\r
+\r
+ constructor(public router: Router, \r
+ private route: ActivatedRoute,\r
+ private http: HttpClient,\r
+ private _global: AppGlobals,\r
+ private cookie: CookieService,\r
+ private dialog: MatDialog,\r
+ private auth: AuthService\r
+ ) {}\r
+\r
+ ngOnInit() {\r
+ this.User={};\r
+ this.User.email = "";\r
+ this.User.password = "";\r
+ this.authResult={};\r
+\r
+ this.auth.logout();\r
+\r
+ this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';\r
+ }\r
+\r
+ onLoggedin() {\r
+ //alert("User email: " + this.User.email + " User password: " + this.User.password);\r
+ this.auth.login(this.User) //need to use /authorization\r
+ .subscribe(\r
+ (authResult) => {\r
+ if(this.cookie.check('access_token')){\r
+ this.router.navigate([this.returnUrl]);\r
+ }else {\r
+ if (authResult['user'] && !authResult['user']['enabled']) {\r
+ this.dialog.open(AlertModalComponent, {\r
+ width: '450px',\r
+ data: {\r
+ type: 'ok',\r
+ message: "Your account is not yet enabled. Please wait for approval."\r
+ }\r
+ });\r
+ }\r
+ else {\r
+ this.dialog.open(AlertModalComponent, {\r
+ width: '450px',\r
+ data: {\r
+ type: 'alert',\r
+ message: "Something went wrong... Please Refresh and try again."\r
+ }\r
+ });\r
+ }\r
+ }\r
+ },\r
+ (error) => {\r
+ this.loginFailed = true;\r
+ this.dialog.open(AlertModalComponent, {\r
+ width: '450px',\r
+ data: {\r
+ type: 'alert',\r
+ message: error + " Please try again"\r
+ }\r
+ });\r
+ });\r
+ }\r
+}\r