Fairoj : Automatic Login feature implemented on Link PD
This commit is contained in:
parent
e0f6cc5c02
commit
d04d5930a7
@ -1,11 +1,14 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild } from '@angular/router';
|
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild } from '@angular/router';
|
||||||
|
import { AwsService } from 'app/AwsService/aws.service';
|
||||||
|
import { DashboardService } from 'app/dashboard/dashboard.service';
|
||||||
import { PdTrigerService } from 'app/personal-discussion/pd-service/pd-triger.service';
|
import { PdTrigerService } from 'app/personal-discussion/pd-service/pd-triger.service';
|
||||||
|
import { environment } from 'environments/environment';
|
||||||
import { CognitoService } from '../AwsService/cognito.service';
|
import { CognitoService } from '../AwsService/cognito.service';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthGuard implements CanActivate, CanActivateChild {
|
export class AuthGuard implements CanActivate, CanActivateChild {
|
||||||
|
|
||||||
constructor(private router: Router,public shared:CognitoService,private pdTriggerService:PdTrigerService) { }
|
constructor(private router: Router,public shared:CognitoService,private pdTriggerService:PdTrigerService,private aws : AwsService,private dashBoardService:DashboardService) { }
|
||||||
|
|
||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||||
if (this.shared.getToken()) {
|
if (this.shared.getToken()) {
|
||||||
@ -20,7 +23,7 @@ export class AuthGuard implements CanActivate, CanActivateChild {
|
|||||||
}
|
}
|
||||||
|
|
||||||
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot,): boolean {
|
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot,): boolean {
|
||||||
console.log(route.queryParams.str)
|
console.log(route.routeConfig.path,route.routeConfig.path.includes('viewpd'))
|
||||||
let paramCheck = route.queryParams.str
|
let paramCheck = route.queryParams.str
|
||||||
if(paramCheck) {
|
if(paramCheck) {
|
||||||
paramCheck = paramCheck.split('/')
|
paramCheck = paramCheck.split('/')
|
||||||
@ -40,7 +43,11 @@ export class AuthGuard implements CanActivate, CanActivateChild {
|
|||||||
// alert("if");
|
// alert("if");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else if(paramCheck &&( route.routeConfig.path.includes('viewpd') || route.routeConfig.path.includes('personal_discussion'))){
|
||||||
|
console.log("Login Process started for Link user")
|
||||||
|
this.linkLogin()
|
||||||
|
}
|
||||||
|
else{
|
||||||
console.log(route);
|
console.log(route);
|
||||||
// debugger;
|
// debugger;
|
||||||
// else {
|
// else {
|
||||||
@ -53,6 +60,45 @@ export class AuthGuard implements CanActivate, CanActivateChild {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
linkLogin() {
|
||||||
|
let auth = { 'Username': environment.credential.uname, 'Password': environment.credential.pwd };
|
||||||
|
this.aws.dologin(auth).subscribe(res => {
|
||||||
|
// console.log("do login",res);
|
||||||
|
if (res !== undefined) {
|
||||||
|
this.getCommonSettings().then(()=>{
|
||||||
|
// local storage for validate user access
|
||||||
|
localStorage.setItem('user_role',res.idToken.payload["custom:role_id"]);
|
||||||
|
if(this.pdTriggerService.customer_url_data && this.pdTriggerService.customer_url_data.pdid && this.pdTriggerService.customer_url_data.rdmstr && this.pdTriggerService.customer_url_data.from == 'link') {
|
||||||
|
let data= this.pdTriggerService.customer_url_data
|
||||||
|
this.router.navigateByUrl('/personal_discussion/pdlist/viewpd?str='+data.pdid+'/'+data.rdmstr+'/link', {replaceUrl: true});
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
this.router.navigate(['/'])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, err => {
|
||||||
|
if (err.message == "New password is required.") {
|
||||||
|
alert("Please inform to administrator to set the password")
|
||||||
|
// this.newpassopen();
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
//alert(err.message);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
getCommonSettings(){
|
||||||
|
return new Promise((resolve,reject)=>{
|
||||||
|
return this.dashBoardService.getCommonSettingsConfig().subscribe(res=>{
|
||||||
|
let commonDetails:any = res;
|
||||||
|
if(commonDetails.dataStatus == true){
|
||||||
|
localStorage.setItem("commonSettings",JSON.stringify(commonDetails.records));
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// public getToken(): string {
|
// public getToken(): string {
|
||||||
// return localStorage.getItem('token');
|
// return localStorage.getItem('token');
|
||||||
|
|||||||
@ -615,7 +615,7 @@ export class ViewPdComponent implements OnInit, OnDestroy {
|
|||||||
data: {msg: msg,iscompleteenable: enable_complete,isCompleteAnywaydialog:true},
|
data: {msg: msg,iscompleteenable: enable_complete,isCompleteAnywaydialog:true},
|
||||||
disableClose: true,
|
disableClose: true,
|
||||||
minWidth: '30%',
|
minWidth: '30%',
|
||||||
maxWidth: '40%',
|
// maxWidth: '40%',
|
||||||
});
|
});
|
||||||
dialogRef.afterClosed()
|
dialogRef.afterClosed()
|
||||||
.subscribe(dataresult => {
|
.subscribe(dataresult => {
|
||||||
|
|||||||
@ -27,6 +27,10 @@ export const environment = {
|
|||||||
storageBucket: "",
|
storageBucket: "",
|
||||||
messagingSenderId: "906855209078",
|
messagingSenderId: "906855209078",
|
||||||
appId: "1:906855209078:web:c1583378f1fb2c71"
|
appId: "1:906855209078:web:c1583378f1fb2c71"
|
||||||
|
},
|
||||||
|
credential:{
|
||||||
|
uname:"officerbot@sine.com",
|
||||||
|
pwd:"bot1234"
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -74,6 +74,10 @@ export const environment = {
|
|||||||
s3_endpoint: '',
|
s3_endpoint: '',
|
||||||
accessToken:'',
|
accessToken:'',
|
||||||
//apiUrl:'http://localhost/sparqapi/api/'
|
//apiUrl:'http://localhost/sparqapi/api/'
|
||||||
|
credential:{
|
||||||
|
uname:"testofficerbot@sine.com",
|
||||||
|
pwd:"test1234"
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -73,5 +73,8 @@ export const environment = {
|
|||||||
s3_endpoint: '',
|
s3_endpoint: '',
|
||||||
accessToken:'',
|
accessToken:'',
|
||||||
//apiUrl:'http://localhost/sparqapi/api/'
|
//apiUrl:'http://localhost/sparqapi/api/'
|
||||||
|
credential:{
|
||||||
|
uname:"testofficerbot@sine.com",
|
||||||
|
pwd:"test1234"
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user