-
Notifications
You must be signed in to change notification settings - Fork 1
B3.02 Security: Authorization (AdminUsers and AdminRoles Features) (Xamarin)
chempkovsky edited this page Aug 3, 2021
·
7 revisions
Instead of adding all security components into Navbar we define a pair of Features with security components as a child.
- Create
asp\AdminRoles\Views
-subfolder underFeatureServicesPrismModule
-project - Create
asp\AdminRoles\ViewModels
-subfolder underFeatureServicesPrismModule
-project - Right click
asp\AdminRoles\Views
-folder - Open FeatureScripts Wizard
- On the first page click "Next"-button
- On the second page
- select aspnetchckdbcontext-DBcontext
- click Next-button
- On the third page
- click Add-button
- Feature-dialog will be shown
- In Feature-dialog
- Type AdminUsers
- check
- aspnetdashboardView (01598-LformUserControl.xaml)
- aspnetmodelView (01598-LformUserControl.xaml)
- aspnetroleView (01598-LformUserControl.xaml)
- aspnetroleView (02122-O2mMaskUserControl.xaml)
- aspnetrolemaskView (01598-LformUserControl.xaml)
- click Save button
- You are On the third page again
- click Next-button
- On the fourth page
- Select "30100-FtrUserControl.xaml.cs"
- Click Next-button
- On the fifth page
- Select "FtrUserControl.Xamarin.xaml.cs.t4"
- Click "Next"-button
- On the sixth page
- Click "Save"-button
- Click "Next"-button
- You are On the third page again
- click Next-button
- On the fourth page
- Select "30102-FtrUserControl.xaml"
- Click Next-button
- On the fifth page
- Select "FtrUserControl.Xamarin.xaml.t4"
- Click "Next"-button
- On the sixth page
- Click "Save"-button
- close the dialog
- Right click
asp\AdminRoles\ViewModels
-folder - Open FeatureScripts Wizard
- On the first page click "Next"-button
- On the third page
- select "AdminRoles"
- click Next-button
- On the fourth page
- Select "30104-FtrViewModel.cs"
- Click Next-button
- On the fifth page
- Select "FtrViewModel.Xamarin.cs.t4"
- Click "Next"-button
-
On the sixth page
- Click "Save"-button
- Click "Next"-button
-
You are On the third page again
- click Next-button
- On the fourth page
- Select "30104-FtrViewModel.PrismModuleModifier.txt"
- Click Next-button
- On the fifth page
- Select "30104-FtrViewModel.PrismModuleModifier.txt.t4"
- Click "Next"-button
- On the sixth page
- Click "Save"-button
- close the dialog
open "AdminRolesFtrViewModel.cs"-file and DO NOT follow the instructions
- Under FeatureServicesPrismModule-project the RegisterTypes()-method of the FeatureServicesPrismModuleModule.cs becomes as follows
public void RegisterTypes(IContainerRegistry containerRegistry)
{
...
Prism.Mvvm.ViewModelLocationProvider.Register<FeatureServicesPrismModule.asp.AdminRoles.Views.AdminRolesFtrUserControl, FeatureServicesPrismModule.asp.AdminRoles.ViewModels.AdminRolesFtrViewModel>();
containerRegistry.RegisterForNavigation<FeatureServicesPrismModule.asp.AdminRoles.Views.AdminRolesFtrUserControl, FeatureServicesPrismModule.asp.AdminRoles.ViewModels.AdminRolesFtrViewModel>("AdminRolesFtrUserControl");
}
We need only the name "AdminRolesFtrUserControl"
- Open "Views\MainFlyoutPage.xaml"-file of the PrismDemoApp-project
- Modify content of StackLayout as shown:
...
<Label Text="Admin"/>
<Button BackgroundColor="Transparent" Text="Admin Roles" Command="{Binding NavigateCommand}" CommandParameter="AdminRolesFtrUserControl" />
- run Dm04WebApp-app
- run PrismDemoApp-app
- click "Admin Roles"-navigation menu
- here is a result
- Create
asp\AdminUsers\Views
-subfolder underFeatureServicesPrismModule
-project - Create
asp\AdminUsers\ViewModels
-subfolder underFeatureServicesPrismModule
-project - Repeat the steps described above to create AdminUsers Feature
- Include in the list of the AdminUsers Feature:
- aspnetroleView (01598-LformUserControl.xaml)
- aspnetuserView (01598-LformUserControl.xaml)
- aspnetuserView (02122-O2mMaskUserControl.xaml)
- aspnetuserView (01698-O2mUserControl.xaml)
- aspnetuserrolesView (01598-LformUserControl.xaml)
open "AdminUsersFtrViewModel.cs"-file and DO NOT follow the instructions
- Under FeatureServicesPrismModule-project the RegisterTypes()-method of the FeatureServicesPrismModuleModule.cs becomes as follows
public void RegisterTypes(IContainerRegistry containerRegistry)
{
...
Prism.Mvvm.ViewModelLocationProvider.Register<FeatureServicesPrismModule.asp.AdminUsers.Views.AdminUsersFtrUserControl, FeatureServicesPrismModule.asp.AdminUsers.ViewModels.AdminUsersFtrViewModel>();
containerRegistry.RegisterForNavigation<FeatureServicesPrismModule.asp.AdminUsers.Views.AdminUsersFtrUserControl, FeatureServicesPrismModule.asp.AdminUsers.ViewModels.AdminUsersFtrViewModel>("AdminUsersFtrUserControl");
}
We need only the name "AdminUsersFtrUserControl"
- Open "Views\MainFlyoutPage.xaml"-file of the PrismDemoApp-project
- Modify content of StackLayout as shown:
...
<Label Text="Admin"/>
<Button BackgroundColor="Transparent" Text="Admin Roles" Command="{Binding NavigateCommand}" CommandParameter="AdminRolesFtrUserControl" />
<Button BackgroundColor="Transparent" Text="Admin Users" Command="{Binding NavigateCommand}" CommandParameter="AdminUsersFtrUserControl" />
- run Dm04WebApp-app
- run PrismDemoApp-app
- click "Admin Users"-navigation menu
- here is a result
- in db
- in db
With "aspnetuserView (02122-O2mMaskUserControl.xaml)" you can view permission mask for the given user.
- Note: you can not change permission mask with current component. This component is useful if more than one role has been assigned to a given user.
- in db
- in db
Please take a look at the code of "aspnetuserrolesViewWebApiController.cs"-file
[HttpGet]
[Route("getwithfilter")]
[ResponseType(typeof(aspnetuserrolesViewPage))]
public IHttpActionResult getwithfilter([FromUri] System.String[] userId
, [FromUri] string[] userIdOprtr
, [FromUri] System.String[] roleId
, [FromUri] string[] roleIdOprtr
, [FromUri] System.String[] uUserName
, [FromUri] string[] uUserNameOprtr
, [FromUri] System.String[] rName
, [FromUri] string[] rNameOprtr
, [FromUri] string[] orderby = null, [FromUri] int? page =null, [FromUri] int? pagesize = null)
{
string[] EqualOperators = { "eq", "lk" };
string[] ExpectedOperators = { "eq", "lk", "gt", "lt", "ne" };
int currentPageSize = this.defaultPageSize;
int currentPage = 1;
if (pagesize.HasValue) {
currentPageSize = pagesize.Value;
if ((currentPageSize < this.minPageSize) || (currentPageSize > this.maxPageSize)) {
currentPageSize = defaultPageSize;
}
}
if (page.HasValue) {
currentPage = page.Value+1;
if (currentPage < 1) {
currentPage = 1;
}
}
bool hasNo = true;
System.String UserId = null;
if(userId != null) {
if(userId.Length > 0) {
int filterCnt = userId.Length;
for(int i = 0; i < filterCnt; i++) {
if( string.IsNullOrEmpty(userId[i]) ) continue;
UserId = userId[i];
hasNo = false;
break;
}
}
}
aspnetuserrolesViewPage resultObject = new aspnetuserrolesViewPage() {
page = (currentPage > 0) ? (currentPage-1) : currentPage,
pagesize = currentPageSize,
pagecount = 0,
total = 0,
items = new List<aspnetuserrolesView>()
};
if (hasNo) {
return Ok(resultObject);
}
ApplicationUser usr = UserManager.Users.Where(u => u.Id == UserId).FirstOrDefault();
if(usr == null) {
return Ok(resultObject);
}
...
"aspnetuserrolesView (01598-LformUserControl.xaml)"-component can be used as detail part of O2m-control. So remove it from the "AdminUsersFtrUserControl".