Advertisement:

Author Topic: Login website returns to Admin page => FIX  (Read 3801 times)

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Login website returns to Admin page => FIX
« on: September 06, 2015, 08:42:58 pm »
Hi there,

the topic is not new but since I ran into the 'issue' too many times myself I think I now have a fix that works! :)
(So far I have not experienced the issue again)

The issue; after having done some work in Admin, logging out, press back to my-web-site and trying to login as a regular user I get redirected to my Admin login page. Very annoying!

The fix; Open the core file: oc-includes/osclass/controller/login.php using your favorite text editor (Notepad++ or similar preferably)
Find the function called: "doModel" and follow the code down until you get to the code "default:" and replace the code with this code:
Code: [Select]
                default:                //login
if(strpos(osc_get_http_referer(),'oc-admin')) {
Session::newInstance()->_setReferer(osc_base_url());
} else {
Session::newInstance()->_setReferer(osc_get_http_referer());
}
                                        if( osc_logged_user_id() != '' ) {
                                            $this->redirectTo(osc_user_dashboard_url());
                                        }
                                        $this->doView( 'user-login.php' );


Regards,
Eric
« Last Edit: September 06, 2015, 08:45:30 pm by SmaRTeY »

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: Login website returns to Admin page => FIX
« Reply #1 on: September 07, 2015, 12:58:58 am »
Hi SmaRTeY,

Unfortunately, the above code did not make any difference in my case :-(

This is a very old issue reported long time ago and Conejo could not reproduce it. However,  I always had something else to do, and so never got into this myself. From what I've noticed, it can be reproduced only with themes that have a quick login box, but if you visit a regular login page @frontend you will never have a problem (and I assume that's why Conejo couldn't see it) update: nope, it can be reproduced even with Bender theme. One thing I don't particularly like above is a hard-coded admin url.

The referer is not important at all (you could entirely remove that line and the problem will be still there). The only line that does make a difference is a user dash redirect.

Regards
« Last Edit: September 07, 2015, 01:32:31 am by dev101 »

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: Login website returns to Admin page => FIX
« Reply #2 on: September 07, 2015, 01:28:56 am »
I have created new issue about this, so maybe this time it will be resolved:
https://github.com/osclass/Osclass/issues/1913

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Login website returns to Admin page => FIX
« Reply #3 on: September 07, 2015, 01:31:29 am »
Hi dev101,

Maybe coincidence but since this change I have not seen the issue re-occurring.
I will undo my changes and see what happens.

If I experience the issue again I am pretty sure this change does the trick for me.
I'm using Boxer theme and the regular login-page, not a quick login box and I was definitely having the issue.

I wonder why it isn't working for you, what theme are you using? (and did you clear your cache thoroughly before testing?)

Regards,
Eric

Hi SmaRTeY,

Unfortunately, the above code did not make any difference in my case :-(

This is a very old issue reported long time ago and Conejo could not reproduce it. However,  I always had something else to do, and so never got into this myself. From what I've noticed, it can be reproduced only with themes that have a quick login box, but if you visit a regular login page @frontend you will never have a problem (and I assume that's why Conejo couldn't see it). One thing I don't particularly like above is a hard-coded admin url.

The referer is not important at all (you could entirely remove that line and the problem will be still there). The only line that does make a difference is a user dash redirect.

Regards

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: Login website returns to Admin page => FIX
« Reply #4 on: September 07, 2015, 01:34:19 am »
Hi SmaRTeY,

I have updated my original reply moments ago, I can reproduce this even in Bender theme and default setup, will continue to investigate this and report if I find something, so far few tricks did not work, however, it is not my top priority... :(

edit/update:

I wonder why it isn't working for you, what theme are you using? (and did you clear your cache thoroughly before testing?)

Hmm, this could be it. Although I've manually removed cookies, I haven't cleared cache from Chrome, and it is possible it served cached page responses instead (grrr...). I have just checked your code with a fresh start and it worked!

Thanks,
Regards
« Last Edit: September 07, 2015, 01:48:12 am by dev101 »

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Login website returns to Admin page => FIX
« Reply #5 on: September 07, 2015, 01:48:12 am »
EDIT: GREAT! I didn't see your last/edited post but I'm also pretty sure it's fixed 8)

Okay, I just UN-DO'd my changes, cleared my browser cache, closed my browser and re-opened. I went to my website, changed url into oc-admin url in browser and logged into Admin. I surfed around a bit and pressed Log Out. In the page that followed I pressed the link "Back to Spulleboel" and I was redirected to my website front page as expected. I pressed login and got redirected to my login page, I entered my credentials and I IMMEDIATELY got redirected to the Admin Login page......meaning my issue was there again.

I RE-DID my fix again, followed the EXACT same routine and after login I actually get logged in as it should! ;D

For now I have to say my fix works, at least for me, and I am pretty sure if it makes a difference for me it will most likely make a difference for others as well.

What browser you are using?

I have tested now with Edge and I will do the same with Opera v28.0.1750.48 (newer version is not working correct for me with window-scroll script function as is not with Chrome latest version)


Regards,
Eric
« Last Edit: September 07, 2015, 01:50:14 am by SmaRTeY »

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: Login website returns to Admin page => FIX
« Reply #6 on: September 07, 2015, 01:49:13 am »
Hi SmaRTeY, yes it seems to work now once I cleared cache, check my updated reply above.
Chrome has a very aggressive caching mechanism which I don't like sometimes. :-(

Many thanks for this!
Regards

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Login website returns to Admin page => FIX
« Reply #7 on: September 07, 2015, 01:51:22 am »
Haha YW ;D

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Login website returns to Admin page => FIX
« Reply #8 on: September 07, 2015, 01:53:43 am »
If you see a quick fix that replaces the hard-coded 'oc-admin' check in url and doesn't break the fix it would be even better ;)

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: Login website returns to Admin page => FIX
« Reply #9 on: September 07, 2015, 01:57:38 am »
Hmm, just tested this on a 3rd setup with own theme and there it does not work :-(
Cleared cache again and nope, no difference. Will continue to investigate, controller logic is the same.

update: the issue is (again) with quick login, works OK from login page.

You can get oc-admin with subtraction between osc_admin_base_url and osc_base_url ;)
« Last Edit: September 07, 2015, 03:15:43 am by dev101 »

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Login website returns to Admin page => FIX
« Reply #10 on: September 07, 2015, 03:01:04 am »
Ok, using 'quick' login box works different, what theme can I use to test this?

(Interesting to see issue with quick login box vs. regular working login page)

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: Login website returns to Admin page => FIX
« Reply #11 on: September 07, 2015, 03:15:09 am »
Modern

Even manual referer reset doesn't do the trick in that case.
« Last Edit: September 07, 2015, 03:16:45 am by dev101 »

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Login website returns to Admin page => FIX
« Reply #12 on: September 07, 2015, 03:32:56 am »
I tested with Modern, quick login does not work because of the 'action' it passes in this case so it does not pass the 'default' action we changed.

Fix for this:
In same file 'login.php' around line 99 you see this code: $url_redirect = osc_get_http_referer();

Replace that line of code with this code:
Code: [Select]
if(strpos(osc_get_http_referer(),'oc-admin')) {
$url_redirect = osc_base_url();
} else {
$url_redirect = osc_get_http_referer();
}

Worked for me, let me know if it works for you as well....


Regards,
Eric

dev101

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2155
  • osclass.work
Re: Login website returns to Admin page => FIX
« Reply #13 on: September 07, 2015, 04:25:14 am »
Hi SmaRTeY, it is exactly the same form, they all pass login_post:

Code: [Select]
                        <form id="login" action="<?php echo osc_base_url(true); ?>" method="post">
                            <fieldset>
                                <input type="hidden" name="page" value="login" />
                                <input type="hidden" name="action" value="login_post" />

Code: [Select]
                <form action="<?php echo osc_base_url(true); ?>" method="post" >
                    <input type="hidden" name="page" value="login" />
                    <input type="hidden" name="action" value="login_post" />

The only difference is present id because of js (irrelevant). This is a bit strange.

But, nice catch anyway, you are right, that spot also needed an update and now it works correctly.

Again, many thanks for this - it should be updated in the core for sure.

Regards,
dev101

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Login website returns to Admin page => FIX
« Reply #14 on: September 07, 2015, 11:40:09 am »
Quote
Hi SmaRTeY, it is exactly the same form, they all pass login_post:

Ahum, missed that to be honest and thought it was why the quick login wasn't working :)