108 Security: User management. Typescript classes. - chempkovsky/CS82ANGULAR GitHub Wiki
Security has two aspects: Authentication and Authorization
- Before this article, we used to generate typescript classes with
PhbkDbContext-Dbcontext as a Wizard's Repo. - In the article 012.1 we generated Auxiliary classes. All information about created object was persisted in a Wizard's Repo of
PhbkDbContext - Now,
aspnetchckdbcontextwill be used to generate the Typescript code. But theaspnetchckdbcontextRepo does not contain information about the common classes that have already been created in the project. - Thus, our very first task is to import common classes info from
PhbkDbContext-Repo inaspnetchckdbcontext-Repo.- There is a
import common staff-button on one of the page of JavaScript Wizard. But we do not recommend to use this functionality (it's under the development). - Instead, we will show how to copy/paste json fragment from
PhbkDbContext-Repo inaspnetchckdbcontext-Repo.
- There is a
- run Visual studio 2022
- open the
PhBkContext.PhBkContext.csproj.PhBkContext.Auth.aspnetchckdbcontext.json-file, which is a Repo foraspnetchckdbcontext - open the
PhBkContext.PhBkContext.csproj.PhBkContext.PhBk.PhbkDbContext.json-file, which is a Repo forPhbkDbContext - Note: you will find both files in the Solution folder.
- Format both files
- right click editor window and select
Format document-menu item
- right click editor window and select
Click to show the picture

- Select
CommonStaffs-section ofPhBkContext.PhBkContext.csproj.PhBkContext.PhBk.PhbkDbContext.json-file and copy into the clipboard.
Click to show the picture

- Replace
"CommonStaffs": null-line ofPhBkContext.PhBkContext.csproj.PhBkContext.PhBk.PhbkDbContext.json-file with the clipboard selection.
Click to show the picture

- save
PhBkContext.PhBkContext.csproj.PhBkContext.Auth.aspnetchckdbcontext.json-file - close both files
- right click
src/app-folder of the Angular project and selectJavascript Wizard-menu item - on the first page click
next-button - on the second page
- select
PhBkContext.csproj-project - select
aspnetchckdbcontext-Dbcontext - click
next-button
- select
- on the third page
- select
aspnetmodelViewin the combo - click
next-button
- select
- on the fourth page
- click
batch processing-button-
Batch actionsdialog will be shown
-
- click
- on Batch actions dialog run the scripts:
02040-AspNetAllInterfacesBatch.json02041-AspNetAllWebApiServicesBatch.json02042-AspNetAllSFormsBatch.json02043-AspNetAllVformsBatch.json02044-AspNetAllAformsBatch.json02044-AspNetAllUformsBatch.json02044-AspNetAllDformsBatch.json02047-AspNetAllRvBatch.json02048-AspNetAllRaBatch.json02049-AspNetAllRuBatch.json02050-AspNetAllRdBatch.json02051-AspNetAllRlBatch.json02052-AspNetAllRdlBatch.json
- After you finish
- open the
src\app\components\aspnetuser-view\aspnetuser-view-rdl.routing.module.ts-file- the
children-array is empty!!! - here is a fragment
- the
- open the
...
const routes: Routes = [
{
path: '',
component: AspnetuserViewRdlistComponent,
canActivate: [AppGlblSettingsServiceActivator],
children: [
//
// Info: Root Master View [aspnetuserView]
// Info: Detail View [aspnetuserrolesView]
//
//
//warning: for the View [aspnetuserrolesView] the component [02050-Rdl-lazy.routing.module.ts] has not been generated yet
//
//
// Info: Root Master View [aspnetuserView]
// Info: Detail View [aspnetusermaskView]
//
//
//warning: for the View [aspnetusermaskView] the component [02050-Rdl-lazy.routing.module.ts] has not been generated yet
//
]
}
];
...- to fix this issue, run the following batch-scripts second time:
02042-AspNetAllSFormsBatch.json02043-AspNetAllVformsBatch.json02047-AspNetAllRvBatch.json02051-AspNetAllRlBatch.json02052-AspNetAllRdlBatch.json
-
Navigation paths
-
in the article 106 we generated Webapi services.
- Webapi service generated for
aspnetroleViewusesRoleManager<IdentityRole>-class functionality-
RoleManagercan not return users for the given Role.
-
- Webapi service generated for
aspnetuserViewusesUserManager<IdentityUser>-class functionality-
UserManagercan return roles for the given user
-
- Webapi service generated for
-
in the article 107 we regenerated entities and Dbcontext for production.
- The List of Entities consists of only two objects:
-
aspnetmodelto persist all Views in the project -
aspnetrolemaskto persist triples (View, Role, Permission Bitmask)
-
- The List of Entities consists of only two objects:
-
As a result
- Webapi service generated for
aspnetusermaskViewreturns read only data. - Webapi service generated for
aspnetuserpermsViewreturns read only data. - The Rlform(Rflform) for
aspnetuserrolesViewcan be used only as detail panel foraspnetuserView-master Rlform(Rflform)
- Webapi service generated for
-
Navigation paths which make sense
-
aspnetuserView-aspnetroleView-aspnetrolemask -
aspnetuserView-aspnetusermaskView -
aspnetroleView-aspnetrolemask -
aspnetmodelView-aspnetrolemask
-
-
-
RlandRdlnavigation forms:- For our demo app we will generate
RoutesforRlandRdlnavigation forms- Real app require only one type of forms (
RdlorRl) -
Rdlforms implement Add/Update/Delete/View item as popup dialogs -
Rlforms implement Add/Update/Delete/View item as a separate navigation forms.
- Real app require only one type of forms (
- For our demo app we will generate
- right click
src/app-folder of the Angular project and selectJavascript Wizard-menu item - on the first page click
next-button - on the second page
- select
PhBkContext.csproj-project - select
aspnetchckdbcontext-Dbcontext - click
next-button
- select
- on the third page
- select
aspnetmodelViewin the combo - click
next-button
- select
- on the fourth page
- select
01980-R-lazy.routes.ts - click
next-button
- select
- on the fifth page
- select
r-lazy.routes.ts.t4 - click
next-button
- select
- copy generated code in the
app-routing.module.ts-file - copy the following html in the
app.component.html-file
<a mat-list-item [routerLink]="['aspnetmodelView']" routerLinkActive="active">List of aspnetmodels</a>- on the fourth page
- select
02060-Rdl-lazy.routes.ts - click
next-button
- select
- on the fifth page
- select
rdl-lazy.routes.ts.t4 - click
next-button
- select
- copy generated code in the
app-routing.module.ts-file - copy the following html in the
app.component.html-file
<a mat-list-item [routerLink]="['RDLaspnetmodelView']" routerLinkActive="active">List of aspnetmodels (Dlg)</a>repeat the steps similar to those described for aspnetmodelView
repeat the steps similar to those described for aspnetmodelView
- We do not need generate Routes and menu items for the rest of the Views.
-
aspnetrolemaskViewis returned only for one selected role -
aspnetusermaskViewis returned only for one selected user- It is a dynamically generated data. It collects Roles assigned to the given User.
- Having the Roles along with Role Permission Masks it defines permission Masks for the given user.
-
aspnetuserpermsViewis returned only for one selected user.- It is a helper structure that is sent to the client after the user has logged in
-
aspnetuserrolesViewis returned only for one selected user. It does not return for one selected Role.
-