sparqclientapp user mangement aws

This commit is contained in:
venbaSriram 2018-09-20 12:48:57 +05:30
parent f9410a50ea
commit d52bcb1990
18 changed files with 958 additions and 722 deletions

View File

@ -6986,6 +6986,14 @@
"resolved": "https://registry.npmjs.org/ngx-color-picker/-/ngx-color-picker-4.5.3.tgz", "resolved": "https://registry.npmjs.org/ngx-color-picker/-/ngx-color-picker-4.5.3.tgz",
"integrity": "sha512-CJca1od05yf2j8OKUm5ar+mIVFB3n01+vbMpLeT+9/drKYCxgmtxxmmsgwWBNNXWYa2GNYB7PGH+mdKQkeypOg==" "integrity": "sha512-CJca1od05yf2j8OKUm5ar+mIVFB3n01+vbMpLeT+9/drKYCxgmtxxmmsgwWBNNXWYa2GNYB7PGH+mdKQkeypOg=="
}, },
"ngx-mat-select-search": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/ngx-mat-select-search/-/ngx-mat-select-search-1.3.1.tgz",
"integrity": "sha512-ZggcqsfcJZ1tcy6ZgNnifrvn/ahWJqRO2B7QXHt0FDUo4lrv/2cuHALzwuwlY/z8rZeH+ZEmaAevzQtYH8mKpA==",
"requires": {
"tslib": "^1.9.0"
}
},
"ngx-perfect-scrollbar": { "ngx-perfect-scrollbar": {
"version": "5.0.0-7", "version": "5.0.0-7",
"resolved": "https://registry.npmjs.org/ngx-perfect-scrollbar/-/ngx-perfect-scrollbar-5.0.0-7.tgz", "resolved": "https://registry.npmjs.org/ngx-perfect-scrollbar/-/ngx-perfect-scrollbar-5.0.0-7.tgz",

View File

@ -50,6 +50,7 @@
"ng2-translate": "5.0.0", "ng2-translate": "5.0.0",
"ng2-validation": "4.2.0", "ng2-validation": "4.2.0",
"ngx-color-picker": "^4.0.3", "ngx-color-picker": "^4.0.3",
"ngx-mat-select-search": "^1.3.1",
"ngx-perfect-scrollbar": "5.0.0-7", "ngx-perfect-scrollbar": "5.0.0-7",
"node-sass": "^4.9.3", "node-sass": "^4.9.3",
"perfect-scrollbar": "^1.3.0", "perfect-scrollbar": "^1.3.0",

View File

@ -10,10 +10,10 @@ import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar';
import { PERFECT_SCROLLBAR_CONFIG } from 'ngx-perfect-scrollbar'; import { PERFECT_SCROLLBAR_CONFIG } from 'ngx-perfect-scrollbar';
import { PerfectScrollbarConfigInterface } from 'ngx-perfect-scrollbar'; import { PerfectScrollbarConfigInterface } from 'ngx-perfect-scrollbar';
import { TokenInterceptor } from './_guard/token.interceptor'; import { TokenInterceptor } from './_guard/token.interceptor';
import { TranslateModule, TranslateLoader, TranslateStaticLoader } from 'ng2-translate/ng2-translate'; import { TranslateModule, TranslateLoader, TranslateStaticLoader } from 'ng2-translate/ng2-translate';
import { FlexLayoutModule } from '@angular/flex-layout'; import { FlexLayoutModule } from '@angular/flex-layout';
import { DemoMaterialModule } from './shared/demo.module'; import { DemoMaterialModule } from './shared/demo.module';
import {MatSidenavModule} from '@angular/material/sidenav'; import {MatSidenavModule} from '@angular/material/sidenav';
import {MatInputModule} from '@angular/material/input'; import {MatInputModule} from '@angular/material/input';

View File

@ -2,14 +2,15 @@ import { Routes } from '@angular/router';
import { AdminLayoutComponent } from './layouts/admin/admin-layout.component'; import { AdminLayoutComponent } from './layouts/admin/admin-layout.component';
import { AuthLayoutComponent } from './layouts/auth/auth-layout.component'; import { AuthLayoutComponent } from './layouts/auth/auth-layout.component';
import { SharedService } from './shared.service';
export const AppRoutes: Routes = [{ export const AppRoutes: Routes = [{
path: '', path: '',
redirectTo: 'authentication', redirectTo: 'home',
pathMatch: 'full', pathMatch: 'full',
}, { }, {
path: '', path: '',
component: AdminLayoutComponent, component: AdminLayoutComponent,
canActivateChild: [SharedService],
children: [{ children: [{
path: 'home', path: 'home',
loadChildren: './dashboard/dashboard.module#DashboardModule' loadChildren: './dashboard/dashboard.module#DashboardModule'

View File

@ -16,11 +16,11 @@ import { LoginComponent } from "./session/login/login.component";
import { Http, Headers, RequestOptions } from '@angular/http'; import { Http, Headers, RequestOptions } from '@angular/http';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
import { SharedService } from './shared.service'; import { SharedService } from './shared.service';
let apiurl = 'http://localhost/sparqapi/api/';
const sineedge_poolData = { const sineedge_poolData = {
UserPoolId: "ap-south-1_y7dt3iEaX", //ap-south-1_qQ85yQZJO UserName :SPARQ_SINEEDGE_DEV UserPoolId: "ap-south-1_y7dt3iEaX", //ap-south-1_qQ85yQZJO UserName :SPARQ_SINEEDGE_DEV
ClientId: "291qt4smn5pql6o8cc2hi201lj" // ClientName: SINEEDGE_DEV_WEB ClientId: "291qt4smn5pql6o8cc2hi201lj" // ClientName: SINEEDGE_DEV_WEB
@ -48,7 +48,7 @@ const sineedgeIdentity = "ap-south-1:9a551eab-97cf-4991-b677-2f9bcd058961";//"ap
const lenderIdentity = "ap-south-1:ca22dabc-db59-4af5-9bb8-265f7ec95907"; const lenderIdentity = "ap-south-1:ca22dabc-db59-4af5-9bb8-265f7ec95907";
const vendorIdenttiy = ""; const vendorIdenttiy = "";
// serviceProvider // serviceProvider
// apiurl = "http://localhost/sineedge/sparqapi/api/"; const apiurl = "http://localhost/sineedge/sparqapi/api/";
const currentdate = new Date().toJSON().slice(0,19).replace('T',' '); const currentdate = new Date().toJSON().slice(0,19).replace('T',' ');
@Injectable({ @Injectable({
@ -126,7 +126,7 @@ export class AwsService {
// gets the current user from the local storage // gets the current user from the local storage
this.cognitoUser = sineedgedevUserpool.getCurrentUser(); this.cognitoUser = sineedgedevUserpool.getCurrentUser();
//let sessions = ''; //let sessions = '';
let jwttoken = ""; let jwttoken = "";
let session = ""; let session = "";
if (this.cognitoUser != null) { if (this.cognitoUser != null) {
@ -203,8 +203,23 @@ export class AwsService {
*/ */
logOut() { logOut() {
window.localStorage.removeItem("Currentuser"); window.localStorage.removeItem("Currentuser");
this.getUser().signOut(); let session = this.getAuthenticatedUser() || "";
this.cognitoUser = null; //console.log(session.getAccessToken().getJwtToken());
let params:any = {
AccessToken:session.getAccessToken().getJwtToken()
//UserPoolId:sineedge_poolData.UserPoolId
}
return Observable.create(observe=>{
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
cognitoidentityserviceprovider.globalSignOut(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else
AwsService.prototype.getUser().signOut();
AwsService.prototype.cognitoUser = null;
observe.next(data); // successful response
});
});
} }
/** /**
* User Change Password * User Change Password
@ -271,6 +286,7 @@ export class AwsService {
] ]
}; };
} else if (userData.type.entity_type_id == 2) { } else if (userData.type.entity_type_id == 2) {
console.log(2);
params = { params = {
UserPoolId: lender_poolData.UserPoolId /* required */, UserPoolId: lender_poolData.UserPoolId /* required */,
Username: userData.email /* required */, Username: userData.email /* required */,
@ -294,7 +310,7 @@ export class AwsService {
] ]
}; };
} }
// .log(params); console.log(params);
return Observable.create(observe => { return Observable.create(observe => {
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider(); let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
@ -306,30 +322,32 @@ export class AwsService {
// an error occurred // an error occurred
this.mySecData = data;
AwsService.prototype.UserGroup(data, userData); AwsService.prototype.UserGroup(data, userData);
observe.next(data); observe.next(data);
// successful response // successful response
}); });
}); });
}else{
return alert('Admin Only create user');
} }
} }
UserGroup(cognitodata, userData) { UserGroup(cognitodata, userData) {
//(userData); //(userData);
console.log(cognitodata);
let session = this.getAuthenticatedUser() || ""; let session = this.getAuthenticatedUser() || "";
this.getconfig(); this.getconfig();
//let cognitodata = "539bfefa-ae42-4bee-bf79-4b15d1a2af7f"; //let cognitodata = "539bfefa-ae42-4bee-bf79-4b15d1a2af7f";
if(userData.userid ==''){ if(userData.userid === null ){
for(let role of userData.role){ for(let role of userData.role){
let params: any; let params: any;
if (userData.type.entity_type_id == 1) { if (userData.type.entity_type_id == 1) {
params = { params = {
GroupName: role.value /* required */, GroupName: role.value /* required */,
UserPoolId: sineedgedev_poolData.UserPoolId,//"ap-south-1_y7dt3iEaX" /* required */, UserPoolId: sineedgedev_poolData.UserPoolId,//"ap-south-1_y7dt3iEaX" /* required */,
@ -433,43 +451,59 @@ export class AwsService {
createdby = this.getlocale(); createdby = this.getlocale();
createdon = currentdate; createdon = currentdate;
} }
let profilepic:any;
if(users.userpic !=null && users.userpic !='' && users.userpic !==undefined){
profilepic= users.userpic.name;
}
console.log(profilepic);
let formData = new FormData(); let formData = new FormData();
console.log(users); console.log(users);
let records:any = {
"userid":users.userid,
"aws_name": aws_name,
"first_name": users.firstName,
"last_name": users.lastName,
"mobile_no": users.phone,
"email": users.email,
"alt_email":users.alt_email,
"alt_mobile_no":users.alt_mobile_no,
"addressline1":users.address1,
"addressline2":users.address2,
"addressline3":users.address3,
"isactive":users.isactive,
"fk_entity_id":users.type.entity_type_id,
"fk_designation":users.designation.designation_id,
"fk_city":users.city.city_id,
"fk_state":users.state.state_id,
"pincode":users.pincode,
"profilepic":users.userpic.name,
"fk_createdby":createdby,
"fk_updatedby":updateby,
"createdon":createdon,
"updatedon":updateon,
};
let roles:any=[]; let roles:any=[];
for(var role of users.role){ for(var role of users.role){
roles.push({ "user_role": role.value }); roles.push({ "user_role": role.value });
} }
console.log(roles); let designation:any;
if(users.type.entity_type_id ==2){
let lenderhie:any =[];
lenderhie.push(users.lenderHierarchy);
formData.append('lender_hierarchy',JSON.stringify(lenderhie));
designation = '';
}else if(users.type.entity_type_id ==1){
designation =users.designation.designation_id;
}
let records:any = {
"userid":users.userid,
"aws_name": aws_name,
"first_name": users.firstName,
"last_name": users.lastName,
"mobile_no": users.phone,
"email": users.email,
"alt_email":users.alt_email,
"alt_mobile_no":users.alt_mobile_no,
"addressline1":users.address1,
"addressline2":users.address2,
"addressline3":users.address3,
"isactive":users.isactive,
"fk_entity_id":users.type.entity_type_id,
"fk_designation":designation,
"fk_city":users.city.city_id,
"fk_state":users.state.state_id,
"pincode":users.pincode,
"profilepic":profilepic,
"fk_createdby":createdby,
"fk_updatedby":updateby,
"createdon":createdon,
"updatedon":updateon,
};
//console.log(roles);
formData.append('records',JSON.stringify(records)); formData.append('records',JSON.stringify(records));
formData.append('roles',JSON.stringify(roles)); formData.append('roles',JSON.stringify(roles));
formData.append('profilepic',users.userpic); formData.append('profilepic',users.userpic);
//new Response(formData).text().then(console.log); //new Response(formData).text().then(console.log);
//let headers = this.shared.headercofig(''); //let headers = this.shared.headercofig('');
let session:any = this.getAuthenticatedUser() ||""; let session:any = this.getAuthenticatedUser() ||"";
@ -481,7 +515,9 @@ export class AwsService {
//(request); //(request);
if(users.userid !='' && users.userid !=null && users.userid !==undefined){ if(users.userid !='' && users.userid !=null && users.userid !==undefined){
delete this.localUserId;
return this.http.post(apiurl+'updateExistUser',formData,{headers:headers}).map(res=>res.json()); return this.http.post(apiurl+'updateExistUser',formData,{headers:headers}).map(res=>res.json());
}else{ }else{
return this.http.post(apiurl + "saveNewUser", formData, { headers: headers }).map(res => res.json()); return this.http.post(apiurl + "saveNewUser", formData, { headers: headers }).map(res => res.json());
} }
@ -503,9 +539,10 @@ export class AwsService {
usergroup => usergroup == "ADMIN" usergroup => usergroup == "ADMIN"
)[0]; )[0];
//cognitosdata = 7; //cognitosdata = 7;
let params:any;
if (userGroup == 'ADMIN') { if (userGroup == 'ADMIN') {
var params = { if(user.type.entity_type_id ==1){
params = {
UserAttributes: [ /* required */ UserAttributes: [ /* required */
{ {
Name: 'locale', /* required */ Name: 'locale', /* required */
@ -516,6 +553,19 @@ export class AwsService {
UserPoolId: sineedgedev_poolData.UserPoolId, /* required */ UserPoolId: sineedgedev_poolData.UserPoolId, /* required */
Username: user.email /* required */ Username: user.email /* required */
}; };
}else if(user.type.entity_type_id ==2){
params = {
UserAttributes: [ /* required */
{
Name: 'locale', /* required */
Value: cognitosdata.toString()
},
/* more items */
],
UserPoolId: lender_poolData.UserPoolId, /* required */
Username: user.email /* required */
};
}
//console.log(params); //console.log(params);
return Observable.create(observe => { return Observable.create(observe => {
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider(); let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
@ -606,11 +656,18 @@ export class AwsService {
* @param records * @param records
*/ */
adminupendis(records){ adminupendis(records){
let headers = this.shared.headercofig(''); //let headers = this.shared.headercofig('');
console.log(headers); // console.log(headers);
let users = this.http.post(apiurl + 'updateExistUser',JSON.stringify(records), { headers: headers }).map(res => res.json()); let session = this.getAuthenticatedUser() || "";
console.log(users); let formData = new FormData();
return users; formData.append('records',JSON.stringify(records));
let headers = new Headers(
{
'Authorization':'sparqvenba2018','Token':session.getIdToken().getJwtToken()
});
return this.http.post(apiurl+'updateExistUser',formData,{headers:headers}).map(res=>res.json());
//console.log(users);
} }
/** /**
* Admin Create User End * Admin Create User End
@ -645,7 +702,7 @@ export class AwsService {
if (userData.fk_entity_id == 1) { if (userData.fk_entity_id == 1) {
params = { params = {
UserPoolId: sineedgedev_poolData.UserPoolId /* required */, UserPoolId: sineedgedev_poolData.UserPoolId /* required */,
Username: userData.email,//userData.email /* required */, Username: userData.aws_name,//userData.email /* required */,
// ForceAliasCreation: true || false, // ForceAliasCreation: true || false,
@ -664,7 +721,7 @@ export class AwsService {
} else if (userData.fk_entity_id == 2) { } else if (userData.fk_entity_id == 2) {
params = { params = {
UserPoolId: lender_poolData.UserPoolId /* required */, UserPoolId: lender_poolData.UserPoolId /* required */,
Username: changeusers.email /* required */, Username: userData.aws_name /* required */,
UserAttributes: [ UserAttributes: [
{ {
@ -679,6 +736,7 @@ export class AwsService {
] ]
}; };
} }
console.log(params);
return Observable.create(observe=>{ return Observable.create(observe=>{
let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider(); let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
cognitoidentityserviceprovider.adminUpdateUserAttributes(params, function(err, data) { cognitoidentityserviceprovider.adminUpdateUserAttributes(params, function(err, data) {
@ -774,5 +832,10 @@ adminremoveGroup(roles,users){
let master_name = {'master_name':'DESIGNATION'}; let master_name = {'master_name':'DESIGNATION'};
return this.http.post(apiurl+'getListOfMaster',master_name,{headers:headers}).map(res=>res.json()); return this.http.post(apiurl+'getListOfMaster',master_name,{headers:headers}).map(res=>res.json());
} }
lenderHierarchy(){
let headers = this.shared.headercofig('');
let master_name = {'master_name':'LENDERHIERARCHY'};
return this.http.post(apiurl+'getListOfMaster',master_name,{headers:headers}).map(res=>res.json());
}
} }

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,7 @@ import PerfectScrollbar from 'perfect-scrollbar';
import { PerfectScrollbarConfigInterface, import { PerfectScrollbarConfigInterface,
PerfectScrollbarComponent, PerfectScrollbarDirective } from 'ngx-perfect-scrollbar'; PerfectScrollbarComponent, PerfectScrollbarDirective } from 'ngx-perfect-scrollbar';
import { SharedService } from '../../shared.service'; import { SharedService } from '../../shared.service';
import { AwsService } from '../../aws.service';
@Component({ @Component({
selector: 'app-layout', selector: 'app-layout',
templateUrl: './admin-layout.component.html' templateUrl: './admin-layout.component.html'
@ -42,7 +43,7 @@ export class AdminLayoutComponent implements OnInit, OnDestroy {
@ViewChild('sidemenu') sidemenu; @ViewChild('sidemenu') sidemenu;
public config: PerfectScrollbarConfigInterface = {}; public config: PerfectScrollbarConfigInterface = {};
constructor(private router: Router, public menuItems: MenuItems, public horizontalMenuItems : HorizontalMenuItems, public translate: TranslateService,public shared:SharedService ) { constructor(private router: Router, public menuItems: MenuItems, public horizontalMenuItems : HorizontalMenuItems, public translate: TranslateService,public shared:SharedService,public aws:AwsService ) {
const browserLang: string = translate.getBrowserLang(); const browserLang: string = translate.getBrowserLang();
translate.use(browserLang.match(/en|fr/) ? browserLang : 'en'); translate.use(browserLang.match(/en|fr/) ? browserLang : 'en');
} }
@ -221,4 +222,14 @@ export class AdminLayoutComponent implements OnInit, OnDestroy {
] ]
}); });
} }
logout(){
this.aws.logOut().subscribe(res=>{
this.router.navigate(['/authentication/login']);
});
}
userProfile(){
this.router.navigate(['/user-pages/userprofile']);
}
} }

View File

@ -1,24 +1,27 @@
<mat-card> <mat-card>
<mat-card-title>User Registration</mat-card-title>
<mat-card-title> <button mat-raised-button mat-icon-button class="mr-1 mb-1 hover-icon button" (click)="back()"><mat-icon>chevron_left</mat-icon></button> User Registration</mat-card-title>
<!-- <mat-card-subtitle>Angular2 custom validation</mat-card-subtitle> --> <!-- <mat-card-subtitle>Angular2 custom validation</mat-card-subtitle> -->
<form [formGroup]="regForm" (ngSubmit)="register(regForm.value)"> <form [formGroup]="regForm" (ngSubmit)="register(regForm.value)">
<mat-card-content> <mat-card-content>
<div fxLayout="row" fxLayoutAlign="start center" class="mb-2"> <div fxLayout="row" fxLayoutAlign="start center" class="mb-2">
<mat-form-field dividerColor="primary" class="ml-xs mr-xs"> <mat-form-field dividerColor="primary" class="ml-xs mr-xs">
<input matInput placeholder="First name" [formControl]="regForm.controls['firstName']"> <input matInput placeholder="First name" [formControl]="regForm.controls['firstName']">
<mat-error *ngIf="regForm.controls['firstName'].hasError('required') && regForm.controls['firstName'].touched" class="mat-text-warn">You must include a first name.</mat-error>
<mat-error *ngIf="regForm.controls['firstName'].hasError('minlength') && regForm.controls['firstName'].touched" class="mat-text-warn">Your first name must be at least 5 characters long.</mat-error>
<mat-error *ngIf="regForm.controls['firstName'].hasError('maxlength') && regForm.controls['firstName'].touched" class="mat-text-warn">Your first name cannot exceed 10 characters.</mat-error>
</mat-form-field> </mat-form-field>
<small *ngIf="regForm.controls['firstName'].hasError('required') && regForm.controls['firstName'].touched" class="mat-text-warn">You must include a first name.</small>
<small *ngIf="regForm.controls['firstName'].hasError('minlength') && regForm.controls['firstName'].touched" class="mat-text-warn">Your first name must be at least 5 characters long.</small>
<small *ngIf="regForm.controls['firstName'].hasError('maxlength') && regForm.controls['firstName'].touched" class="mat-text-warn">Your first name cannot exceed 10 characters.</small>
<mat-form-field dividerColor="primary" class="ml-xs mr-xs"> <mat-form-field dividerColor="primary" class="ml-xs mr-xs">
<input matInput placeholder="Last name" [formControl]="regForm.controls['lastName']"> <input matInput placeholder="Last name" [formControl]="regForm.controls['lastName']">
<mat-error *ngIf="regForm.controls['lastName'].hasError('required') && regForm.controls['lastName'].touched" class="mat-text-warn">You must include a last name.</mat-error>
</mat-form-field> </mat-form-field>
<small *ngIf="regForm.controls['lastName'].hasError('required') && regForm.controls['lastName'].touched" class="mat-text-warn">You must include a last name.</small> <!-- <mat-error *ngIf="regForm.controls['lastName'].hasError('minlength') && regForm.controls['lastName'].touched" class="mat-text-warn">Your first name must be at least 5 characters long.</mat-error>
<!-- <small *ngIf="regForm.controls['lastName'].hasError('minlength') && regForm.controls['lastName'].touched" class="mat-text-warn">Your first name must be at least 5 characters long.</small> <mat-error *ngIf="regForm.controls['lastName'].hasError('maxlength') && regForm.controls['lastName'].touched" class="mat-text-warn">Your first name cannot exceed 10 characters.</mat-error> -->
<small *ngIf="regForm.controls['lastName'].hasError('maxlength') && regForm.controls['lastName'].touched" class="mat-text-warn">Your first name cannot exceed 10 characters.</small> -->
<mat-form-field style="display: none;"> <mat-form-field style="display: none;">
<input matInput placeholder="User Id" [formControl]="regForm.controls['userid']"> <input matInput placeholder="User Id" [formControl]="regForm.controls['userid']">
</mat-form-field> </mat-form-field>
@ -28,15 +31,15 @@
<div fxLayout="row" fxLayoutAlign="start center" class="mb-2"> <div fxLayout="row" fxLayoutAlign="start center" class="mb-2">
<mat-form-field dividerColor="primary" class="ml-xs mr-xs"> <mat-form-field dividerColor="primary" class="ml-xs mr-xs">
<input matInput placeholder="Email address" [formControl]="regForm.controls['email']" type="email"> <input matInput placeholder="Email address" [formControl]="regForm.controls['email']" type="email">
<mat-error *ngIf="regForm.controls['email'].hasError('required') && regForm.controls['email'].touched" class="mat-text-warn">You must include an email address.</mat-error>
<mat-error *ngIf="regForm.controls['email'].errors?.email && regForm.controls['email'].touched" class="mat-text-warn">You must include a valid email address.</mat-error>
</mat-form-field> </mat-form-field>
<small *ngIf="regForm.controls['email'].hasError('required') && regForm.controls['email'].touched" class="mat-text-warn">You must include an email address.</small>
<small *ngIf="regForm.controls['email'].errors?.email && regForm.controls['email'].touched" class="mat-text-warn">You must include a valid email address.</small>
<mat-form-field dividerColor="primary" class="ml-xs mr-xs"> <mat-form-field dividerColor="primary" class="ml-xs mr-xs">
<input matInput placeholder="Alt Email address" [formControl]="regForm.controls['altemail']" type="email"> <input matInput placeholder="Alt Email address" [formControl]="regForm.controls['altemail']" type="email">
</mat-form-field> </mat-form-field>
<small *ngIf="regForm.controls['email'].errors?.email && regForm.controls['altemail'].touched" class="mat-text-warn">You must include a valid email address.</small> <mat-error *ngIf="regForm.controls['email'].errors?.email && regForm.controls['altemail'].touched" class="mat-text-warn">You must include a valid email address.</mat-error>
</div> </div>
@ -46,15 +49,17 @@
<div fxLayout="row" fxLayoutAlign="start center" class="mb-2"> <div fxLayout="row" fxLayoutAlign="start center" class="mb-2">
<mat-form-field dividerColor="primary" class="ml-xs mr-xs"> <mat-form-field dividerColor="primary" class="ml-xs mr-xs">
<input matInput placeholder="Phone number" [formControl]="regForm.controls['phone']" type="text"> <input matInput placeholder="Phone number" [formControl]="regForm.controls['phone']" type="text">
<mat-error *ngIf="regForm.controls['phone'].hasError('required') && regForm.controls['phone'].touched" class="mat-text-warn">You must include phone number.</mat-error>
<mat-error *ngIf="regForm.controls['phone'].errors?.phone && regForm.controls['phone'].touched" class="mat-text-warn">You must include a valid phone number.</mat-error>
</mat-form-field> </mat-form-field>
<small *ngIf="regForm.controls['phone'].hasError('required') && regForm.controls['phone'].touched" class="mat-text-warn">You must include phone number.</small>
<small *ngIf="regForm.controls['phone'].errors?.phone && regForm.controls['phone'].touched" class="mat-text-warn">You must include a valid phone number.</small>
<mat-form-field dividerColor="primary" class="ml-xs mr-xs"> <mat-form-field dividerColor="primary" class="ml-xs mr-xs">
<input matInput placeholder="Alt Phone number" [formControl]="regForm.controls['altphone']" type="text"> <input matInput placeholder="Alt Phone number" [formControl]="regForm.controls['altphone']" type="text">
<mat-error *ngIf="regForm.controls['altphone'].errors?.phone && regForm.controls['phone'].touched" class="mat-text-warn">You must include a valid phone number.</mat-error>
</mat-form-field> </mat-form-field>
<!-- <small *ngIf="regForm.controls['phone'].hasError('required') && regForm.controls['phone'].touched" class="mat-text-warn">You must include phone number.</small> --> <!-- <mat-error *ngIf="regForm.controls['phone'].hasError('required') && regForm.controls['phone'].touched" class="mat-text-warn">You must include phone number.</mat-error> -->
<small *ngIf="regForm.controls['altphone'].errors?.phone && regForm.controls['phone'].touched" class="mat-text-warn">You must include a valid phone number.</small>
<mat-form-field dividerColor="primary" class="ml-xs mr-xs"> <mat-form-field dividerColor="primary" class="ml-xs mr-xs">
<input matInput placeholder="Address 1" [formControl]="regForm.controls['address1']"> <input matInput placeholder="Address 1" [formControl]="regForm.controls['address1']">
@ -85,21 +90,21 @@
</mat-option> </mat-option>
</mat-select> </mat-select>
<small *ngIf="regForm.controls['role'].hasError('required') && regForm.controls['role'].touched" class="mat-text-warn">Select User Role</small> <mat-error *ngIf="regForm.controls['role'].hasError('required') && regForm.controls['role'].touched" class="mat-text-warn">Select User Role</mat-error>
<small *ngIf="regForm.controls['role'].errors?.phone && regForm.controls['role'].touched" class="mat-text-warn">Select User Role</small> <mat-error *ngIf="regForm.controls['role'].errors?.phone && regForm.controls['role'].touched" class="mat-text-warn">Select User Role</mat-error>
</mat-form-field> </mat-form-field>
<!-- <pre>{{regForm.controls['role'].value | json}}</pre> --> <!-- <pre>{{regForm.controls['role'].value | json}}</pre> -->
<mat-form-field dividerColor="primary" class="ml-xs mr-xs" style="width: 100%;"> <mat-form-field dividerColor="primary" class="ml-xs mr-xs" style="width: 100%;">
<mat-select matInput placeholder="Select type" [formControl]="regForm.controls['type']" required> <mat-select matInput placeholder="Select type" (selectionChange)="checktype($event.value)"[formControl]="regForm.controls['type']" required>
<mat-option>--</mat-option> <mat-option>--</mat-option>
<mat-option *ngFor="let types of types" [value]="types" > <mat-option *ngFor="let types of types" [value]="types" >
{{types.name}} {{types.name}}
</mat-option> </mat-option>
</mat-select> </mat-select>
<small *ngIf="regForm.controls['type'].hasError('required') && regForm.controls['type'].touched" class="mat-text-warn">Select User Role</small> <mat-error *ngIf="regForm.controls['type'].hasError('required') && regForm.controls['type'].touched" class="mat-text-warn">Select User Role</mat-error>
<small *ngIf="regForm.controls['type'].errors?.phone && regForm.controls['type'].touched" class="mat-text-warn">Select User Role</small> <mat-error *ngIf="regForm.controls['type'].errors?.phone && regForm.controls['type'].touched" class="mat-text-warn">Select User Role</mat-error>
</mat-form-field> </mat-form-field>
</div> </div>
<div fxLayout="row" fxLayoutAlign="start center" class="mb-2"> <div fxLayout="row" fxLayoutAlign="start center" class="mb-2">
@ -122,7 +127,7 @@
</mat-form-field> </mat-form-field>
<mat-form-field dividerColor="primary" class="ml-xs mr-xs" style="width: 100%;"> <mat-form-field dividerColor="primary" class="ml-xs mr-xs" style="width: 100%;" *ngIf="typeValue == '1'">
<mat-select matInput placeholder="Select designation" [formControl]="regForm.controls['designation']" required> <mat-select matInput placeholder="Select designation" [formControl]="regForm.controls['designation']" required>
<mat-option>--</mat-option> <mat-option>--</mat-option>
<mat-option *ngFor="let d of designation" [value]="d"> <mat-option *ngFor="let d of designation" [value]="d">
@ -130,6 +135,14 @@
</mat-option> </mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
<mat-form-field dividerColor="primary" class="ml-xs mr-xs" style="width: 100%;" *ngIf="typeValue == '2'">
<mat-select matInput placeholder="Select lenderHierarchy" [formControl]="regForm.controls['lenderHierarchy']" required>
<mat-option>--</mat-option>
<mat-option *ngFor="let l of lenderHierarchy" [value]="l">
{{l.lender_hierarchy}}
</mat-option>
</mat-select>
</mat-form-field>
</div> </div>
<div fxLayout="row" fxLayoutAlign="start center" class="mb-2"> <div fxLayout="row" fxLayoutAlign="start center" class="mb-2">
@ -145,26 +158,20 @@
</mat-slide-toggle> </mat-slide-toggle>
</mat-card-content> </mat-card-content>
<hr> <hr>
<!-- <pre>{{regForm.controls['userid'].value | json}}</pre> -->
<!-- <mat-card-actions *ngIf="regForm.controls['userid'].value !=null">
<mat-card-actions *ngIf="usersData !=''"> <button mat-raised-button color="primary" type="submit">Submit</button>
</mat-card-actions> -->
<mat-card-actions >
<button mat-raised-button color="primary" type="submit">Submit</button> <button mat-raised-button color="primary" type="submit">Submit</button>
</mat-card-actions> </mat-card-actions>
<mat-card-actions *ngIf="usersData ==''">
<button mat-raised-button color="primary" [disabled]="!regForm.valid" type="submit">Submit</button>
</mat-card-actions>
</form> </form>
<!-- <button mat-raised-button color="primary" (click)="userupdate()" >Submit</button> --> <!-- <button mat-raised-button color="primary" (click)="userupdate()" >Submit</button> -->
<mat-form-field dividerColor="primary" class="ml-xs mr-xs" style="width: 100%;"> </mat-card>
<mat-select matInput placeholder="Select Role" [(ngModel)]="sampledrop" required multiple> <div *ngIf="loader">
<!-- <mat-option #allSelected (click)="toggleAllSelection()" [value]="0">ALL</mat-option> --> <mat-progress-bar mode="indeterminate" color="accent" class="mb-1"></mat-progress-bar>
<mat-option *ngFor="let role of roles" [value]="role" (click)="toggleAllSelection(role)">
{{role.name}} </div>
</mat-option>
</mat-select>
<!-- <small *ngIf="regForm.controls['role'].hasError('required') && regForm.controls['role'].touched" class="mat-text-warn">Select User Role</small>
<small *ngIf="regForm.controls['role'].errors?.phone && regForm.controls['role'].touched" class="mat-text-warn">Select User Role</small> -->
</mat-form-field>
</mat-card>

View File

@ -1,16 +1,16 @@
.mat-card-title{ // .mat-card-title{
color: #fff; // color: #fff;
margin-left: 13px; // margin-left: 13px;
background: rgba(157, 69, 124, 1); // background: rgba(157, 69, 124, 1);
box-shadow: 0 4px 20px 0 rgba(157, 69, 124, 1), 0 7px 10px -5px rgba(157, 69, 124, 1);; // box-shadow: 0 4px 20px 0 rgba(157, 69, 124, 1), 0 7px 10px -5px rgba(157, 69, 124, 1);;
display: inline-block; // display: inline-block;
border-radius: 6px; // border-radius: 6px;
padding: 10px; // padding: 10px;
margin-top: -52px; // margin-top: -52px;
} // }

View File

@ -16,6 +16,7 @@ export class RegisterComponent implements OnInit {
img: any; img: any;
roles: any; roles: any;
types: any; types: any;
loader:boolean = false;
public regForm: FormGroup; public regForm: FormGroup;
// name: string; // name: string;
@ -26,14 +27,18 @@ export class RegisterComponent implements OnInit {
City: any; City: any;
State: any; State: any;
designation: any; designation: any;
hierarchy:any=[];
files: File = null files: File = null
usersData: any; usersData: any;
sampledrop:any; sampledrop:any;
typeValue:any;
lenderHierarchy:any;
@ViewChild('allSelected') private allSelected: MatOption; @ViewChild('allSelected') private allSelected: MatOption;
constructor( constructor(
private router: Router, public fb: FormBuilder, public AWS: AwsService, private cd: ChangeDetectorRef private router: Router, public fb: FormBuilder, public AWS: AwsService, private cd: ChangeDetectorRef
, public shared: SharedService,private elementRef: ElementRef) { } , public shared: SharedService,private elementRef: ElementRef) { }
ngOnInit() { ngOnInit() {
if (this.AWS.localUserId != '' && this.AWS.localUserId != null && this.AWS.localUserId !== undefined) { if (this.AWS.localUserId != '' && this.AWS.localUserId != null && this.AWS.localUserId !== undefined) {
} else { } else {
@ -63,6 +68,7 @@ export class RegisterComponent implements OnInit {
userpic: [null], userpic: [null],
isactive: [true], isactive: [true],
pincode: [null], pincode: [null],
lenderHierarchy:[null,Validators.compose([Validators.required])],
}); });
this.userupdate(); this.userupdate();
@ -80,7 +86,7 @@ export class RegisterComponent implements OnInit {
this.AWS.entityType().subscribe(res => { this.AWS.entityType().subscribe(res => {
if (res.status == 200) { if (res.status == 200) {
this.types = res.records; this.types = res.records;
console.log(this.types); //console.log(this.types);
} }
}); });
this.AWS.City().subscribe(res => { this.AWS.City().subscribe(res => {
@ -98,10 +104,15 @@ export class RegisterComponent implements OnInit {
this.designation = res.records; this.designation = res.records;
} }
}); });
this.AWS.lenderHierarchy().subscribe(res=>{
if(res.status ==200){
this.lenderHierarchy = res.records;
}
})
//console.log(this.State+''+this.types+''+this.City+''+this.designation); //console.log(this.State+''+this.types+''+this.City+''+this.designation);
} }
onFileChange($event) { onFileChange($event) {
console.log($event.target.files[0]); //console.log($event.target.files[0]);
//if($event.target.files[0] < 0 ){ //if($event.target.files[0] < 0 ){
this.files = $event.target.files[0]; this.files = $event.target.files[0];
@ -109,26 +120,29 @@ export class RegisterComponent implements OnInit {
//console.log(this.files); //console.log(this.files);
} }
register(userData) { register(userData) {
console.log(userData); console.log(this.usersData);
// console.log(this.files); // console.log(this.files);
if (this.usersData != '') { if (this.usersData != '' && this.usersData !== undefined) {
if (this.files) { if (this.files) {
userData.userpic = this.files; userData.userpic = this.files;
} else { } else {
userData.userpic = this.usersData.profilepic; userData.userpic = this.usersData.profilepic;
} }
} else { } else {
if (this.files) { if (this.files) {
userData.userpic = this.files; userData.userpic = this.files;
} }
} }
console.log(this.usersData); //console.log(this.usersData);
this.loader = true;
if (this.usersData === undefined) { if (this.usersData === undefined) {
this.AWS.register(userData).subscribe(res => { this.AWS.register(userData).subscribe(res => {
if (res.User.UserStatus != '' && res.User.UserStatus !== undefined && res.User.UserStatus != null) { if (res.User.UserStatus != '' && res.User.UserStatus !== undefined && res.User.UserStatus != null) {
this.AWS.saveRecords(res, userData).subscribe(res => { this.AWS.saveRecords(res, userData).subscribe(res => {
if (res.status == 200) { if (res.status == 200) {
this.AWS.adminUpdateuser(userData, res.record).subscribe(res => { this.AWS.adminUpdateuser(userData, res.record).subscribe(res => {
this.loader =false;
console.log(res); console.log(res);
alert('user Created'); alert('user Created');
this.shared.redirectTo('settings/userListing'); this.shared.redirectTo('settings/userListing');
@ -140,7 +154,10 @@ console.log(this.usersData);
} else { } else {
this.AWS.adminchangeData(this.usersData,userData).subscribe(res=>{ this.AWS.adminchangeData(this.usersData,userData).subscribe(res=>{
this.AWS.saveRecords(res,userData).subscribe(res=>{ this.AWS.saveRecords(res,userData).subscribe(res=>{
console.log(res); this.loader = false;
alert('Update User');
this.shared.redirectTo('settings/userListing');
delete this.AWS.localUserId;
}) })
}) })
@ -172,36 +189,49 @@ console.log(this.usersData);
if (this.AWS.localUserId != '' && this.AWS.localUserId != null && this.AWS.localUserId !== undefined) { if (this.AWS.localUserId != '' && this.AWS.localUserId != null && this.AWS.localUserId !== undefined) {
this.usersData = this.AWS.localUserId; this.usersData = this.AWS.localUserId;
console.log(this.usersData); // console.log(this.usersData);
this.AWS.entityType().subscribe(res => { this.AWS.entityType().subscribe(res => {
if (res.status == 200) { if (res.status == 200) {
this.types = res.records; this.types = res.records;
let type = this.types.filter(type => type.entity_type_id == this.usersData.fk_entity_id)[0]; let type = this.types.filter(type => type.entity_type_id == this.usersData.fk_entity_id)[0];
this.regForm.controls['type'].setValue(type); this.regForm.controls['type'].setValue(type);
this.checktype(type);
} }
}); });
this.AWS.City().subscribe(res => { this.AWS.City().subscribe(res => {
if (res.status == 200) { if (res.status == 200) {
this.City = res.records.filter(city => city.city_id == this.usersData.fk_city); this.City = res.records;
this.regForm.controls['city'].setValue(this.City[0]); let citys = this.City.filter(city => city.city_id == this.usersData.fk_city)[0];
console.log(this.City); this.regForm.controls['city'].setValue(citys);
// console.log(this.City);
} }
}); });
this.AWS.State().subscribe(res => { this.AWS.State().subscribe(res => {
if (res.status == 200) { if (res.status == 200) {
this.State = res.records.filter(state => state.state_id == this.usersData.fk_state); this.State = res.records;
console.log(this.State); let states = this.State.filter(state => state.state_id == this.usersData.fk_state)[0];
this.regForm.controls['state'].setValue(this.State[0]); // console.log(this.State);
this.regForm.controls['state'].setValue(states);
} }
}); });
this.AWS.designation().subscribe(res => { this.AWS.designation().subscribe(res => {
if (res.status == 200) { if (res.status == 200) {
this.designation = res.records.filter(des => des.designation_id == this.usersData.fk_designation); this.designation = res.records;
this.regForm.controls['designation'].setValue(this.designation[0]); let des = this.designation.filter(des => des.designation_id == this.usersData.fk_designation)[0];
this.regForm.controls['designation'].setValue(des);
} }
}); });
this.AWS.lenderHierarchy().subscribe(res=>{
if(res.status ==200){
this.lenderHierarchy = res.records;
let hie = this.lenderHierarchy.filter(hie => hie.lender_hierarchy_id == this.usersData.fk_hierarchy_id)[0];
console.log(hie);
this.regForm.controls['lenderHierarchy'].setValue(hie);
}
})
let userRole: any = []; let userRole: any = [];
console.log(this.usersData.profilepic); //console.log(this.usersData.profilepic);
for (let role of this.usersData[0]) { for (let role of this.usersData[0]) {
//console.log(role); //console.log(role);
userRole.push(this.roles.filter(roles => roles.value == role.user_role)[0]); userRole.push(this.roles.filter(roles => roles.value == role.user_role)[0]);
@ -231,5 +261,26 @@ console.log(this.usersData);
this.img = this.usersData.profilepic; this.img = this.usersData.profilepic;
} }
} }
checktype(e){
console.log(e);
if(e !== undefined){
switch (e.entity_type_id) {
case "1":
this.typeValue =1;
break;
case "2":
this.typeValue =2;
break;
case "3":
this.typeValue =3;
break;
default :
this.typeValue = -1;
break;
}
}
}
back(){
this.router.navigate(['settings/userListing']);
}
} }

View File

@ -15,6 +15,9 @@ export const SettingsRoute: Routes = [
{ {
path:'userListing', path:'userListing',
component:UserListComponent component:UserListComponent
},{
path: 'userRegister',
component: RegisterComponent
},{ },{
path:'masters', path:'masters',
component:MastersComponent component:MastersComponent

View File

@ -1,12 +1,15 @@
<div *ngIf="loader"> <div *ngIf="loader">
<mat-progress-bar mode="indeterminate" color="accent" class="mb-1"></mat-progress-bar> <mat-progress-bar mode="indeterminate" color="accent" class="mb-1"></mat-progress-bar>
</div> </div>
<div style="text-align: right;"> <div style="text-align: right;">
<button mat-raised-button color="primary" (click)="addRegister()" > + Add Register</button> <button mat-raised-button color="primary" (click)="add()">Add Register</button>
</div> </div>
<mat-card> <mat-card>
<div datatable> <div datatable>
<table style="border-collapse: collapse"> <table style="border-collapse: collapse">
<thead> <thead>
<th style="text-align: center;">No</th> <th style="text-align: center;">No</th>
@ -16,19 +19,21 @@
<th style="text-align: center;">Action</th> <th style="text-align: center;">Action</th>
<th style="text-align: center;">Isactive</th> <th style="text-align: center;">Isactive</th>
</thead> </thead>
<tbody>
<tr *ngFor="let us of userdata; let i=index" > <tr *ngFor="let us of userdata; let i=index;" >
<td style="text-align: center;">{{i+1}}</td> <td style="text-align: center;">{{i+1}}</td>
<td style="text-align: center;">{{us.user_first_name}} {{us.user_last_name}}</td> <td style="text-align: center;">{{us.user_first_name}} {{us.user_last_name}}</td>
<td style="text-align: center;">{{us.email}}</td> <td style="text-align: center;">{{us.email}}</td>
<td style="text-align: center;">{{us.mobile_no}}</td> <td style="text-align: center;">{{us.mobile_no}}</td>
<td style="text-align: center;font-size: 20px"><a (click)="editUserDetails(us.userid,us.aws_name)"><i class="fa fa-pencil"></i></a></td> <td style="text-align: center;font-size: 20px"><a (click)="editUserDetails(us.userid,us.aws_name)"><mat-icon>edit</mat-icon></a></td>
<td *ngIf="us.isactive ==1" style="text-align: center;"><a (click)="isactive(us.userid,us.aws_name)"><i class="fa fa-check-circle active"></i></a></td> <td *ngIf="us.isactive ==1" style="text-align: center;"><a class="active" (click)="isactive(us.userid,us.aws_name)"><mat-icon>done</mat-icon></a></td>
<td *ngIf="us.isactive ==0" style="text-align: center;"><a (click)="isactive(us.userid,us.aws_name)"><i class="fa fa-times-circle deactive"></i></a></td> <td *ngIf="us.isactive ==0" style="text-align: center;"><a class="deactive" (click)="isactive(us.userid,us.aws_name)"><mat-icon>close</mat-icon></a></td>
</tr> </tr>
</tbody>
</table> </table>
</div> </div>

View File

@ -6,12 +6,20 @@ table {
text-align: left; text-align: left;
} }
.active{ .active{
padding-left: 6px;
color: green; color: green;
font-size: 20px; font-size: 20px;
} }
.active:hover{
color:red;
font-size:25px;
}
.deactive{ .deactive{
padding-left: 6px;
color: red; color: red;
font-size: 20px; font-size: 20px;
}
.deactive:hover{
color: green;
font-size: 25px;
} }

View File

@ -13,13 +13,17 @@ export class UserListComponent implements OnInit {
userdata: any = []; userdata: any = [];
loader: boolean = false; loader: boolean = false;
@ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatPaginator) paginator: MatPaginator;
constructor(public aws: AwsService, public route: Router, public shared: SharedService) { } constructor(public aws: AwsService, public route: Router, public shared: SharedService) { }
ngOnInit() { ngOnInit() {
this.getusers(); this.getusers();
delete this.aws.localUserId;
} }
getusers() { getusers() {
@ -32,18 +36,18 @@ export class UserListComponent implements OnInit {
} }
}) })
} }
isactive(id, awsname) { isactive(id, awsname) {
let userstatus = this.userdata.filter((users) => users.userid == id)[0]; let userstatus = this.userdata.filter((users) => users.userid == id)[0];
if (userstatus.isactive == 1) { if (userstatus.isactive == 1) {
this.aws.admindisabelUser(userstatus, awsname).subscribe(res => { this.aws.admindisabelUser(userstatus, awsname).subscribe(res => {
if (res == 0) { if (res == 0) {
let users = { let users = {
'records': {
'userid': userstatus.userid, 'userid': userstatus.userid,
'isactive': '0', 'isactive': '0',
} }
};
this.aws.adminupendis(users).subscribe(res => { this.aws.adminupendis(users).subscribe(res => {
if (res.status == 200) { if (res.status == 200) {
this.shared.redirectTo(this.route.url); this.shared.redirectTo(this.route.url);
@ -57,11 +61,11 @@ export class UserListComponent implements OnInit {
console.log(res); console.log(res);
if (res == 1) { if (res == 1) {
let users = { let users = {
'records': { 'userid': userstatus.userid,
'userid': userstatus.userid,
'isactive': '1', 'isactive': '1',
} }
};
this.aws.adminupendis(users).subscribe(res => { this.aws.adminupendis(users).subscribe(res => {
if (res.status == 200) { if (res.status == 200) {
this.shared.redirectTo(this.route.url); this.shared.redirectTo(this.route.url);
@ -79,8 +83,7 @@ export class UserListComponent implements OnInit {
this.route.navigate(['settings/userRegister']); this.route.navigate(['settings/userRegister']);
}); });
} }
add(){
addRegister(){
this.route.navigate(['settings/userRegister']); this.route.navigate(['settings/userRegister']);
} }
} }

View File

@ -1,8 +1,11 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AuthenticationDetails, CognitoUser, CognitoUserPool } from 'amazon-cognito-identity-js'; import { AuthenticationDetails, CognitoUser, CognitoUserPool } from 'amazon-cognito-identity-js';
import { Router } from "@angular/router"; import { Router, CanActivate, CanActivateChild } from "@angular/router";
import * as aws from 'aws-sdk'; import * as aws from 'aws-sdk';
import { Http, Headers, RequestOptions } from '@angular/http'; import { Http, Headers, RequestOptions } from '@angular/http';
import { of } from 'rxjs';
import { Observable } from 'rxjs/internal/Observable';
import { BooleanNullable } from 'aws-sdk/clients/glue';
let apiUrl = 'http://localhost/sparqapi/api/' let apiUrl = 'http://localhost/sparqapi/api/'
let currentuser: any = window.localStorage.getItem("Currentuser"); let currentuser: any = window.localStorage.getItem("Currentuser");
console.log(currentuser); console.log(currentuser);
@ -10,23 +13,14 @@ let poolData: any;
let userPool: any; let userPool: any;
if (currentuser != '' && currentuser != null && currentuser == 1) { //if (currentuser != '' && currentuser != null && currentuser == 1) {
poolData = { poolData = {
UserPoolId: 'ap-south-1_qQ85yQZJO', // Your user pool id here UserPoolId: 'ap-south-1_qQ85yQZJO', // Your user pool id here
ClientId: '2o5c3cs9k3als16nqhp3irh8rs' // Your client id here ClientId: '2o5c3cs9k3als16nqhp3irh8rs' // Your client id here
}; };
} else if (currentuser != '' && currentuser != null && currentuser == 2) {
poolData = {
UserPoolId: "ap-south-1_hFiGyr1Gw", // Your user pool id here
ClientId: "6egsdssf0i7h2o9mscqgqbn788" // Your client id here
}; //console.log(poolData);
} else {
}
console.log(poolData);
if (poolData !== undefined) { if (poolData !== undefined) {
userPool = new CognitoUserPool(poolData); userPool = new CognitoUserPool(poolData);
@ -34,19 +28,40 @@ if (poolData !== undefined) {
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class SharedService { export class SharedService implements CanActivateChild {
cognitoUser: any; cognitoUser: any;
jwttoken: any; jwttoken: any;
constructor(public route: Router,public http:Http) { // canActivate() {
// if(this.getroutersession()){
// // alert('session valid')
if (this.getAuthenticatedUser() !== '' && this.getAuthenticatedUser() !== undefined) { // return true;
this.route.navigate(['/home']); // }else{
} else { // this
this.route.navigate(['/']); // alert('session valid timeout');
} // return false;
// }
// }
canActivateChild(){
if(this.getroutersession()){
//alert('session valid')
return true;
}else{
this.route.navigate(['/authentication/login']);
//alert('session valid timeout');
return false;
}
} }
constructor(public route: Router,public http:Http) {
this.route.navigate([this.route.url]);
// if (this.getAuthenticatedUser() !== '' && this.getAuthenticatedUser() !== undefined) {
// this.route.navigate(['/home']);
// } else {
// this.route.navigate(['/']);
// }
}
/** /**
* refresh session function * refresh session function
@ -72,37 +87,83 @@ export class SharedService {
} }
} }
getroutersession(): any {
getheaderssession() { // gets the current user from the local storage
if (userPool !== undefined) { if (userPool !== undefined) {
this.cognitoUser = userPool.getCurrentUser(); this.cognitoUser = userPool.getCurrentUser();
console.log(this.cognitoUser);
} }
let jwttoken = ''; //let sessions = '';
let session = '';
let jwttoken:boolean = false;
let session = "";
if (this.cognitoUser != null) { if (this.cognitoUser != null) {
this.cognitoUser.getSession(function (err, session) { this.cognitoUser.getSession(function (err, session) {
if (err) { if (err) {
alert(err.message || JSON.stringify(err)); alert(err.message || JSON.stringify(err));
return; return;
} }
console.log('session validity: ' + session.isValid()); if(session.isValid()){
jwttoken = session; jwttoken = true;
}else{
jwttoken = false;
}
////(jwttoken);
}); });
//console.log() ////()
return jwttoken;
}
}
getheaderssession() {
if (userPool !== undefined) {
this.cognitoUser = userPool.getCurrentUser();
console.log(this.cognitoUser);
}
let jwttoken:any = '';
let sesvalid = '';
if (this.cognitoUser != null) {
this.cognitoUser.getSession(function (err, session) {
if (err) {
alert(err.message || JSON.stringify(err));
return;
}else{
console.log("else");
jwttoken = session;
}
// if(session.isValid()){
// jwttoken = session;
// }else{
// alert("session valid timeout");
// }
});
//console.log(jwttoken.isValid());
return jwttoken; return jwttoken;
} }
} }
headercofig(customeData){ headercofig(customeData){
let session:any = this.getheaderssession() ||""; let session:any = this.getheaderssession() || null;
let headers = new Headers( let headers:any
if(session !=null){
headers = new Headers(
{ {
'Content-Type':'application/json','Authorization':'sparqvenba2018','Token':session.getIdToken().getJwtToken() 'Content-Type':'application/json','Authorization':'sparqvenba2018','Token':session.getIdToken().getJwtToken()
}); });
}else{
//alert('token not attached');
this.redirectTo(this.route.url);
}
return headers; return headers;
} }
@ -118,10 +179,10 @@ export class SharedService {
* Get Roles * Get Roles
*/ */
getroles(){ getroles(){
let cogusers:any = this.getheaderssession() ||""; let cogusers:any = this.getheaderssession();
console.log(cogusers.idToken.payload.locale); console.log(cogusers.idToken.payload.locale);
let roles = {'userid':cogusers.idToken.payload.locale}; let roles = {'userid':cogusers.idToken.payload.locale};
let headers = this.headercofig(''); let headers = this.headercofig('');
return this.http.post(apiUrl+'getUsersDetails',roles,{headers:headers}).map(res=>res.json()); return this.http.post(apiUrl+'getUsersDetails',roles,{headers:headers}).map(res=>res.json());
} }
} }

View File

@ -64,9 +64,9 @@ const MENUITEMS : Menu[] = [
type:'sub', type:'sub',
icon:'settings', icon:'settings',
children:[ children:[
{state:'userRegister',name:'User Register'}, {state: 'masters',name:'Master Details'},
{state:'userListing',name:'User Listing'}, {state:'userListing',name:'User Listing'},
{state: 'masters',name:'Master Details'}
] ]
}, },
{ {

View File

@ -26,14 +26,16 @@
<img src="../../../assets/images/test3.jpg" width="200" height="200" alt="user"> <img src="../../../assets/images/test3.jpg" width="200" height="200" alt="user">
</div> </div>
<div class="profile-info"> <div class="profile-info">
<h3 class="profile-name"><strong>Jane Doe</strong></h3> <h3 class="profile-name"><strong>{{userDetails.user_full_name}}</strong></h3>
<span class="user-name">@JaneDoe</span> <span class="user-name">{{userDetails.email}}</span>
<span class="user-name">{{userDetails.mobile_no}}</span>
<span class="pro-des"> <span class="pro-des">
CEO at @DoeCorp
</span> </span>
<span><i class="fa fa-map-marker"></i> San Jose,USA</span> <span><i class="fa fa-map-marker"></i> {{userDetails.addressline1}} {{userDetails.addressline2}}</span>
<span><i class="fa fa-calendar"></i>Joined March 2009</span> <span><i class="fa fa-calendar"></i>{{userDetails.addressline3}} {{userDetails.state_name}} - {{userDetails.pincode}}</span>
<span><i class="fa fa-birthday-cake"></i>29 December,1978</span> <span>{{userDetails.createdon | date:'dd MMM yyyy'}}</span>
</div> </div>
</div> </div>
<div fxFlex.gt-sm="50" fxFlex.gt-xs="50" fxFlex="100" class="mt-1"> <div fxFlex.gt-sm="50" fxFlex.gt-xs="50" fxFlex="100" class="mt-1">
@ -55,10 +57,14 @@
</div> </div>
<div class="pl-1 pr-1 profile-i" fxFlex.xs="85" fxFlex.sm="85" fxFlex.md="85" fxFlex.lg="85" fxFlex.xl="85"> <div class="pl-1 pr-1 profile-i" fxFlex.xs="85" fxFlex.sm="85" fxFlex.md="85" fxFlex.lg="85" fxFlex.xl="85">
<div> <div>
<span class="post-profile-head">Jane Doe</span> <span class="post-profile-head">{{userDetails.user_full_name}}</span>
<span class="twitter-uname">@JaneDoe</span> <span class="twitter-uname"><i class="fa fa-email"></i> {{userDetails.email}}</span>
<span class="time">Sep 3, 2017</span> <span class="time">{{userDetails.createdon | date:'dd MMM yyyy'}}</span>
<p>Continued jobless claims at lowest level in more than 28 years</p> <p><i class="fa fa-mobile"></i> {{userDetails.mobile_no}}</p>
<p>{{userDetails.addressline1}} {{userDetails.addressline2}} <br/>
{{userDetails.addressline3}} - {{userDetails.pincode}} {{userDetails.state_name}}
</p>
</div> </div>
<div class="profile-action"><a href=""><i class="fa fa-retweet"></i></a><a href=""><i class="fa fa-comment-o"></i></a><a href=""><i class="fa fa-heart-o"></i></a></div> <div class="profile-action"><a href=""><i class="fa fa-retweet"></i></a><a href=""><i class="fa fa-comment-o"></i></a><a href=""><i class="fa fa-heart-o"></i></a></div>
</div> </div>

View File

@ -3,6 +3,7 @@ import { AwsService } from '../../aws.service';
import { MatDialog, MatDialogRef, MatDialogConfig } from '@angular/material'; import { MatDialog, MatDialogRef, MatDialogConfig } from '@angular/material';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
import { CustomValidators } from 'ng2-validation'; import { CustomValidators } from 'ng2-validation';
import { SharedService } from '../../shared.service';
@Component({ @Component({
selector: 'ms-user-profile', selector: 'ms-user-profile',
templateUrl:'./user-profile-component.html', templateUrl:'./user-profile-component.html',
@ -21,30 +22,36 @@ export class UserProfileComponent implements OnInit {
right: '' right: ''
} }
}; };
constructor(public AWS:AwsService,public dialog: MatDialog) {} userDetails:any=[];
constructor(public AWS:AwsService,public dialog: MatDialog,public shared:SharedService ) {}
ngOnInit() { ngOnInit() {
this.getuser(); this.getuser();
} }
getuser(){ getuser(){
console.log(this.AWS.getUser()); //console.log(this.AWS.getUser());
this.shared.getroles().subscribe(res=>{
this.userDetails = res.records[0];
});
} }
changePassword(){ changePassword(){
let dialogRef = this.dialog.open(ChangePasswordDialog,this.config); let dialogRef = this.dialog.open(ChangePasswordDialog,this.config);
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
console.log(result); if(result !==undefined){
if(result.confirmPassword !="" && result.newPassword !="" && result.oldPassword !=""){ if(result.confirmPassword !== undefined && result.confirmPassword !="" && result.newPassword !="" && result.oldPassword !=""){
this.AWS.changepassword(result) this.AWS.changepassword(result)
.subscribe(res=>{ .subscribe(res=>{
alert('Change Password'); alert('Change Password');
}) })
} }
}
//console.log(ChangePasswordDialog.prototype.pass); //console.log(ChangePasswordDialog.prototype.pass);
}); });
} }
} }