Advertisement:

Author Topic: [Fix] Login (when permalinks = on)  (Read 2972 times)

code monkey

  • Full Member
  • ***
  • Posts: 204
[Fix] Login (when permalinks = on)
« on: March 13, 2011, 06:38:00 am »
If "Enable friendly urls" is on (Settings > Permalinks), you may notice that
when you log in, the browser becomes stuck in a redirect loop.

Seems to be because the permalink for login is incorrectly set to: /user/login
But /user.php does not process login requests.

To fix it, without turning permalinks off...

Open: /oc-includes/osclass/helpers/hDefines.php

Find (line 303):
Code: [Select]
    function osc_user_login_url() {
        if ( osc_rewrite_enabled() ) {
            $path = osc_base_url() . 'user/login' ;

Replace with:
Code: [Select]
    function osc_user_login_url() {
        if ( osc_rewrite_enabled() ) {
            $path = osc_base_url() . '?page=login' ;

code monkey

  • Full Member
  • ***
  • Posts: 204
Re: [Fix] Login (when permalinks = on)
« Reply #1 on: March 13, 2011, 06:42:02 am »
Another quick update.

If user is already logged in, visiting /index.php?page=login will still show the login form.
Instead, redirect the user to the account dashboard.

Find (~ line 101):
Code: [Select]
default: //login
$this->doView( 'user-login.php' ) ;
        }

Replace with:
Code: [Select]
default: //login
if (!osc_is_web_user_logged_in())
$this->doView( 'user-login.php' ) ;
else
$this->redirectTo( osc_user_dashboard_url() ) ;
        }

code monkey

  • Full Member
  • ***
  • Posts: 204
Re: [Fix] Login (when permalinks = on)
« Reply #2 on: March 13, 2011, 07:02:41 am »
Another login update.

Open: /login.php

1. The login uses email - not username. We must update the error text message.

Find (~line 63):
Code: [Select]
osc_add_flash_message( _m('The username doesn\'t exist')) ;
Replace with:
Code: [Select]
osc_add_flash_message( _m('No account with that email address')) ;

2. Add login validation. If the email is incorrect format, don't bother checking in the database.

Find (~line 30):
Code: [Select]
           case('login_post'):     //post execution for the login
Replace with:
Code: [Select]
           case('login_post'):     //post execution for the login
if (preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", Params::getParam('email'))) {

Find (~line 58):
Code: [Select]
} else {
osc_add_flash_message( _m('The password is incorrect')) ;
}

Replace with:
Code: [Select]
} else {
$error_login = true;
osc_add_flash_message( _m('The password is incorrect')) ;
}

Find (~line 63):
Code: [Select]
} else {
osc_add_flash_message( _m('No account with that email address')) ;
}

Replace with:
Code: [Select]
} else {
$error_login = true;
osc_add_flash_message( _m('No account with that email address')) ;
}
} else {
$error_login = true;
}

Find (~line 69):
Code: [Select]
$this->redirectTo( osc_user_dashboard_url() ) ;
Replace with:
Code: [Select]
if ($error_login)
$this->redirectTo( osc_user_login_url() ) ;
else
{
osc_add_flash_message( _m('Welcome: ' . $user['s_name'])) ;
$this->redirectTo( osc_user_dashboard_url() ) ;
}
« Last Edit: March 13, 2011, 07:05:03 am by codeMonkey »

davidsl

  • Newbie
  • *
  • Posts: 9
Re: [Fix] Login (when permalinks = on)
« Reply #3 on: March 13, 2011, 02:06:08 pm »
In the replaced code in line 63, we can add a message after second $error_login = true;, when the email address is not a valid email.

Code: [Select]
} else {
$error_login = true;
osc_add_flash_message( _m('No account with that email address')) ;
}
} else {
osc_add_flash_message( _m('Please, insert a valid email address')) ;
$error_login = true;
}

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 4689
Re: [Fix] Login (when permalinks = on)
« Reply #4 on: March 14, 2011, 02:16:30 am »
If "Enable friendly urls" is on (Settings > Permalinks), you may notice that
when you log in, the browser becomes stuck in a redirect loop.

Seems to be because the permalink for login is incorrectly set to: /user/login
But /user.php does not process login requests.

To fix it, without turning permalinks off...

Open: /oc-includes/osclass/helpers/hDefines.php

Find (line 303):
Code: [Select]
    function osc_user_login_url() {
        if ( osc_rewrite_enabled() ) {
            $path = osc_base_url() . 'user/login' ;

Replace with:
Code: [Select]
    function osc_user_login_url() {
        if ( osc_rewrite_enabled() ) {
            $path = osc_base_url() . '?page=login' ;

Hi CodeMonkey,

That will fix it, but unfortunately you will not have permalinks on login url, the solution was another (changing some rewrite rules which were outdated), The solution is already uploadede to the developmente branch on GIT, we'll take a look at the other fix/solutions you offered and include them in the code as soon as posible.

Thanks a lot for the help!