This discussion is archived
1 2 Previous Next 17 Replies Latest reply: Aug 20, 2013 1:41 PM by Greg Jarmiolowski RSS

Problem closing Skillbuilders modal page when using Login page 101

user11878652 Newbie
Currently Being Moderated

Trying to setup website with the Login page opening in a modal window instead of normal Apex window.

 

Have a Global Page (0) which has a Login button defined - that has a dynamic action defined on it

 

Login Clicked

     True

          SkillBuilders Modal Page(2.0.0) [Plug-in]

 

Fire When Event Result is True

 

Dialog Title:  Login

URL Location:  Statically Defined

Static URL:  f?p=&APP_ID.:101:&APP_SESSION.:::1:::

Auto-close On Element Selector:  div#success-message

 

Created a branch page 102 called Close Modal

 

Have tried putting the following javascripts into Page 102 and also without - but cannot get the modal window to close out.

 

Dynamic Action on page 102  Close Modal Window - Event is On Page Load.  No condition set

 

Execute Javascript Code

Fire When Event Result is True

Fire On Page Load - checked

 

 

Code: 

javascript:parent.$(parent.document).apex_modal_page('close');

 

Any ideas which might help ?

 

Thanks - Jonathan

  • 1. Re: Problem closing Skillbuilders modal page when using Login page 101
    user8531750 Newbie
    Currently Being Moderated

    hi Jonathan, We will look at this ASAP.

    Dave Anderson

    SkillBuilders.com

  • 2. Re: Problem closing Skillbuilders modal page when using Login page 101
    user11878652 Newbie
    Currently Being Moderated

    Thanks Dave - bit bemused after following all the tutorials and documents - all seems to work for other pages - but the login page seems to behave very differently.

  • 3. Re: Problem closing Skillbuilders modal page when using Login page 101
    Greg Jarmiolowski Journeyer
    Currently Being Moderated

    Jonathan,

     

    Can you confirm the the modal window is redirecting from 101 to 102?

     

    Greg

  • 4. Re: Problem closing Skillbuilders modal page when using Login page 101
    user11878652 Newbie
    Currently Being Moderated

    Hi Greg - it seems to be - when I click on the login button - it is redirecting to a page which is displaying the whole template for my site in the modal window - so I am assuming it is redirecting to page 102.

     

    Thanks - Jonathan

  • 5. Re: Problem closing Skillbuilders modal page when using Login page 101
    Greg Jarmiolowski Journeyer
    Currently Being Moderated

    Can you put something in Page 102 that will confirm this is indeed the page that is rendered inside your iframe after you login?

     

    I suspect that the login process is redirecting the user (within the modal) to the page that called the modal login page.

     

    Greg

  • 6. Re: Problem closing Skillbuilders modal page when using Login page 101
    user11878652 Newbie
    Currently Being Moderated

    Hmmm- ok I added an region to 102 and add in a color picker item and when I click login it is not showing those items on the page - so it would seem it is not redirecting to page 102 for some reason.

  • 7. Re: Problem closing Skillbuilders modal page when using Login page 101
    user11878652 Newbie
    Currently Being Moderated

    At the moment i am just using the standard apex authentication scheme - is it possible that is preventing it from redirecting to page 102 ?

     

    Tried running it directly from page 101 outside of modal window and get the same behaviour - seems to just display blank page 0 stuff instead of page 102.

  • 8. Re: Problem closing Skillbuilders modal page when using Login page 101
    jrimblas Expert
    Currently Being Moderated

    Jonathan, it's hard to make APEX work with a login inside the modal window.  Even if you get it to close the problem you'll face is that the calling page was not authenticated.  Once you log in you get a new authenticated session id and you want to make your app use it.

    On p102 you'll want to have a javascript redirect similar to this:

     

    <script language="JavaScript" type="text/javascript">
    top.location.href="&FSP_AFTER_LOGIN_URL.";
    </script>
    

     

    FSP_AFTER_LOGIN_URL contains the page that the user intended to go.  Alternatively you can just send the user to a specific page:

     

    <script language="JavaScript" type="text/javascript">
    top.location.href="f?p=&APP_ID.:1:&SESSION.:";
    </script>
    

     

    The top.location will escape the iframe that gets created by the modal window and change the browser flow to the new page.

    Hope this helps. It may not be the behavior you want, but otherwise you have other problems to solve.

     

    Thanks

    -Jorge

    http://rimblas.com/blog/

     

    PS. Greg is right in suspecting you're never going to p102.  The login page will redirect you to the either the entry page in your app or the secure page the user intended to go to. One problem you'll have it that the login in the modal will break the deep linking functionality of APEX. If you don't care about deep linking, great, otherwise you need extra code to keep track of where the user intended to go.

  • 9. Re: Problem closing Skillbuilders modal page when using Login page 101
    Greg Jarmiolowski Journeyer
    Currently Being Moderated

    There may be a workaround but the problem you are having is due to the internal actions of the login process.

     

    Unless you have altered page 101, your login page will have a Login process with a pl/sql block that looks like this:

     

    apex_authentication.login(

        p_username => :P101_USERNAME,

        p_password => :P101_PASSWORD );

     

     

    Here is the 4.2 documentation for this procedure. Note step 5 - this procedure will redirect the user within the modal window.

     

    LOGIN Procedure

    This procedure authenticates the user in the current session.

    Login processing has the following steps:

     

    1.      Run authentication scheme's pre-authentication procedure.
    2.      Run authentication scheme's authentication function to check the user credentials (p_username, p_password), returning true on success.
    3.      If result=true: run post-authentication procedure.
    4.      If result=true: save username in session table.
    5.      If result=true: set redirect url to deep link.
    6.      If result=false: set redirect url to current page, with an error message in the notification_msg parameter.
    7.      Log authentication result.
    8.      Redirect.

     

    I suspect this means they are redirected in the modal window to the same page that is their current page (where they clicked your login button). Therein may be a solution but I think the easiest way to get your desired functionality would be to create a login region and login process on page 0 and hide it until the login link is clicked. This way the current page is posted instead of the page in the iframe.

     

    If you are comfortable with JQuery and/or Javascript you could keep down the current path and add javascript (on page 0) that would listen for the reloading of the modal page (the iframe source) and close it (depending on something in that page or even an ajax call to test if the user has a valid session).

     

    Greg

  • 10. Re: Problem closing Skillbuilders modal page when using Login page 101
    user11878652 Newbie
    Currently Being Moderated

    Would using a custom authentication scheme bypass this problem ?  I am pretty sure this used to work with Apex 4.1.

  • 11. Re: Problem closing Skillbuilders modal page when using Login page 101
    Greg Jarmiolowski Journeyer
    Currently Being Moderated

    I can't say. I have not successfully tried this in any version of Apex (until just now).

     

    Ignore my suggestions regarding page 0 from earlier.

     

    If the user is on a page in your application and they have an invalid session, when they get that valid session in the login page how are you going to pass along that information to the parent/calling page? This just doesn't seem to be only about the authentication scheme.

     

    A simple test I set up right now has me at page 1. I click a button and I get the login page modal. I login and the modal window displays a logged in version of page 1.  But if I manually close that modal window and then refresh page 1 in the main parent window, I am still not logged in. A little further digging and I see it is in part due to the URL and the session id within.

     

    If my URL is http://apex.oracle.com/pls/apex/apex/f?p=18025:1 then this refresh will not work.


    If my URL is http://apex.oracle.com/pls/apex/apex/f?p=18025:1:123456 and 123456 is not a valid session then this refresh will not work.

     

    You'd need to follow Jorge's suggestion to use some javascript like top.location.href="&FSP_AFTER_LOGIN_URL." to set the parent window to use the correct url containing the session id.


    You would have to control when that code is placed on a page. I have a working example now at the above URL that uses a dynamic action on page 0.


    Event = Page Load

    Condition = Page != 101

    Action = Execute Javascript Code

    JS Code =

    if (window.location != window.parent.location)

      parent.location.href="&FSP_AFTER_LOGIN_URL."


    So if I am loading page 101 do nothing. If I am loading another page, check if the parent and iframe are different source locations (indicating this is an iframe because even a non-iframe window will have a value for parent.location) and if so then set the parent page location to that of the iframe. In effect the redirect that happens in the modal is transferred to the parent.


    This will break any other modal page instances you use though. But you could add them to the condition of the dynamic action on page 0 so you have something like "page not in 101, 1020, etc."


    It seems to work but it feels like a hack to me. Perhaps a specific template for the modal window with some version of this javascript would at least keep you from running this script on every page load.


    Greg


  • 12. Re: Problem closing Skillbuilders modal page when using Login page 101
    user11878652 Newbie
    Currently Being Moderated

    Greg, Jorge - many thanks for both your responses - no much of an expert on some of these elements - but will see if I can get your suggestions working - will let you know

     

    Regards - Jonathan

  • 13. Re: Problem closing Skillbuilders modal page when using Login page 101
    Tom Petrus Expert
    Currently Being Moderated

    I'm a bit unsure on how to deal with deeplinks: when a user has a deeplink to a page that requires authentication, how will you deal with this? Apex will simply redirect you to the login page, it will not show the deeplinked page. This means no popup window and simply the default authentication mechanic. Which might be fine, because I'm just not sure how else you can deal with this (or maybe better: should you?). I mean: there simply will be no page to pop anything up from, save from the login page. It makes sense that the secured page is not rendered at all until you have verified credentials and any other thing may be less secure for it. Unless start making the whole app public and put an authorization on components individually but honestly I don't think this is worth the hassle.

     

    Now if you take deeplinks into account and don't handle those then there ain't a lot of redirect issues.

    Say you go to the application and you land on a public page. You click login, and a modal window opens. Since the url for the modal window is a static url and refers to page 101 then you will simply always go to the login page. Take away the &APP_SESSION. from the static url and just open the login in a new session so that it is unaffected by other settings. You want to make sure that after logging in you are always redirected to the page you want and need. Then close the modal page with the javascript and pass back a close value to the parent window.

    javascript:parent.$(parent.document).apex_modal_page('close', {"sessionId":"&APP_SESSION."});

    This session id is the id of the authenticated session, and the goal is to have an authenticated page in the calling window. I wouldn't complicate it by passing along a whole url to anything else: you are on a page, have the login popup, and thus expect to land back on the same page you popped the login up from and not be redirected to somewhere else because of some weird mechanic on the login page.

    By defining a dynamic action which acts on the closing of the modal window (easily done because this is provided by the plugin) you can redirect to the same page by simply reconstructing the link and redirecting in an execute javascript action:

    if(this.data.modalPageCloseValue.sessionId){
       window.location.href = "f?p=&APP_ID.:&APP_PAGE_ID.:" + this.data.modalPageCloseValue.sessionId;
    };
  • 14. Re: Problem closing Skillbuilders modal page when using Login page 101
    user11878652 Newbie
    Currently Being Moderated

    So I have been playing around with this and seemed to have got it to work - but not sure if it is a good way - so if someone more experienced can advise would appreciate it.

     

    What I have done is make page 102 require authentication (ie not public)

     

    I have then changed my login button to redirect to page 102 - instead of 101 - because it requires authentication it goes to page 101 in the modal window first and then correctly displays the contents of page 102 in the modal window.

     

    I then added a dynamic action to page 102 which calls the javascript code which you guys provided:

     

    1. javascript:parent.$(parent.document).apex_modal_page('close', {"sessionId":"&APP_SESSION."});


    This all seems to work - modal opens, login, modal closes - only outstanding part is the parent page does not seem to know about the login session - is there a way to get that back to the parent and refresh - manually reload seems to work - tried adding dynamic action to page 102 but does not seem to refresh parent - it remains showing the Login button instead of a Logout button - but not consistently - or am I going about this all wrong ???

     

    Also a bit concerned that I am opening security hole in the web site by doing this ? Any experience on this front also ?  Thanks for all the assistance - Jonathan

1 2 Previous Next

Legend

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