From 6b9bf73b8206e43c34fca40708dd011919675c5c Mon Sep 17 00:00:00 2001 From: Yura Simonyan Date: Fri, 12 Mar 2021 11:15:34 +0200 Subject: [PATCH] fixed errors in user state --- src/app/header/header.component.ts | 25 ++++----- .../shared/store/user-registration.state.ts | 21 ++++---- .../provider-config.component.ts | 51 ++++++++++++++++++- 3 files changed, 73 insertions(+), 24 deletions(-) diff --git a/src/app/header/header.component.ts b/src/app/header/header.component.ts index 7b0b38fdf7..a0d5ba4221 100644 --- a/src/app/header/header.component.ts +++ b/src/app/header/header.component.ts @@ -10,8 +10,8 @@ import { Router } from '@angular/router'; import { HostListener } from '@angular/core'; enum RoleLinks{ - provider='provider', - parent ='parent' + provider= 'provider', + parent = 'parent' } @Component({ @@ -23,17 +23,18 @@ export class HeaderComponent implements OnInit { user = { firstName: 'Іванов В. М' - } - showModalReg: boolean = false; + }; + showModalReg = false; @Select(UserRegistrationState.isAuthorized) isAuthorized$: Observable; + @Select(UserRegistrationState.userName) + userName$: Observable; constructor(private modalDialog: MatDialog, - public store: Store, - private actions$: Actions, - public snackBar: MatSnackBar, - private router: Router) { + public store: Store, + private actions$: Actions, + public snackBar: MatSnackBar) { actions$.pipe( ofAction(AuthFail) ).subscribe(action => { @@ -41,16 +42,16 @@ export class HeaderComponent implements OnInit { duration: 5000, panelClass: ['red-snackbar'], }); - }) + }); } ngOnInit(): void { - this.store.dispatch(new CheckAuth()) + this.store.dispatch(new CheckAuth()); } logout(): void { - this.store.dispatch(new Logout()) + this.store.dispatch(new Logout()); } login(): void{ - this.store.dispatch(new Login()) + this.store.dispatch(new Login()); } } diff --git a/src/app/shared/store/user-registration.state.ts b/src/app/shared/store/user-registration.state.ts index 67e911eeb9..3c1ffed061 100644 --- a/src/app/shared/store/user-registration.state.ts +++ b/src/app/shared/store/user-registration.state.ts @@ -4,20 +4,21 @@ import { Login, Logout, CheckAuth, AuthFail } from './user-registration.actions' import { HttpClient } from '@angular/common/http'; import { OidcSecurityService } from 'angular-auth-oidc-client'; +import jwt_decode from 'jwt-decode'; export interface UserRegistrationStateModel { isAuthorized: boolean; - userName:string; - role:string; + userName: string; + role: string; } @State({ name: 'user', defaults: { isAuthorized: false, - userName:'', + userName: '', role: '' - + } }) @Injectable() @@ -52,20 +53,20 @@ export class UserRegistrationState { this.oidcSecurityService .checkAuth() .subscribe((auth) => { - console.log('is authenticated', auth) + console.log('is authenticated', auth); patchState({ isAuthorized: auth}); if (auth) { patchState({role: jwt_decode(this.oidcSecurityService.getToken())['role']}); patchState({userName: jwt_decode(this.oidcSecurityService.getToken())['name']}); } - }) + }); } @Action(AuthFail) AuthFail(): void { - console.log("Authorization failed"); + console.log('Authorization failed'); } } -function jwt_decode(arg0: string) { - throw new Error('Function not implemented.'); -} +// function jwt_decode(arg0: string): any { +// throw new Error('Function not implemented.'); +// } diff --git a/src/app/shell/provider/provider-config/provider-config.component.ts b/src/app/shell/provider/provider-config/provider-config.component.ts index 61844b87d0..681afcc961 100644 --- a/src/app/shell/provider/provider-config/provider-config.component.ts +++ b/src/app/shell/provider/provider-config/provider-config.component.ts @@ -35,8 +35,55 @@ export class ProviderConfigComponent implements OnInit { } ngOnInit(): void { - // this.http.post('http://localhost:5000/Organization/CreateOrganization', this.data) - // .subscribe(value => console.log(value)); + this.http.post('http://localhost:5000/Provider/Create', { + "id": 0, + "title": "string", + "shortTitle": "string", + "website": "string", + "facebook": "string", + "instagram": "string", + "description": "string", + "mfo": "string", + "edrpou": "string", + "koatuu": "string", + "inpp": "string", + "director": "string", + "directorPosition": "string", + "authorityHolder": "string", + "directorBirthDay": "2021-03-11", + "directorPhonenumber": "string", + "managerialBody": "string", + "ownership": 0, + "type": 0, + "form": "string", + "profile": 0, + "index": "string", + "isSubmitPZ1": true, + "attachedDocuments": "string", + "addressId": 0, + "userId": "string", + "user": { + "id": "string", + "userName": "string", + "normalizedUserName": "string", + "email": "string", + "normalizedEmail": "string", + "emailConfirmed": true, + "passwordHash": "string", + "securityStamp": "string", + "concurrencyStamp": "string", + "phoneNumber": "string", + "phoneNumberConfirmed": true, + "twoFactorEnabled": true, + "lockoutEnd": "2021-03-11T10:48:01.648Z", + "lockoutEnabled": true, + "accessFailedCount": 0, + "creatingTime": "2021-03-11T10:48:01.648Z", + "lastLogin": "2021-03-11T10:48:01.648Z" + } + }) + .subscribe(value => console.log(value)); + this.http.get('http://localhost:5000/Provider/GetProviders').subscribe(value => console.log(value)); } onSubmit(): void {