0
votes

I want to create a custom login form with several conditions.

Here is the scenario: When users log in to the app, PowerApps only show the screen based on their position. for example:

  • Mr. ABC as a Staff,
  • Mrs. DEF as a Supervisor,
  • then when Mr. ABC logs in, he just gets a Staff screen
  • and when Mrs. DEF logs in, she can access to Staff and Supervisor screen

I already create a table on Data Source with Name, Email, Password and Position column. On Canvas App:

  • I set TextInput1 (Email)
  • TextInput2 (Password)
  • and button1 (Login)

On button1: I set a function on OnSelect event

If(LookUp('MyDataSource', Email = TextInput1.Text, Password)=TextInput2.Text, Nagivate(StaffScreen,None))

This action is just only taken users to Staff Screen.

How to solve this problem?

2
Currently it looks like you have no condition to navigate to a staff and supervisor screen.LafaMan

2 Answers

0
votes

A Suggestion: You can setup/create different groups for each category of users in Azure AD and use AD connector to valid each user and navigate them to appropriate screens.

0
votes

I would avoid managing a table of passwords, etc. This adds unnecessary complexity. Users already have to use their Active Directory credentials to log into PowerApps. Leverage Active Directory attributes or Microsoft Office properties.

One way is to key off of the JobTitle listed in Microsoft Office, you can accomplish this with the Office365Users Connector in PowerApps.

OnStart:

Set(varJobTitle, 
    First(
        Office365Users.SearchUserV2(
            {
                searchTerm:User().Email
            }
        ).value.JobTitle
    ).JobTitle
)

OnSelect of a "Login" button on the first screen:

If(
    varJobTitle = "Staff",
    Set(varUserType, "user");
    Navigate(scrStaff, Fade),
    varJobTitle = "Supervisor",
    Set(varUserType, "admin");
    Navigate(scrSupervisors, Fade)
    <etc.>
)

You could adapt this to groups of JobTitles as well with something like:

If(
    Or(
        varJobTitle = "Staff",
        varJobTitle = "Helper",
        varJobTitle = "Deckhand"
    ),
    Set(varUserType, "user");
    Navigate(scrStaff, Fade),
    Or(
        varJobTitle = "Supervisor",
        varJobTitle = "Manager",
        varJobTitle = "Director"
    ),
    Set(varUserType, "admin");
    Navigate(scrSupervisors, Fade)
    <etc.>
)

  • Then on scrSupervisors, add a button that navigates admins to scrStaff.
  • Then on scrStaff add a button with Visible property set to If(varUserType = "admin", true, false) which navigates admins to scrSupervisors.

Many ways to accomplish what you're aiming for. Adapt accordingly.