From d52bcb1990b1e398bf5075a14e5e2e4e9736ede3 Mon Sep 17 00:00:00 2001 From: venbaSriram Date: Thu, 20 Sep 2018 12:48:57 +0530 Subject: [PATCH] sparqclientapp user mangement aws --- sineedge/package-lock.json | 8 + sineedge/package.json | 1 + sineedge/src/app/app.module.ts | 4 +- sineedge/src/app/app.routing.ts | 5 +- sineedge/src/app/aws.service.ts | 155 ++- .../layouts/admin/admin-layout.component.html | 1059 +++++++++-------- .../layouts/admin/admin-layout.component.ts | 13 +- .../settings/register/register.component.html | 89 +- .../settings/register/register.component.scss | 20 +- .../settings/register/register.component.ts | 89 +- sineedge/src/app/settings/settings.routing.ts | 3 + .../user-list/user-list.component.html | 23 +- .../user-list/user-list.component.scss | 12 +- .../settings/user-list/user-list.component.ts | 19 +- sineedge/src/app/shared.service.ts | 133 ++- .../src/app/shared/menu-items/menu-items.ts | 4 +- .../user-profile/user-profile-component.html | 26 +- .../user-profile/user-profile.component.ts | 17 +- 18 files changed, 958 insertions(+), 722 deletions(-) diff --git a/sineedge/package-lock.json b/sineedge/package-lock.json index 8236241..ea4bdf7 100755 --- a/sineedge/package-lock.json +++ b/sineedge/package-lock.json @@ -6986,6 +6986,14 @@ "resolved": "https://registry.npmjs.org/ngx-color-picker/-/ngx-color-picker-4.5.3.tgz", "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": { "version": "5.0.0-7", "resolved": "https://registry.npmjs.org/ngx-perfect-scrollbar/-/ngx-perfect-scrollbar-5.0.0-7.tgz", diff --git a/sineedge/package.json b/sineedge/package.json index aea7053..d8bb8ba 100755 --- a/sineedge/package.json +++ b/sineedge/package.json @@ -50,6 +50,7 @@ "ng2-translate": "5.0.0", "ng2-validation": "4.2.0", "ngx-color-picker": "^4.0.3", + "ngx-mat-select-search": "^1.3.1", "ngx-perfect-scrollbar": "5.0.0-7", "node-sass": "^4.9.3", "perfect-scrollbar": "^1.3.0", diff --git a/sineedge/src/app/app.module.ts b/sineedge/src/app/app.module.ts index 03df850..c7d87a4 100755 --- a/sineedge/src/app/app.module.ts +++ b/sineedge/src/app/app.module.ts @@ -10,10 +10,10 @@ import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar'; import { PERFECT_SCROLLBAR_CONFIG } from 'ngx-perfect-scrollbar'; import { PerfectScrollbarConfigInterface } from 'ngx-perfect-scrollbar'; 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 { DemoMaterialModule } from './shared/demo.module'; + import {MatSidenavModule} from '@angular/material/sidenav'; import {MatInputModule} from '@angular/material/input'; diff --git a/sineedge/src/app/app.routing.ts b/sineedge/src/app/app.routing.ts index 1d1b242..978968f 100755 --- a/sineedge/src/app/app.routing.ts +++ b/sineedge/src/app/app.routing.ts @@ -2,14 +2,15 @@ import { Routes } from '@angular/router'; import { AdminLayoutComponent } from './layouts/admin/admin-layout.component'; import { AuthLayoutComponent } from './layouts/auth/auth-layout.component'; - +import { SharedService } from './shared.service'; export const AppRoutes: Routes = [{ path: '', - redirectTo: 'authentication', + redirectTo: 'home', pathMatch: 'full', }, { path: '', component: AdminLayoutComponent, + canActivateChild: [SharedService], children: [{ path: 'home', loadChildren: './dashboard/dashboard.module#DashboardModule' diff --git a/sineedge/src/app/aws.service.ts b/sineedge/src/app/aws.service.ts index 32b0444..55206a0 100755 --- a/sineedge/src/app/aws.service.ts +++ b/sineedge/src/app/aws.service.ts @@ -16,11 +16,11 @@ import { LoginComponent } from "./session/login/login.component"; import { Http, Headers, RequestOptions } from '@angular/http'; import { HttpClient } from '@angular/common/http'; import 'rxjs/add/operator/map'; - + import { SharedService } from './shared.service'; -let apiurl = 'http://localhost/sparqapi/api/'; + const sineedge_poolData = { UserPoolId: "ap-south-1_y7dt3iEaX", //ap-south-1_qQ85yQZJO UserName :SPARQ_SINEEDGE_DEV 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 vendorIdenttiy = ""; // serviceProvider -// apiurl = "http://localhost/sineedge/sparqapi/api/"; +const apiurl = "http://localhost/sineedge/sparqapi/api/"; const currentdate = new Date().toJSON().slice(0,19).replace('T',' '); @Injectable({ @@ -126,7 +126,7 @@ export class AwsService { // gets the current user from the local storage this.cognitoUser = sineedgedevUserpool.getCurrentUser(); //let sessions = ''; - + let jwttoken = ""; let session = ""; if (this.cognitoUser != null) { @@ -203,8 +203,23 @@ export class AwsService { */ logOut() { window.localStorage.removeItem("Currentuser"); - this.getUser().signOut(); - this.cognitoUser = null; + let session = this.getAuthenticatedUser() || ""; + //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 @@ -271,6 +286,7 @@ export class AwsService { ] }; } else if (userData.type.entity_type_id == 2) { + console.log(2); params = { UserPoolId: lender_poolData.UserPoolId /* required */, Username: userData.email /* required */, @@ -294,7 +310,7 @@ export class AwsService { ] }; } - // .log(params); + console.log(params); return Observable.create(observe => { let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider(); @@ -306,30 +322,32 @@ export class AwsService { // an error occurred - this.mySecData = data; + AwsService.prototype.UserGroup(data, userData); observe.next(data); // successful response }); }); + }else{ + return alert('Admin Only create user'); } } UserGroup(cognitodata, userData) { //(userData); - +console.log(cognitodata); let session = this.getAuthenticatedUser() || ""; this.getconfig(); //let cognitodata = "539bfefa-ae42-4bee-bf79-4b15d1a2af7f"; - if(userData.userid ==''){ + if(userData.userid === null ){ for(let role of userData.role){ let params: any; if (userData.type.entity_type_id == 1) { - + params = { GroupName: role.value /* required */, UserPoolId: sineedgedev_poolData.UserPoolId,//"ap-south-1_y7dt3iEaX" /* required */, @@ -433,43 +451,59 @@ export class AwsService { createdby = this.getlocale(); 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(); 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=[]; for(var role of users.role){ 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('roles',JSON.stringify(roles)); formData.append('profilepic',users.userpic); + //new Response(formData).text().then(console.log); //let headers = this.shared.headercofig(''); let session:any = this.getAuthenticatedUser() ||""; @@ -481,7 +515,9 @@ export class AwsService { //(request); 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()); + }else{ return this.http.post(apiurl + "saveNewUser", formData, { headers: headers }).map(res => res.json()); } @@ -503,9 +539,10 @@ export class AwsService { usergroup => usergroup == "ADMIN" )[0]; //cognitosdata = 7; - + let params:any; if (userGroup == 'ADMIN') { - var params = { + if(user.type.entity_type_id ==1){ + params = { UserAttributes: [ /* required */ { Name: 'locale', /* required */ @@ -516,6 +553,19 @@ export class AwsService { 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() + }, + /* more items */ + ], + UserPoolId: lender_poolData.UserPoolId, /* required */ + Username: user.email /* required */ + }; + } //console.log(params); return Observable.create(observe => { let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider(); @@ -606,11 +656,18 @@ export class AwsService { * @param records */ adminupendis(records){ - let headers = this.shared.headercofig(''); - console.log(headers); - let users = this.http.post(apiurl + 'updateExistUser',JSON.stringify(records), { headers: headers }).map(res => res.json()); - console.log(users); - return users; + //let headers = this.shared.headercofig(''); + // console.log(headers); + let session = this.getAuthenticatedUser() || ""; + let formData = new FormData(); + 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 @@ -645,7 +702,7 @@ export class AwsService { if (userData.fk_entity_id == 1) { params = { UserPoolId: sineedgedev_poolData.UserPoolId /* required */, - Username: userData.email,//userData.email /* required */, + Username: userData.aws_name,//userData.email /* required */, // ForceAliasCreation: true || false, @@ -664,7 +721,7 @@ export class AwsService { } else if (userData.fk_entity_id == 2) { params = { UserPoolId: lender_poolData.UserPoolId /* required */, - Username: changeusers.email /* required */, + Username: userData.aws_name /* required */, UserAttributes: [ { @@ -679,6 +736,7 @@ export class AwsService { ] }; } + console.log(params); return Observable.create(observe=>{ let cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider(); cognitoidentityserviceprovider.adminUpdateUserAttributes(params, function(err, data) { @@ -774,5 +832,10 @@ adminremoveGroup(roles,users){ let master_name = {'master_name':'DESIGNATION'}; 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()); + } } diff --git a/sineedge/src/app/layouts/admin/admin-layout.component.html b/sineedge/src/app/layouts/admin/admin-layout.component.html index a6a1a44..ca0232b 100755 --- a/sineedge/src/app/layouts/admin/admin-layout.component.html +++ b/sineedge/src/app/layouts/admin/admin-layout.component.html @@ -1,533 +1,534 @@
- - -
- + + \ No newline at end of file diff --git a/sineedge/src/app/layouts/admin/admin-layout.component.ts b/sineedge/src/app/layouts/admin/admin-layout.component.ts index 50d2d47..f167db7 100755 --- a/sineedge/src/app/layouts/admin/admin-layout.component.ts +++ b/sineedge/src/app/layouts/admin/admin-layout.component.ts @@ -11,6 +11,7 @@ import PerfectScrollbar from 'perfect-scrollbar'; import { PerfectScrollbarConfigInterface, PerfectScrollbarComponent, PerfectScrollbarDirective } from 'ngx-perfect-scrollbar'; import { SharedService } from '../../shared.service'; +import { AwsService } from '../../aws.service'; @Component({ selector: 'app-layout', templateUrl: './admin-layout.component.html' @@ -42,7 +43,7 @@ export class AdminLayoutComponent implements OnInit, OnDestroy { @ViewChild('sidemenu') sidemenu; 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(); 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']); + } } diff --git a/sineedge/src/app/settings/register/register.component.html b/sineedge/src/app/settings/register/register.component.html index 6d16379..ab28d31 100755 --- a/sineedge/src/app/settings/register/register.component.html +++ b/sineedge/src/app/settings/register/register.component.html @@ -1,24 +1,27 @@ + + - User Registration + + User Registration
+ You must include a first name. + Your first name must be at least 5 characters long. + Your first name cannot exceed 10 characters. - You must include a first name. - Your first name must be at least 5 characters long. - Your first name cannot exceed 10 characters. - + + You must include a last name. - You must include a last name. - + @@ -28,15 +31,15 @@
+ You must include an email address. + You must include a valid email address. - You must include an email address. - You must include a valid email address. - + - You must include a valid email address. + You must include a valid email address.
@@ -46,15 +49,17 @@
+ You must include phone number. + You must include a valid phone number. + - You must include phone number. - You must include a valid phone number. - + + You must include a valid phone number. + - - You must include a valid phone number. + @@ -85,21 +90,21 @@ - Select User Role - Select User Role + Select User Role + Select User Role - + -- {{types.name}} - Select User Role - Select User Role + Select User Role + Select User Role - +
@@ -122,7 +127,7 @@ - + -- @@ -130,6 +135,14 @@ + + + -- + + {{l.lender_hierarchy}} + + +
@@ -145,26 +158,20 @@
+ + + + - - - - - - - - - {{role.name}} - - - - - - \ No newline at end of file + +
+ + +
\ No newline at end of file diff --git a/sineedge/src/app/settings/register/register.component.scss b/sineedge/src/app/settings/register/register.component.scss index fb6260e..cdb0650 100755 --- a/sineedge/src/app/settings/register/register.component.scss +++ b/sineedge/src/app/settings/register/register.component.scss @@ -1,16 +1,16 @@ - .mat-card-title{ + // .mat-card-title{ - color: #fff; - margin-left: 13px; - 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);; - display: inline-block; - border-radius: 6px; - padding: 10px; - margin-top: -52px; + // color: #fff; + // margin-left: 13px; + // 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);; + // display: inline-block; + // border-radius: 6px; + // padding: 10px; + // margin-top: -52px; - } + // } diff --git a/sineedge/src/app/settings/register/register.component.ts b/sineedge/src/app/settings/register/register.component.ts index ab62ed1..972f118 100755 --- a/sineedge/src/app/settings/register/register.component.ts +++ b/sineedge/src/app/settings/register/register.component.ts @@ -16,6 +16,7 @@ export class RegisterComponent implements OnInit { img: any; roles: any; types: any; + loader:boolean = false; public regForm: FormGroup; // name: string; @@ -26,14 +27,18 @@ export class RegisterComponent implements OnInit { City: any; State: any; designation: any; + hierarchy:any=[]; files: File = null usersData: any; sampledrop:any; + typeValue:any; + lenderHierarchy:any; @ViewChild('allSelected') private allSelected: MatOption; constructor( private router: Router, public fb: FormBuilder, public AWS: AwsService, private cd: ChangeDetectorRef , public shared: SharedService,private elementRef: ElementRef) { } ngOnInit() { + if (this.AWS.localUserId != '' && this.AWS.localUserId != null && this.AWS.localUserId !== undefined) { } else { @@ -63,6 +68,7 @@ export class RegisterComponent implements OnInit { userpic: [null], isactive: [true], pincode: [null], + lenderHierarchy:[null,Validators.compose([Validators.required])], }); this.userupdate(); @@ -80,7 +86,7 @@ export class RegisterComponent implements OnInit { this.AWS.entityType().subscribe(res => { if (res.status == 200) { this.types = res.records; - console.log(this.types); + //console.log(this.types); } }); this.AWS.City().subscribe(res => { @@ -98,10 +104,15 @@ export class RegisterComponent implements OnInit { 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); } onFileChange($event) { - console.log($event.target.files[0]); + //console.log($event.target.files[0]); //if($event.target.files[0] < 0 ){ this.files = $event.target.files[0]; @@ -109,26 +120,29 @@ export class RegisterComponent implements OnInit { //console.log(this.files); } register(userData) { - console.log(userData); + console.log(this.usersData); // console.log(this.files); - if (this.usersData != '') { + if (this.usersData != '' && this.usersData !== undefined) { if (this.files) { userData.userpic = this.files; } else { userData.userpic = this.usersData.profilepic; } } else { - if (this.files) { + if (this.files) { userData.userpic = this.files; - } + } } -console.log(this.usersData); +//console.log(this.usersData); +this.loader = true; if (this.usersData === undefined) { + this.AWS.register(userData).subscribe(res => { if (res.User.UserStatus != '' && res.User.UserStatus !== undefined && res.User.UserStatus != null) { this.AWS.saveRecords(res, userData).subscribe(res => { if (res.status == 200) { this.AWS.adminUpdateuser(userData, res.record).subscribe(res => { + this.loader =false; console.log(res); alert('user Created'); this.shared.redirectTo('settings/userListing'); @@ -140,7 +154,10 @@ console.log(this.usersData); } else { this.AWS.adminchangeData(this.usersData,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) { this.usersData = this.AWS.localUserId; - console.log(this.usersData); + // console.log(this.usersData); this.AWS.entityType().subscribe(res => { if (res.status == 200) { this.types = res.records; let type = this.types.filter(type => type.entity_type_id == this.usersData.fk_entity_id)[0]; this.regForm.controls['type'].setValue(type); + this.checktype(type); } }); this.AWS.City().subscribe(res => { if (res.status == 200) { - this.City = res.records.filter(city => city.city_id == this.usersData.fk_city); - this.regForm.controls['city'].setValue(this.City[0]); - console.log(this.City); + this.City = res.records; + let citys = this.City.filter(city => city.city_id == this.usersData.fk_city)[0]; + this.regForm.controls['city'].setValue(citys); + // console.log(this.City); } }); this.AWS.State().subscribe(res => { if (res.status == 200) { - this.State = res.records.filter(state => state.state_id == this.usersData.fk_state); - console.log(this.State); - this.regForm.controls['state'].setValue(this.State[0]); + this.State = res.records; + let states = this.State.filter(state => state.state_id == this.usersData.fk_state)[0]; + // console.log(this.State); + this.regForm.controls['state'].setValue(states); } }); this.AWS.designation().subscribe(res => { if (res.status == 200) { - this.designation = res.records.filter(des => des.designation_id == this.usersData.fk_designation); - this.regForm.controls['designation'].setValue(this.designation[0]); + this.designation = res.records; + 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 = []; - console.log(this.usersData.profilepic); + //console.log(this.usersData.profilepic); for (let role of this.usersData[0]) { //console.log(role); 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; } } - + 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']); + } } diff --git a/sineedge/src/app/settings/settings.routing.ts b/sineedge/src/app/settings/settings.routing.ts index e177053..ac33c5d 100755 --- a/sineedge/src/app/settings/settings.routing.ts +++ b/sineedge/src/app/settings/settings.routing.ts @@ -15,6 +15,9 @@ export const SettingsRoute: Routes = [ { path:'userListing', component:UserListComponent + },{ + path: 'userRegister', + component: RegisterComponent },{ path:'masters', component:MastersComponent diff --git a/sineedge/src/app/settings/user-list/user-list.component.html b/sineedge/src/app/settings/user-list/user-list.component.html index 4008331..96700e4 100644 --- a/sineedge/src/app/settings/user-list/user-list.component.html +++ b/sineedge/src/app/settings/user-list/user-list.component.html @@ -1,12 +1,15 @@
-
-
- -
+
+ +
+
+ + + @@ -16,19 +19,21 @@ - - + + - + - + - + + +
NoAction Isactive
{{i+1}} {{us.user_first_name}} {{us.user_last_name}} {{us.email}} {{us.mobile_no}}editdoneclose
diff --git a/sineedge/src/app/settings/user-list/user-list.component.scss b/sineedge/src/app/settings/user-list/user-list.component.scss index 4745956..5f4a8eb 100644 --- a/sineedge/src/app/settings/user-list/user-list.component.scss +++ b/sineedge/src/app/settings/user-list/user-list.component.scss @@ -6,12 +6,20 @@ table { text-align: left; } .active{ - padding-left: 6px; + color: green; font-size: 20px; } +.active:hover{ + color:red; + font-size:25px; +} .deactive{ - padding-left: 6px; + color: red; font-size: 20px; +} +.deactive:hover{ + color: green; + font-size: 25px; } \ No newline at end of file diff --git a/sineedge/src/app/settings/user-list/user-list.component.ts b/sineedge/src/app/settings/user-list/user-list.component.ts index 4429c6c..c160d4f 100644 --- a/sineedge/src/app/settings/user-list/user-list.component.ts +++ b/sineedge/src/app/settings/user-list/user-list.component.ts @@ -13,13 +13,17 @@ export class UserListComponent implements OnInit { userdata: any = []; loader: boolean = false; + @ViewChild(MatPaginator) paginator: MatPaginator; constructor(public aws: AwsService, public route: Router, public shared: SharedService) { } + + ngOnInit() { this.getusers(); + delete this.aws.localUserId; } getusers() { @@ -32,18 +36,18 @@ export class UserListComponent implements OnInit { } }) } - isactive(id, awsname) { let userstatus = this.userdata.filter((users) => users.userid == id)[0]; if (userstatus.isactive == 1) { this.aws.admindisabelUser(userstatus, awsname).subscribe(res => { if (res == 0) { let users = { - 'records': { + 'userid': userstatus.userid, 'isactive': '0', } - }; + + this.aws.adminupendis(users).subscribe(res => { if (res.status == 200) { this.shared.redirectTo(this.route.url); @@ -57,11 +61,11 @@ export class UserListComponent implements OnInit { console.log(res); if (res == 1) { let users = { - 'records': { - 'userid': userstatus.userid, + 'userid': userstatus.userid, 'isactive': '1', } - }; + + this.aws.adminupendis(users).subscribe(res => { if (res.status == 200) { this.shared.redirectTo(this.route.url); @@ -79,8 +83,7 @@ export class UserListComponent implements OnInit { this.route.navigate(['settings/userRegister']); }); } - - addRegister(){ + add(){ this.route.navigate(['settings/userRegister']); } } diff --git a/sineedge/src/app/shared.service.ts b/sineedge/src/app/shared.service.ts index d3a1c60..e9820db 100755 --- a/sineedge/src/app/shared.service.ts +++ b/sineedge/src/app/shared.service.ts @@ -1,8 +1,11 @@ import { Injectable } from '@angular/core'; 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 { 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 currentuser: any = window.localStorage.getItem("Currentuser"); console.log(currentuser); @@ -10,23 +13,14 @@ let poolData: any; let userPool: any; -if (currentuser != '' && currentuser != null && currentuser == 1) { +//if (currentuser != '' && currentuser != null && currentuser == 1) { poolData = { UserPoolId: 'ap-south-1_qQ85yQZJO', // Your user pool 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 - }; - -} else { - -} -console.log(poolData); +//console.log(poolData); if (poolData !== undefined) { userPool = new CognitoUserPool(poolData); @@ -34,19 +28,40 @@ if (poolData !== undefined) { @Injectable({ providedIn: 'root' }) -export class SharedService { +export class SharedService implements CanActivateChild { cognitoUser: any; jwttoken: any; - constructor(public route: Router,public http:Http) { - - - if (this.getAuthenticatedUser() !== '' && this.getAuthenticatedUser() !== undefined) { - this.route.navigate(['/home']); - } else { - this.route.navigate(['/']); - } - +// canActivate() { +// if(this.getroutersession()){ +// // alert('session valid') +// return true; +// }else{ +// this +// 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 @@ -72,37 +87,83 @@ export class SharedService { } } - - getheaderssession() { + getroutersession(): any { + // gets the current user from the local storage if (userPool !== undefined) { this.cognitoUser = userPool.getCurrentUser(); - console.log(this.cognitoUser); } - let jwttoken = ''; - let session = ''; + //let sessions = ''; + + let jwttoken:boolean = false; + let session = ""; if (this.cognitoUser != null) { this.cognitoUser.getSession(function (err, session) { if (err) { alert(err.message || JSON.stringify(err)); return; } - console.log('session validity: ' + session.isValid()); - jwttoken = session; + if(session.isValid()){ + 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; } } 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() }); + }else{ + //alert('token not attached'); + this.redirectTo(this.route.url); + } return headers; } @@ -118,10 +179,10 @@ export class SharedService { * Get Roles */ getroles(){ - let cogusers:any = this.getheaderssession() ||""; + let cogusers:any = this.getheaderssession(); console.log(cogusers.idToken.payload.locale); let roles = {'userid':cogusers.idToken.payload.locale}; let headers = this.headercofig(''); return this.http.post(apiUrl+'getUsersDetails',roles,{headers:headers}).map(res=>res.json()); - } -} + } +} diff --git a/sineedge/src/app/shared/menu-items/menu-items.ts b/sineedge/src/app/shared/menu-items/menu-items.ts index 80381e0..231bbec 100755 --- a/sineedge/src/app/shared/menu-items/menu-items.ts +++ b/sineedge/src/app/shared/menu-items/menu-items.ts @@ -64,9 +64,9 @@ const MENUITEMS : Menu[] = [ type:'sub', icon:'settings', children:[ - {state:'userRegister',name:'User Register'}, + {state: 'masters',name:'Master Details'}, {state:'userListing',name:'User Listing'}, - {state: 'masters',name:'Master Details'} + ] }, { diff --git a/sineedge/src/app/user-pages/user-profile/user-profile-component.html b/sineedge/src/app/user-pages/user-profile/user-profile-component.html index 3ac74fa..0d1c48b 100755 --- a/sineedge/src/app/user-pages/user-profile/user-profile-component.html +++ b/sineedge/src/app/user-pages/user-profile/user-profile-component.html @@ -26,14 +26,16 @@ user
-

Jane Doe

- @JaneDoe +

{{userDetails.user_full_name}}

+ {{userDetails.email}} + {{userDetails.mobile_no}} + - CEO at @DoeCorp + - San Jose,USA - Joined March 2009 - 29 December,1978 + {{userDetails.addressline1}} {{userDetails.addressline2}} + {{userDetails.addressline3}} {{userDetails.state_name}} - {{userDetails.pincode}} + {{userDetails.createdon | date:'dd MMM yyyy'}}
@@ -55,10 +57,14 @@
- Jane Doe - - Sep 3, 2017 -

Continued jobless claims at lowest level in more than 28 years

+ {{userDetails.user_full_name}} + + {{userDetails.createdon | date:'dd MMM yyyy'}} +

{{userDetails.mobile_no}}

+

{{userDetails.addressline1}} {{userDetails.addressline2}}
+ {{userDetails.addressline3}} - {{userDetails.pincode}} {{userDetails.state_name}} +

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