B4J Question [ABMaterial] what approach for users and admin ?

giannimaione

Well-Known Member
Licensed User
Longtime User
Hi ,
we want create a different menu (page.NavigationBar). One for administrator and one for all user. there is no problem.
But which pages to check to allow authorized access ?
 

alwaysbusy

Expert
Licensed User
Longtime User
Basically, when one logins, we add an attribute to the session:

B4X:
page.ws.session.SetAttribute("authType", "admin")
'or
page.ws.session.SetAttribute("authType", "user")

When entering a page, we check if the page is allowed for this type user in WebSocket_Connected():
B4X:
If session.GetAttribute2("authType", "") <> "admin" Then
     ' not allowed, so back to the root of the app
     ABMShared.NavigateToPage(ws, ABMPageId, "../",False)
     Return
End If
 
Upvote 0

giannimaione

Well-Known Member
Licensed User
Longtime User
very easy, thank you
 
Upvote 0

giannimaione

Well-Known Member
Licensed User
Longtime User
the same question!
@alwaysbusy your response is easy, but it's possible create two MENU ("admin" and "user") into ABMShared
Menu admin :
Manage DB
Backup DB
Setup
......
....

Menu user:
About
your info
insert message
bla, bla, bla
....
.......
.-.-.-.-.-.-.-
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
For each page, you are building and connecting the navigation bar....

So in ConnectNavigationBar, create what you want depending on user type.
You may also put these items in a DB table - and load them accordingly.


B4X:
Sub ConnectNavigationBar(page As ABMPage, usertype as String)  ' added this usertype param - determined at the page level - optional!
    ' Clear the dummies we created in BuildNavigationBar
    page.NavigationBar.Clear

if usertype = 'admin' then
    page.NavigationBar.AddSideBarItem( "About",   "About / Help", "mdi-action-dashboard",  "../AboutPage")
    page.NavigationBar.AddSideBarDivider '("")
    page.NavigationBar.AddSideBarItem( "Reports",   "System Reports", "mdi-file-folder-open",  "../reportsPage")
else
   ' do something else '
end if

' OR

Select usertype

    case admin
' build admin menu' 
    case user
' build user menu'
    case public
' build public non-user menu - very limited options '

end case
 
Last edited:
Upvote 0

giannimaione

Well-Known Member
Licensed User
Longtime User
For each page, you are building and connecting the navigation bar....

So in ConnectNavigationBar, create what you want depending on user type.
You may also put these items in a DB table - and load them accordingly.
ok it's fine for me
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…