This discussion is archived
9 Replies Latest reply: Feb 14, 2013 9:23 AM by TexasApexDeveloper RSS

Redirect the users to different pages based on users role once they login

orton607 Newbie
Currently Being Moderated
Hello,

Can anyone please help me with this problem.

I have a application and I wanted to redirect users based on their role. For authentication I am using the in-built application express login credentials and for authorization I have a users table with two fields userid and role. The two roles will be ADMIN and ANALYST.

If an user with ADMIN role login's to the application, he/she should be redirected to Home by default - page 1;

if an user with ANALYST role login's to the application, he/she should be redirected to page 2.

I am using oracle APEX version 4.0.2 and Oracle 10g R2 database.

Any help is appreciated.

Thanks,
Orton
  • 1. Re: Redirect the users to different pages based on users role once they login
    714270 Pro
    Currently Being Moderated
    orton607 wrote:
    Hello,

    Can anyone please help me with this problem.

    I have a application and I wanted to redirect users based on their role. For authentication I am using the in-built application express login credentials and for authorization I have a users table with two fields userid and role. The two roles will be ADMIN and ANALYST.

    If an user with ADMIN role login's to the application, he/she should be redirected to Home by default - page 1;

    if an user with ANALYST role login's to the application, he/she should be redirected to page 2.

    I am using oracle APEX version 4.0.2 and Oracle 10g R2 database.

    Any help is appreciated.

    Thanks,
    Orton
    In page 1, you can create a conditional "On-load Before Header" branch to page 2. You can either use a valid condition type from the "Conditions" region on the edit branch page. Or, you can set the "ANALYST" Authorization Scheme on the branch (if you have defined the authorization schemes for the different roles, under shared components of your application).
  • 2. Re: Redirect the users to different pages based on users role once they login
    orton607 Newbie
    Currently Being Moderated
    Thanks Rohit for replying.

    I have tried your option but no luck. I have the authorization schemes for each of the roles.
    For ADMIN Role - Scheme type: Exists Sql Query and Expression1: select 1 from users where USER_ID = UPPER(:APP_USER) and user_role IN ('ADMIN')
    
    For ANALYST Role - Scheme type: Exists Sql Query and Expression1: select 1 from users where USER_ID = UPPER(:APP_USER) and user_role IN ('ANALYST')
    Finally I have created a branch on page 1 on load before header to redirect to page 2 and set the authorization to ANALYST.

    The thing is once I login to the application, its always redirecting to page 2 even if I logged in as ADMIN or as an ANALYST.

    Please help.

    Thanks,
    Orton
  • 3. Re: Redirect the users to different pages based on users role once they login
    TexasApexDeveloper Guru
    Currently Being Moderated
    Why not use the built in roles that can be associated with an apex user? when you call wwv_flow_custom_auth_std.login on the login page, the last item is the page to redirect to, so you could build code around the call to wwv_flow_custom_auth_std.login, like this (pseudo code) :
    Get user role in local variable y
    
    if y = 'ADMIN' set a local variable x to 1
    else set local variable x to 2.
    
    wwv_flow_custom_auth_std.login(
        P_UNAME       => :P101_USERNAME,
        P_PASSWORD    => :P101_PASSWORD,
        P_SESSION_ID  => v('APP_SESSION'),
        P_FLOW_PAGE   => :APP_ID||':'||x
        );
    Thank you,

    Tony Miller
    Ruckersville, VA
  • 4. Re: Redirect the users to different pages based on users role once they login
    orton607 Newbie
    Currently Being Moderated
    Hello Tony,

    I have tried your option but no luck. Like I have changed the process code on the login page 101 to below and its not working. Even if I login as ADMIN or ANALYST; it is always redirecting to page 1.
    DECLARE
       v_role   VARCHAR2 (30);
       v_page   NUMBER;
    BEGIN
       SELECT user_role
         INTO v_role
         FROM users
        WHERE USER_ID = UPPER (TRIM(:P101_USERNAME));
    
       IF v_role = 'ADMIN'
       THEN
          v_page := 1;
       ELSE
          v_page := 2;
       END IF;
       wwv_flow_custom_auth_std.login (P_UNAME        => :P101_USERNAME,
                                       P_PASSWORD     => :P101_PASSWORD,
                                       P_SESSION_ID   => v ('APP_SESSION'),
                                       P_FLOW_PAGE    => :APP_ID || ':' || v_page);
    END;
    Please help.

    Thanks,
    Orton
  • 5. Re: Redirect the users to different pages based on users role once they login
    TexasApexDeveloper Guru
    Currently Being Moderated
    Add

    apex_util.set_session_state(p_name => 'FSP_AFTER_LOGIN_URL'
    ,p_value => null
    );



    to the top of your login process before the call to wwv_flow_custom_auth_std.login

    APEX 4.1.1 modified the login process...

    Thank you,

    Tony Miller
    Ruckersville, VA
  • 6. Re: Redirect the users to different pages based on users role once they login
    orton607 Newbie
    Currently Being Moderated
    It works now.

    Thanks Tony for all your help, really appreciate it.

    Thanks,
    Orton
  • 7. Re: Redirect the users to different pages based on users role once they login
    orton607 Newbie
    Currently Being Moderated
    Hello,

    Can anyone please help with this problem. I am using Oracle Application express authentication and redirecting the users to different page based on their roles; once they login. This is working fine. The problem I have is even if the user is not a valid user; he is able to login to application with no data found message. Below is the login process which I am using.

    If the user is not a valid user then it should display a message Invalid Login credentials. The process which I have is over riding this step. Please help. Any help is appreciated.

    --my login process on pg 101
    DECLARE
       v_role   VARCHAR2 (30);
       v_page   NUMBER;
    BEGIN
       SELECT user_role
         INTO v_role
         FROM users
        WHERE USER_ID = UPPER (TRIM (:P101_USERNAME));
    
       IF v_role = 'ADMIN'
       THEN
          v_page := 1;
       ELSIF v_role = 'USER'
       THEN
          v_page := 32;
       ELSE
          v_page := 200;
       END IF;
    
       APEX_UTIL.
        set_session_state (p_name => 'FSP_AFTER_LOGIN_URL', p_value => NULL);
       wwv_flow_custom_auth_std.login (P_UNAME        => :P101_USERNAME,
                                       P_PASSWORD     => :P101_PASSWORD,
                                       P_SESSION_ID   => v ('APP_SESSION'),
                                       P_FLOW_PAGE    => :APP_ID || ':' || v_page);
    END;
    Thanks,
    Orton
  • 8. Re: Redirect the users to different pages based on users role once they login
    orton607 Newbie
    Currently Being Moderated
    Hello,

    Can anyone please help me out with this issue.

    Thanks,
    Orton
  • 9. Re: Redirect the users to different pages based on users role once they login
    TexasApexDeveloper Guru
    Currently Being Moderated
    Instead of ADDING items to a closed thread, PLEASE start a new thread and refer back to this old thread if you need to...

    Thank you,

    Tony Miller
    Ruckersville, VA

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points