Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed errors in user state #96

Merged
merged 1 commit into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/app/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -23,34 +23,35 @@ export class HeaderComponent implements OnInit {

user = {
firstName: 'Іванов В. М'
}
showModalReg: boolean = false;
};
showModalReg = false;

@Select(UserRegistrationState.isAuthorized)
isAuthorized$: Observable<boolean>;
@Select(UserRegistrationState.userName)
userName$: Observable<boolean>;

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 => {
this.snackBar.open('Check your connection', 'Try again!', {
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());
}
}
21 changes: 11 additions & 10 deletions src/app/shared/store/user-registration.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserRegistrationStateModel>({
name: 'user',
defaults: {
isAuthorized: false,
userName:'',
userName: '',
role: ''

}
})
@Injectable()
Expand Down Expand Up @@ -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.');
// }

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down