bkup files deleted : ps
This commit is contained in:
parent
f1f43227f9
commit
cfcc72cbb6
@ -1,778 +0,0 @@
|
|||||||
import { Injectable } from "@angular/core";
|
|
||||||
import {
|
|
||||||
AuthenticationDetails,
|
|
||||||
CognitoUserPool,
|
|
||||||
CognitoUser,
|
|
||||||
CognitoUserAttribute,
|
|
||||||
ICognitoUserAttributeData,
|
|
||||||
ISignUpResult,
|
|
||||||
CognitoUserSession
|
|
||||||
} from "amazon-cognito-identity-js";
|
|
||||||
import * as AWS from "aws-sdk";
|
|
||||||
|
|
||||||
import { Observable } from "rxjs/Observable";
|
|
||||||
import "rxjs/add/operator/map";
|
|
||||||
// import AWS from "aws-sdk/dist/aws-sdk";
|
|
||||||
|
|
||||||
//environment
|
|
||||||
import { environment } from '../../environments/environment';
|
|
||||||
|
|
||||||
import { Http, Headers, RequestOptions } from '@angular/http';
|
|
||||||
import { HttpClient } from '@angular/common/http';
|
|
||||||
import 'rxjs/add/operator/map';
|
|
||||||
import { CognitoService } from './cognito.service';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// const sineedge_poolData = {
|
|
||||||
// UserPoolId: "ap-south-1_y7dt3iEaX", //ap-south-1_qQ85yQZJO UserName :SPARQ_SINEEDGE_DEV
|
|
||||||
// ClientId: "291qt4smn5pql6o8cc2hi201lj" // ClientName: SINEEDGE_DEV_WEB
|
|
||||||
// };
|
|
||||||
const sineedgedev_poolData = {
|
|
||||||
UserPoolId: "ap-south-1_qQ85yQZJO", // UserName :SPARQ_SINEEDGE_DEV
|
|
||||||
ClientId: "67b4fnbuols5upms5to8bvqddh"// ClientName: SINEEDGE_DEV_WEB
|
|
||||||
}
|
|
||||||
// client id changed on 12-04-2019 by kms
|
|
||||||
//ClientId: "2o5c3cs9k3als16nqhp3irh8rs"
|
|
||||||
|
|
||||||
const lender_poolData = {
|
|
||||||
UserPoolId: "ap-south-1_hFiGyr1Gw", // Username :SPARQ_LENDER_DEV
|
|
||||||
ClientId: "6egsdssf0i7h2o9mscqgqbn788" // ClientName:LENDER_DEV_WEB
|
|
||||||
};
|
|
||||||
const vendor_poolData = {
|
|
||||||
UserPoolId: "ap-south-1_K57yPaWxV",
|
|
||||||
ClientId: ""
|
|
||||||
}
|
|
||||||
// const sineedgeUserPool = new CognitoUserPool(sineedge_poolData);
|
|
||||||
const lenderUserPool = new CognitoUserPool(lender_poolData);
|
|
||||||
const sineedgedevUserpool = new CognitoUserPool(sineedgedev_poolData);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Identity PoolID
|
|
||||||
*/
|
|
||||||
const sineedgeIdentity = "ap-south-1:9a551eab-97cf-4991-b677-2f9bcd058961";//"ap-south-1:9a551eab-97cf-4991-b677-2f9bcd058961";
|
|
||||||
const lenderIdentity = "ap-south-1:ca22dabc-db59-4af5-9bb8-265f7ec95907";
|
|
||||||
const vendorIdenttiy = "ap-south-1:5ad3ce43-4260-4273-87b2-e6a377b8e874";
|
|
||||||
// serviceProvider
|
|
||||||
const apiurl = environment.apiEndpoint;
|
|
||||||
//const apiurl = "http://ssa.sineedge.com/sparqapi/api/";
|
|
||||||
//const apiurl = "http://localhost/sparqapi/api/";
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: "root"
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
export class AwsService {
|
|
||||||
//public static _REGION = environment.region;
|
|
||||||
mySecData: any;
|
|
||||||
|
|
||||||
cognitoUser: any;
|
|
||||||
jwttoken: any;
|
|
||||||
cognitousers: any;
|
|
||||||
localUserId:any = '';
|
|
||||||
constructor(public http: Http, public RequestOptions: RequestOptions,public shared:CognitoService) { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Login Function
|
|
||||||
* @param authenticationData inside of(email and password for login user)
|
|
||||||
* By sriram
|
|
||||||
*/
|
|
||||||
dologin(authenticationData) {
|
|
||||||
//(authenticationData);
|
|
||||||
const authenticationDetails = new AuthenticationDetails(authenticationData);
|
|
||||||
let Newpassword = authenticationData.newpassword;
|
|
||||||
let attributesData = [];
|
|
||||||
const userData = {
|
|
||||||
Username: authenticationData.Username, // User email id
|
|
||||||
Pool: sineedgedevUserpool // user Pool ID
|
|
||||||
};
|
|
||||||
let cognitoUser = new CognitoUser(userData);
|
|
||||||
return Observable.create(observer => {
|
|
||||||
cognitoUser.authenticateUser(authenticationDetails, {
|
|
||||||
newPasswordRequired: (userAttributes, requiredAttributes) => { // new password set
|
|
||||||
cognitoUser.completeNewPasswordChallenge(
|
|
||||||
Newpassword,
|
|
||||||
attributesData,
|
|
||||||
{
|
|
||||||
onSuccess: function (result) {
|
|
||||||
observer.next(result);
|
|
||||||
observer.complete();
|
|
||||||
},
|
|
||||||
onFailure: function (err) {
|
|
||||||
//(err);
|
|
||||||
observer.error(err);
|
|
||||||
//LoginComponent.prototype.open();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
onSuccess: function (result) { // success user login
|
|
||||||
// let accessToken = result.getAccessToken().getJwtToken();
|
|
||||||
////(result);
|
|
||||||
//window.localStorage.setItem('Currentuser', '1');
|
|
||||||
observer.next(result);
|
|
||||||
observer.complete();
|
|
||||||
},
|
|
||||||
onFailure: function (err) { // error user login
|
|
||||||
|
|
||||||
alert(err.message);
|
|
||||||
observer.error(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* End of the login function
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* User forget password
|
|
||||||
*/
|
|
||||||
userforgotpass(auth) {
|
|
||||||
////(auth);
|
|
||||||
const userData = {
|
|
||||||
Username: auth.Username,
|
|
||||||
Pool: sineedgedevUserpool
|
|
||||||
};
|
|
||||||
let cognitoUser = new CognitoUser(userData);
|
|
||||||
return Observable.create(observe => {
|
|
||||||
cognitoUser.forgotPassword({
|
|
||||||
onSuccess: function (data) {
|
|
||||||
// successfully initiated reset password request
|
|
||||||
//('CodeDeliveryData from forgotPassword: ' + data);
|
|
||||||
observe.next(data);
|
|
||||||
},
|
|
||||||
onFailure: function (err) {
|
|
||||||
alert(err.message || JSON.stringify(err));
|
|
||||||
},
|
|
||||||
//Optional automatic callback
|
|
||||||
inputVerificationCode: function (data) {
|
|
||||||
//('Code sent to: ' + data);
|
|
||||||
var verificationCode = prompt('Enter Verification Code Sent to Mobile ', '');
|
|
||||||
var newPassword = prompt('Enter New Password ', '');
|
|
||||||
cognitoUser.confirmPassword(verificationCode, newPassword, {
|
|
||||||
onSuccess() {
|
|
||||||
//('Password confirmed!');
|
|
||||||
},
|
|
||||||
onFailure(err) {
|
|
||||||
//('Password not confirmed!');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* End of the function
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logout function
|
|
||||||
*/
|
|
||||||
logout(){
|
|
||||||
|
|
||||||
return Observable.create(observe=>{
|
|
||||||
this.shared.getCurrentUser().signOut();
|
|
||||||
|
|
||||||
observe.next();
|
|
||||||
|
|
||||||
observe.complete();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Config function
|
|
||||||
*/
|
|
||||||
getconfig() {
|
|
||||||
let session:any = this.shared.getAccessToken() || "";
|
|
||||||
let config = "";
|
|
||||||
config += AWS.config.region = "ap-south-1";
|
|
||||||
config += AWS.config.credentials = new AWS.CognitoIdentityCredentials({
|
|
||||||
IdentityPoolId: sineedgeIdentity, // for sineedge_DEV
|
|
||||||
Logins: {
|
|
||||||
"cognito-idp.ap-south-1.amazonaws.com/ap-south-1_qQ85yQZJO": session
|
|
||||||
.getIdToken()
|
|
||||||
.getJwtToken()
|
|
||||||
}
|
|
||||||
// NOTE: getSession must be called to authenticate user before calling getUserAttributes
|
|
||||||
});
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* admin Disable user
|
|
||||||
* @param userdata
|
|
||||||
* @param awsName
|
|
||||||
*/
|
|
||||||
admindisabelUser(userdata, awsName) {
|
|
||||||
let session:any = this.shared.getAccessToken() || "";
|
|
||||||
this.getconfig();
|
|
||||||
// let config = "";
|
|
||||||
// AWS.config.region = "ap-south-1";//environment.region;
|
|
||||||
// AWS.config.credentials = new AWS.CognitoIdentityCredentials({
|
|
||||||
// IdentityPoolId: sineedgeIdentity, // for sineedge_DEV
|
|
||||||
// Logins: {
|
|
||||||
// "cognito-idp.ap-south-1.amazonaws.com/ap-south-1_qQ85yQZJO": session
|
|
||||||
// .getIdToken()
|
|
||||||
// .getJwtToken()
|
|
||||||
// }
|
|
||||||
// // NOTE: getSession must be called to authenticate user before calling getUserAttributes
|
|
||||||
// });
|
|
||||||
let userGroup = session.idToken.payload["cognito:groups"].filter(
|
|
||||||
usergroup => usergroup == "ADMIN"
|
|
||||||
)[0];
|
|
||||||
//cognitosdata = 7;
|
|
||||||
let params: any;
|
|
||||||
if (userGroup == 'ADMIN') {
|
|
||||||
if (userdata.fk_entity_type_id == 1) {
|
|
||||||
params = {
|
|
||||||
UserPoolId: sineedgedev_poolData.UserPoolId, /* required */
|
|
||||||
Username: awsName /* required */
|
|
||||||
};
|
|
||||||
} else if (userdata.fk_entity_type_id == 2) {
|
|
||||||
params = {
|
|
||||||
UserPoolId: lender_poolData.UserPoolId, /* required */
|
|
||||||
Username: awsName /* required */
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return Observable.create(observe => {
|
|
||||||
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
|
|
||||||
cognitoidentityserviceprovider.adminDisableUser(params, function (err, data) {
|
|
||||||
if (err) console.log(err, err.stack); // an error occurred
|
|
||||||
observe.next("0"); // successful response
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Admin enable user
|
|
||||||
* @param userdata
|
|
||||||
* @param awsName
|
|
||||||
*/
|
|
||||||
adminenableUser(userdata, awsName) {
|
|
||||||
let session:any = this.shared.getAccessToken() || "";
|
|
||||||
// this.getconfig();
|
|
||||||
let config = "";
|
|
||||||
AWS.config.region = "ap-south-1";
|
|
||||||
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
|
|
||||||
IdentityPoolId: sineedgeIdentity, // for sineedge_DEV
|
|
||||||
Logins: {
|
|
||||||
"cognito-idp.ap-south-1.amazonaws.com/ap-south-1_qQ85yQZJO": session
|
|
||||||
.getIdToken()
|
|
||||||
.getJwtToken()
|
|
||||||
}
|
|
||||||
// NOTE: getSession must be called to authenticate user before calling getUserAttributes
|
|
||||||
});
|
|
||||||
let userGroup = session.idToken.payload["cognito:groups"].filter(
|
|
||||||
usergroup => usergroup == "ADMIN"
|
|
||||||
)[0];
|
|
||||||
//cognitosdata = 7;
|
|
||||||
let params: any;
|
|
||||||
if (userGroup == 'ADMIN') {
|
|
||||||
|
|
||||||
if (userdata.fk_entity_type_id == 1) {
|
|
||||||
params = {
|
|
||||||
UserPoolId: sineedgedev_poolData.UserPoolId, /* required */
|
|
||||||
Username: awsName /* required */
|
|
||||||
};
|
|
||||||
} else if (userdata.fk_entity_type_id == 2) {
|
|
||||||
params = {
|
|
||||||
UserPoolId: lender_poolData.UserPoolId, /* required */
|
|
||||||
Username: awsName /* required */
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return Observable.create(observe => {
|
|
||||||
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
|
|
||||||
cognitoidentityserviceprovider.adminEnableUser(params, function (err, data) {
|
|
||||||
if (err) console.log(err, err.stack); // an error occurred
|
|
||||||
observe.next("1"); // successful response
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
register(userData) {
|
|
||||||
let session:any = this.shared.getAccessToken() || "";
|
|
||||||
|
|
||||||
this.getconfig();
|
|
||||||
let registeredData: any = "";
|
|
||||||
let params: any;
|
|
||||||
let userGroup = session.idToken.payload["cognito:groups"].filter(
|
|
||||||
usergroup => usergroup == "ADMIN"
|
|
||||||
)[0];
|
|
||||||
// (userGroup);
|
|
||||||
if (userGroup == "ADMIN") {
|
|
||||||
if (userData.type.entity_type_id == 1) {
|
|
||||||
params = {
|
|
||||||
UserPoolId: sineedgedev_poolData.UserPoolId /* required */,
|
|
||||||
Username: userData.email /* required */,
|
|
||||||
DesiredDeliveryMediums: [
|
|
||||||
"EMAIL"
|
|
||||||
/* more items */
|
|
||||||
],
|
|
||||||
// ForceAliasCreation: true || false,
|
|
||||||
MessageAction: "SUPPRESS",
|
|
||||||
TemporaryPassword: "temp1234",
|
|
||||||
UserAttributes: [
|
|
||||||
{
|
|
||||||
Name: "email" /* required */,
|
|
||||||
Value: userData.email
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "phone_number" /* required */,
|
|
||||||
Value: "+91" + userData.phone
|
|
||||||
},{
|
|
||||||
Name: "custom:role_id" /* required */,
|
|
||||||
Value: userData.role.role_id
|
|
||||||
}
|
|
||||||
/* more items */
|
|
||||||
]
|
|
||||||
};
|
|
||||||
} else if (userData.type.entity_type_id == 2) {
|
|
||||||
params = {
|
|
||||||
UserPoolId: lender_poolData.UserPoolId /* required */,
|
|
||||||
Username: userData.email /* required */,
|
|
||||||
DesiredDeliveryMediums: [
|
|
||||||
"EMAIL"
|
|
||||||
/* more items */
|
|
||||||
],
|
|
||||||
// ForceAliasCreation: true || false,
|
|
||||||
MessageAction: "SUPPRESS",
|
|
||||||
TemporaryPassword: "temp1234",
|
|
||||||
UserAttributes: [
|
|
||||||
{
|
|
||||||
Name: "email" /* required */,
|
|
||||||
Value: userData.email
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "phone_number" /* required */,
|
|
||||||
Value: "+91" + userData.phone
|
|
||||||
},{
|
|
||||||
Name: "custom:role_id" /* required */,
|
|
||||||
Value: userData.role.role_id
|
|
||||||
}
|
|
||||||
/* more items */
|
|
||||||
]
|
|
||||||
};
|
|
||||||
}else if(userData.type.entity_type_id == 3){
|
|
||||||
params = {
|
|
||||||
UserPoolId: vendor_poolData.UserPoolId /* required */,
|
|
||||||
Username: userData.email /* required */,
|
|
||||||
DesiredDeliveryMediums: [
|
|
||||||
"EMAIL"
|
|
||||||
/* more items */
|
|
||||||
],
|
|
||||||
// ForceAliasCreation: true || false,
|
|
||||||
MessageAction: "SUPPRESS",
|
|
||||||
TemporaryPassword: "temp1234",
|
|
||||||
UserAttributes: [
|
|
||||||
{
|
|
||||||
Name: "email" /* required */,
|
|
||||||
Value: userData.email
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "phone_number" /* required */,
|
|
||||||
Value: "+91" + userData.phone
|
|
||||||
},{
|
|
||||||
Name: "custom:role_id" /* required */,
|
|
||||||
Value: userData.role.role_id
|
|
||||||
}
|
|
||||||
/* more items */
|
|
||||||
]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return Observable.create(observe => {
|
|
||||||
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
|
|
||||||
|
|
||||||
cognitoidentityserviceprovider.adminCreateUser(params, (
|
|
||||||
err,
|
|
||||||
data
|
|
||||||
) => {
|
|
||||||
if (err) { alert(err.message); }
|
|
||||||
// an error occurred
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
observe.next(data);
|
|
||||||
|
|
||||||
|
|
||||||
// successful response
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
return alert('Admin Only create user');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
UserGroup(cognitodata, userData) {
|
|
||||||
//console.log(cognitodata);
|
|
||||||
this.getconfig();
|
|
||||||
//console.log(userData);
|
|
||||||
//let cognitodata = "539bfefa-ae42-4bee-bf79-4b15d1a2af7f";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let params: any;
|
|
||||||
|
|
||||||
if(userData.userid === undefined){
|
|
||||||
params = {
|
|
||||||
GroupName: "ADMIN" /* required */,
|
|
||||||
UserPoolId: sineedgedev_poolData.UserPoolId,//"ap-south-1_y7dt3iEaX" /* required */,
|
|
||||||
Username: cognitodata.User.Username //'539bfefa-ae42-4bee-bf79-4b15d1a2af7f' /* required */
|
|
||||||
};
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
params = {
|
|
||||||
GroupName: "ADMIN" /* required */,
|
|
||||||
UserPoolId: sineedgedev_poolData.UserPoolId,//"ap-south-1_y7dt3iEaX" /* required */,
|
|
||||||
Username: userData.aws_name //'539bfefa-ae42-4bee-bf79-4b15d1a2af7f' /* required */
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
//console.log(params);
|
|
||||||
return Observable.create(observe=>{
|
|
||||||
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
|
|
||||||
|
|
||||||
cognitoidentityserviceprovider.adminAddUserToGroup(params, function (
|
|
||||||
err,
|
|
||||||
data
|
|
||||||
) {
|
|
||||||
if (err) {
|
|
||||||
alert(err.message);
|
|
||||||
}//(err, err.stack);
|
|
||||||
// an error occurred
|
|
||||||
else {//(data);
|
|
||||||
|
|
||||||
observe.next(cognitodata);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* admin User update
|
|
||||||
* @param username,clientid params
|
|
||||||
**/
|
|
||||||
adminUpdateuser(user, cognitosdata) {
|
|
||||||
let session:any = this.shared.getAccessToken() || "";
|
|
||||||
this.getconfig();
|
|
||||||
|
|
||||||
//let cognitodata = "539bfefa-ae42-4bee-bf79-4b15d1a2af7f";
|
|
||||||
let userGroup = session.idToken.payload["cognito:groups"].filter(
|
|
||||||
usergroup => usergroup == "ADMIN"
|
|
||||||
)[0];
|
|
||||||
//cognitosdata = 7;
|
|
||||||
let params:any;
|
|
||||||
if (userGroup == 'ADMIN') {
|
|
||||||
if(user.type.entity_type_id ==1){
|
|
||||||
params = {
|
|
||||||
UserAttributes: [ /* required */
|
|
||||||
{
|
|
||||||
Name: 'locale', /* required */
|
|
||||||
Value: cognitosdata.toString()
|
|
||||||
},{
|
|
||||||
Name:"email_verified",
|
|
||||||
Value:"true"
|
|
||||||
},{
|
|
||||||
Name:"phone_number_verified",
|
|
||||||
Value:"true"
|
|
||||||
}
|
|
||||||
/* more items */
|
|
||||||
],
|
|
||||||
UserPoolId: sineedgedev_poolData.UserPoolId, /* required */
|
|
||||||
Username: user.email /* required */
|
|
||||||
};
|
|
||||||
}else if(user.type.entity_type_id ==2){
|
|
||||||
params = {
|
|
||||||
UserAttributes: [ /* required */
|
|
||||||
{
|
|
||||||
Name: 'locale', /* required */
|
|
||||||
Value: cognitosdata.toString()
|
|
||||||
},{
|
|
||||||
Name:"email_verified",
|
|
||||||
Value:"true"
|
|
||||||
},{
|
|
||||||
Name:"phone_number_verified",
|
|
||||||
Value:"true"
|
|
||||||
}
|
|
||||||
/* more items */
|
|
||||||
],
|
|
||||||
UserPoolId: lender_poolData.UserPoolId, /* required */
|
|
||||||
Username: user.email /* required */
|
|
||||||
};
|
|
||||||
}else if(user.type.entity_type_id ==3){
|
|
||||||
params = {
|
|
||||||
UserAttributes: [ /* required */
|
|
||||||
{
|
|
||||||
Name: 'locale', /* required */
|
|
||||||
Value: cognitosdata.toString()
|
|
||||||
},{
|
|
||||||
Name:"email_verified",
|
|
||||||
Value:"true"
|
|
||||||
},{
|
|
||||||
Name:"phone_number_verified",
|
|
||||||
Value:"true"
|
|
||||||
}
|
|
||||||
/* more items */
|
|
||||||
],
|
|
||||||
UserPoolId: vendor_poolData.UserPoolId, /* required */
|
|
||||||
Username: user.email /* required */
|
|
||||||
};
|
|
||||||
}
|
|
||||||
//console.log(params);
|
|
||||||
return Observable.create(observe => {
|
|
||||||
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
|
|
||||||
|
|
||||||
cognitoidentityserviceprovider.adminUpdateUserAttributes(params, function (err, data) {
|
|
||||||
if (err) //(err, err.stack);
|
|
||||||
//console.log(data); // an error occurred
|
|
||||||
observe.next(data); // successful response
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
getlocale(){
|
|
||||||
let session:any = this.shared.getAccessToken() || "";
|
|
||||||
return session.idToken.payload.locale;
|
|
||||||
}
|
|
||||||
|
|
||||||
adminchangeData(userData,changeusers){
|
|
||||||
let session:any = this.shared.getAccessToken() || "";
|
|
||||||
this.getconfig();
|
|
||||||
let registeredData: any = "";
|
|
||||||
let params:any='';
|
|
||||||
let userGroup = session.idToken.payload["cognito:groups"].filter(
|
|
||||||
usergroup => usergroup == "ADMIN"
|
|
||||||
)[0];
|
|
||||||
// (userGroup);
|
|
||||||
if (userGroup == "ADMIN") {
|
|
||||||
if (userData.fk_entity_type_id == 1) {
|
|
||||||
params = {
|
|
||||||
UserPoolId: sineedgedev_poolData.UserPoolId /* required */,
|
|
||||||
Username: userData.aws_name,//userData.email /* required */,
|
|
||||||
|
|
||||||
// ForceAliasCreation: true || false,
|
|
||||||
|
|
||||||
UserAttributes: [
|
|
||||||
{
|
|
||||||
Name: "email" /* required */,
|
|
||||||
Value: changeusers.email,//userData.email
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "phone_number" /* required */,
|
|
||||||
Value: "+91"+ changeusers.phone
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "custom:role_id" /* required */,
|
|
||||||
Value: userData.user_role
|
|
||||||
},{
|
|
||||||
Name:"email_verified",
|
|
||||||
Value:"true"
|
|
||||||
},{
|
|
||||||
Name:"phone_number_verified",
|
|
||||||
Value:"true"
|
|
||||||
}
|
|
||||||
/* more items */
|
|
||||||
]
|
|
||||||
};
|
|
||||||
} else if (userData.fk_entity_type_id == 2) {
|
|
||||||
params = {
|
|
||||||
UserPoolId: lender_poolData.UserPoolId /* required */,
|
|
||||||
Username: userData.aws_name /* required */,
|
|
||||||
|
|
||||||
UserAttributes: [
|
|
||||||
{
|
|
||||||
Name: "email" /* required */,
|
|
||||||
Value: changeusers.email
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "phone_number" /* required */,
|
|
||||||
Value: "+91" + changeusers.phone
|
|
||||||
},{
|
|
||||||
Name: "custom:role_id" /* required */,
|
|
||||||
Value: userData.user_role
|
|
||||||
},{
|
|
||||||
Name:"email_verified",
|
|
||||||
Value:"true"
|
|
||||||
},{
|
|
||||||
Name:"phone_number_verified",
|
|
||||||
Value:"true"
|
|
||||||
}
|
|
||||||
/* more items */
|
|
||||||
]
|
|
||||||
};
|
|
||||||
}else if(userData.fk_entity_type_id == 3)
|
|
||||||
{
|
|
||||||
params = {
|
|
||||||
UserPoolId: vendor_poolData.UserPoolId /* required */,
|
|
||||||
Username: userData.aws_name /* required */,
|
|
||||||
|
|
||||||
UserAttributes: [
|
|
||||||
{
|
|
||||||
Name: "email" /* required */,
|
|
||||||
Value: changeusers.email
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "phone_number" /* required */,
|
|
||||||
Value: "+91" + changeusers.phone
|
|
||||||
},{
|
|
||||||
Name: "custom:role_id" /* required */,
|
|
||||||
Value: userData.user_role
|
|
||||||
},{
|
|
||||||
Name:"email_verified",
|
|
||||||
Value:"true"
|
|
||||||
},{
|
|
||||||
Name:"phone_number_verified",
|
|
||||||
Value:"true"
|
|
||||||
}
|
|
||||||
/* more items */
|
|
||||||
]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return Observable.create(observe=>{
|
|
||||||
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
|
|
||||||
cognitoidentityserviceprovider.adminUpdateUserAttributes(params, function(err, data) {
|
|
||||||
if (err) console.log(err, err.stack); // an error occurred
|
|
||||||
observe.next(data); // successful response
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// adminremoveGroup(roles,users){
|
|
||||||
// console.log(roles);
|
|
||||||
// console.log(users);
|
|
||||||
// if(users !==undefined){
|
|
||||||
|
|
||||||
// let session:any = this.shared.getAccessToken() ||"";
|
|
||||||
// this.getconfig();
|
|
||||||
// let params:any;
|
|
||||||
// if(users.fk_entity_type_id ==1){
|
|
||||||
// params = {
|
|
||||||
// GroupName: roles.GroupName, /* required */
|
|
||||||
// UserPoolId: sineedgedev_poolData.UserPoolId, /* required */
|
|
||||||
// Username: users.aws_name//'2c64866e-e96f-453b-903f-2b6f831688af' /* required */
|
|
||||||
// };
|
|
||||||
// }else if(users.fk_entity_id ==2){
|
|
||||||
// params = {
|
|
||||||
// GroupName: roles.GroupName, /* required */
|
|
||||||
// UserPoolId: lender_poolData.UserPoolId, /* required */
|
|
||||||
// Username: users.aws_name//'2c64866e-e96f-453b-903f-2b6f831688af' /* required */
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
// let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
|
|
||||||
// cognitoidentityserviceprovider.adminRemoveUserFromGroup(params, function(err, data) {
|
|
||||||
// if (err) console.log(err, err.stack); // an error occurred
|
|
||||||
// else console.log(data); // successful response
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
adminresetpassword(awsuser){
|
|
||||||
this.getconfig();
|
|
||||||
let params:any;
|
|
||||||
if(awsuser.fk_entity_id ==1){
|
|
||||||
params= {
|
|
||||||
UserPoolId: sineedgedev_poolData.UserPoolId, /* required */
|
|
||||||
Username: awsuser.email /* required */
|
|
||||||
};
|
|
||||||
}else if(awsuser.fk_entity_id ==2){
|
|
||||||
params= {
|
|
||||||
UserPoolId: lender_poolData.UserPoolId, /* required */
|
|
||||||
Username: awsuser.email /* required */
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return Observable.create(observe=>{
|
|
||||||
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
|
|
||||||
cognitoidentityserviceprovider.changePassword(params, function(err, data) {
|
|
||||||
if (err) console.log(err, err.stack); // an error occurred
|
|
||||||
else {
|
|
||||||
observe.next(data);
|
|
||||||
} // successful response
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
changepassword(passData) {
|
|
||||||
let session:any = this.shared.getAccessToken() || "";
|
|
||||||
this.getconfig();
|
|
||||||
var params = {
|
|
||||||
AccessToken: session.accessToken.jwtToken, /* required */
|
|
||||||
PreviousPassword: passData.oldPassword, /* required */
|
|
||||||
ProposedPassword: passData.newPassword /* required */
|
|
||||||
};
|
|
||||||
return Observable.create(observe => {
|
|
||||||
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
|
|
||||||
cognitoidentityserviceprovider.changePassword(params, function (err, data) {
|
|
||||||
if (err) console.log(err, err.stack); // an error occurred
|
|
||||||
observe.next(data);
|
|
||||||
// successful response
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
admindelete(aws){
|
|
||||||
this.getconfig();
|
|
||||||
let params:any;
|
|
||||||
if(aws.fk_entity_id ==1){
|
|
||||||
params= {
|
|
||||||
UserPoolId: sineedgedev_poolData.UserPoolId, /* required */
|
|
||||||
Username: aws.email /* required */
|
|
||||||
};
|
|
||||||
}else if(aws.fk_entity_id ==2){
|
|
||||||
params= {
|
|
||||||
UserPoolId: lender_poolData.UserPoolId, /* required */
|
|
||||||
Username: aws.email /* required */
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return Observable.create(observe=>{
|
|
||||||
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
|
|
||||||
cognitoidentityserviceprovider.adminDeleteUser(params, function(err, data) {
|
|
||||||
if (err) console.log(err, err.stack); // an error occurred
|
|
||||||
else {
|
|
||||||
observe.next(data);
|
|
||||||
} // successful response
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
adminlistgroup(enitiy){
|
|
||||||
// console.log(enitiy);
|
|
||||||
this.getconfig();
|
|
||||||
let params:any;
|
|
||||||
if(enitiy ==1){
|
|
||||||
params = {
|
|
||||||
UserPoolId:sineedgedev_poolData.UserPoolId,
|
|
||||||
}
|
|
||||||
}else if(enitiy ==2){
|
|
||||||
params = {
|
|
||||||
UserPoolId:lender_poolData.UserPoolId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//console.log(enitiy);
|
|
||||||
return Observable.create(observe=>{
|
|
||||||
|
|
||||||
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
|
|
||||||
cognitoidentityserviceprovider.listGroups(params,function(err,data){
|
|
||||||
if(err) alert(err.stack);
|
|
||||||
else {observe.next(data.Groups);}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,204 +0,0 @@
|
|||||||
import { Injectable } from '@angular/core';
|
|
||||||
import * as AWS from "aws-sdk";
|
|
||||||
import { CanActivateChild, Router } from '@angular/router';
|
|
||||||
import {
|
|
||||||
AuthenticationDetails,
|
|
||||||
CognitoUserPool,
|
|
||||||
CognitoUser,
|
|
||||||
CognitoUserAttribute,
|
|
||||||
ICognitoUserAttributeData,
|
|
||||||
ISignUpResult,
|
|
||||||
CognitoUserSession
|
|
||||||
} from "amazon-cognito-identity-js";
|
|
||||||
import { environment } from '../../environments/environment';
|
|
||||||
|
|
||||||
import { BehaviorSubject,Observable,of } from 'rxjs';
|
|
||||||
const sineedge_poolData = {
|
|
||||||
UserPoolId: "ap-south-1_y7dt3iEaX", //ap-south-1_qQ85yQZJO UserName :SPARQ_SINEEDGE_DEV
|
|
||||||
ClientId: "291qt4smn5pql6o8cc2hi201lj" // ClientName: SINEEDGE_DEV_WEB
|
|
||||||
};
|
|
||||||
const sineedgedev_poolData = {
|
|
||||||
UserPoolId: "ap-south-1_qQ85yQZJO", // UserName :SPARQ_SINEEDGE_DEV
|
|
||||||
ClientId: "67b4fnbuols5upms5to8bvqddh" // ClientName: SINEEDGE_DEV_WEB
|
|
||||||
}
|
|
||||||
const lender_poolData = {
|
|
||||||
UserPoolId: "ap-south-1_hFiGyr1Gw", // Username :SPARQ_LENDER_DEV
|
|
||||||
ClientId: "6egsdssf0i7h2o9mscqgqbn788" // ClientName:LENDER_DEV_WEB
|
|
||||||
};
|
|
||||||
const vendor_poolData = {
|
|
||||||
UserPoolId: "",
|
|
||||||
ClientId: ""
|
|
||||||
}
|
|
||||||
const sineedgeUserPool = new CognitoUserPool(sineedge_poolData);
|
|
||||||
const lenderUserPool = new CognitoUserPool(lender_poolData);
|
|
||||||
const sineedgedevUserpool = new CognitoUserPool(sineedgedev_poolData);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Identity PoolID
|
|
||||||
*/
|
|
||||||
const sineedgeIdentity = "ap-south-1:9a551eab-97cf-4991-b677-2f9bcd058961";//"ap-south-1:9a551eab-97cf-4991-b677-2f9bcd058961";
|
|
||||||
const lenderIdentity = "ap-south-1:ca22dabc-db59-4af5-9bb8-265f7ec95907";
|
|
||||||
const vendorIdenttiy = "";
|
|
||||||
// serviceProvider
|
|
||||||
//const apiurl = "http://ssa.sineedge.com/sparqapi/api/";
|
|
||||||
const apiurl = environment.apiEndpoint;
|
|
||||||
// const apiurl = "http://localhost/sparqapi/api/";
|
|
||||||
|
|
||||||
export interface Callback {
|
|
||||||
callback(): void;
|
|
||||||
|
|
||||||
callbackWithParam(result: any): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root'
|
|
||||||
})
|
|
||||||
export class CognitoService implements CanActivateChild {
|
|
||||||
public loggedIn :boolean = false;
|
|
||||||
// public static _REGION = environment.region;
|
|
||||||
|
|
||||||
// public static _IDENTITY_POOL_ID = environment.identityPoolId;
|
|
||||||
// public static _USER_POOL_ID = environment.UserPoolId;
|
|
||||||
// public static _CLIENT_ID = environment.ClientId;
|
|
||||||
|
|
||||||
// public static _POOL_DATA: any = {
|
|
||||||
// UserPoolId: CognitoService._USER_POOL_ID,
|
|
||||||
// ClientId: CognitoService._CLIENT_ID
|
|
||||||
// };
|
|
||||||
get isLoggedIn() {
|
|
||||||
if(sineedgedevUserpool.getCurrentUser() !=null){
|
|
||||||
this.loggedIn = true;
|
|
||||||
}else{
|
|
||||||
this.loggedIn = false;
|
|
||||||
}
|
|
||||||
return this.loggedIn; // {2}
|
|
||||||
}
|
|
||||||
canActivateChild(){
|
|
||||||
if(this.getToken()){
|
|
||||||
//alert('session valid')
|
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
this.route.navigate(['/authentication/login']);
|
|
||||||
//alert('session valid timeout');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public cognitoCreds: AWS.CognitoIdentityCredentials;
|
|
||||||
isloggin:boolean = false;
|
|
||||||
|
|
||||||
|
|
||||||
// getUserPool() {
|
|
||||||
// if (environment.cognito_idp_endpoint) {
|
|
||||||
// CognitoService.sineedgedev_poolData.endpoint = environment.cognito_idp_endpoint;
|
|
||||||
// }
|
|
||||||
// return new CognitoUserPool(CognitoService.sineedgedev_poolData);
|
|
||||||
// }
|
|
||||||
|
|
||||||
getCurrentUser() {
|
|
||||||
|
|
||||||
return sineedgedevUserpool.getCurrentUser();
|
|
||||||
}
|
|
||||||
constructor(public route:Router) { }
|
|
||||||
|
|
||||||
// getAccessToken(callback: Callback): void {
|
|
||||||
// if (callback == null) {
|
|
||||||
// throw("CognitoUtil: callback in getAccessToken is null...returning");
|
|
||||||
// }
|
|
||||||
// if (this.getCurrentUser() != null) {
|
|
||||||
// this.getCurrentUser().getSession(function (err, session) {
|
|
||||||
// if (err) {
|
|
||||||
// console.log("CognitoUtil: Can't set the credentials:" + err);
|
|
||||||
// callback.callbackWithParam(null);
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// if (session.isValid()) {
|
|
||||||
// console.log("62");
|
|
||||||
// callback.callbackWithParam(session.getAccessToken().getJwtToken());
|
|
||||||
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// callback.callbackWithParam(null);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
refresh() {
|
|
||||||
let tokenexp:boolean;
|
|
||||||
this.getCurrentUser().getSession(function (err, session) {
|
|
||||||
if (err) {
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
if (session.isValid()) {
|
|
||||||
tokenexp = session.isValid();
|
|
||||||
of(tokenexp)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
tokenexp = session.isValid();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return tokenexp;
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
getAccessToken(){
|
|
||||||
this.refresh();
|
|
||||||
let jwttoken = '';
|
|
||||||
if (this.getCurrentUser() != null) {
|
|
||||||
//console.log(JSON.stringify(this.getCurrentUser()));
|
|
||||||
// console.log('76 if');
|
|
||||||
this.getCurrentUser().getSession(function (err, session) {
|
|
||||||
if (err) {
|
|
||||||
jwttoken ='';
|
|
||||||
// console.log('81 if')
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (session.isValid()) {
|
|
||||||
// console.log('85 else if');
|
|
||||||
jwttoken = session;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//console.log("else");
|
|
||||||
|
|
||||||
}
|
|
||||||
return jwttoken;
|
|
||||||
}
|
|
||||||
|
|
||||||
getToken():boolean {
|
|
||||||
let isloggin = false;
|
|
||||||
if (this.getCurrentUser() != null) {
|
|
||||||
//console.log(JSON.stringify(this.getCurrentUser()));
|
|
||||||
//console.log('76 if');
|
|
||||||
this.getCurrentUser().getSession(function (err, session) {
|
|
||||||
if (err) {
|
|
||||||
// console.log("CognitoUtil: Can't set the credentials:" + err);
|
|
||||||
isloggin = false;
|
|
||||||
//console.log('81 if')
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (session.isValid()) {
|
|
||||||
// console.log('85 else if');
|
|
||||||
isloggin = true;
|
|
||||||
} else {
|
|
||||||
isloggin = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// console.log("else");
|
|
||||||
isloggin = false;
|
|
||||||
}
|
|
||||||
return isloggin;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,48 +0,0 @@
|
|||||||
import { Injectable } from '@angular/core';
|
|
||||||
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild } from '@angular/router';
|
|
||||||
import { Observable , of } from 'rxjs';
|
|
||||||
import { CognitoService } from '../AwsService/cognito.service';
|
|
||||||
@Injectable()
|
|
||||||
export class AuthGuard implements CanActivate, CanActivateChild {
|
|
||||||
|
|
||||||
constructor(private router: Router,public shared:CognitoService) { }
|
|
||||||
|
|
||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
|
||||||
if (this.shared.getToken()) {
|
|
||||||
alert("if");
|
|
||||||
// this.router.navigate(['']);
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
alert("else");
|
|
||||||
this.router.navigate(['/login']);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
|
|
||||||
|
|
||||||
if (this.shared.getToken()) {
|
|
||||||
// alert("if");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
// alert("else");
|
|
||||||
setTimeout(() => {
|
|
||||||
this.router.navigate(['authentication/login']);
|
|
||||||
return false;
|
|
||||||
},1000);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// public getToken(): string {
|
|
||||||
// return localStorage.getItem('token');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public logOut() {
|
|
||||||
// localStorage.clear();
|
|
||||||
// if(localStorage.getItem('token') === null){
|
|
||||||
// this.router.navigate(['/login']);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
@ -1,91 +0,0 @@
|
|||||||
import { Injectable } from '@angular/core';
|
|
||||||
import {
|
|
||||||
HttpRequest,
|
|
||||||
HttpHandler,
|
|
||||||
HttpEvent,
|
|
||||||
HttpInterceptor,
|
|
||||||
HttpHeaders
|
|
||||||
} from '@angular/common/http';
|
|
||||||
// import { AuthGuard } from './auth.guard';
|
|
||||||
import { Observable, of, throwError } from 'rxjs';
|
|
||||||
import { Router } from '@angular/router';
|
|
||||||
import { retry,catchError, map, tap } from 'rxjs/operators';
|
|
||||||
import { HttpErrorResponse } from "@angular/common/http";
|
|
||||||
import { CognitoService } from '../AwsService/cognito.service';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class TokenInterceptor implements HttpInterceptor{
|
|
||||||
constructor( private router: Router,public shared:CognitoService) {}
|
|
||||||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
|
||||||
// request = request.clone({
|
|
||||||
// setHeaders: {
|
|
||||||
// Authorization: `${this.auth.getToken()}`
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
let token:any = this.shared.getAccessToken() ||"";
|
|
||||||
//console.log(token);
|
|
||||||
let requests = request.clone({
|
|
||||||
headers:new HttpHeaders({
|
|
||||||
'Authorization': 'sparqvenba2018',
|
|
||||||
'Token': token.getIdToken().getJwtToken()
|
|
||||||
})
|
|
||||||
});
|
|
||||||
return next.handle(requests).pipe(
|
|
||||||
catchError(this.handleError<any>('role', []))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// private handleError<T> (operation = 'operation', result?: T) {
|
|
||||||
// console.log(result);
|
|
||||||
// return (error: any): Observable<T> => {
|
|
||||||
// if(error instanceof HttpErrorResponse){
|
|
||||||
// console.error("Error: " + error.status);
|
|
||||||
// if(error.status == 401){
|
|
||||||
// localStorage.clear();
|
|
||||||
// this.router.navigate(['/authentication/login']);
|
|
||||||
// }
|
|
||||||
// return of(result as T);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
private handleError<T> (operation = 'operation', result?: T) {
|
|
||||||
return (error: any): Observable<T> => {
|
|
||||||
if(error instanceof HttpErrorResponse){
|
|
||||||
console.error("Error: " + error.status);
|
|
||||||
if(error.status == 401){
|
|
||||||
localStorage.clear();
|
|
||||||
this.router.navigate(['/authentication/login']);
|
|
||||||
}
|
|
||||||
else if(error.status == 404){
|
|
||||||
this.router.navigate(['/error/404']);
|
|
||||||
}
|
|
||||||
else if(error.status == 503){
|
|
||||||
this.router.navigate(['/error/503']);
|
|
||||||
}
|
|
||||||
else if(error.status == 0){
|
|
||||||
this.router.navigate(['/error/404']);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
let errorMessage = '';
|
|
||||||
let type : number;
|
|
||||||
if (error.error instanceof ErrorEvent) {
|
|
||||||
// client-side error
|
|
||||||
errorMessage = `Error: ${error.error.message}`;
|
|
||||||
type = 1;
|
|
||||||
} else {
|
|
||||||
// server-side error
|
|
||||||
errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`;
|
|
||||||
type = 2;
|
|
||||||
}
|
|
||||||
return throwError({error_status :type == 2 ? error.status : '',
|
|
||||||
error_message:error.message,
|
|
||||||
error_text :type == 2 ? error.statusText : '',
|
|
||||||
html_format :errorMessage,
|
|
||||||
error_type :type,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user