ollieread / multiauth

Laravel multi auth
441 stars 109 forks source link

Localhost works fine, but on shared hosting Auth fails. #104

Closed ealvizouri closed 9 years ago

ealvizouri commented 9 years ago

Hi!! I'm having trouble with Multiauth for laravel 4.2. I've changed the auth provider to Ollieread\Multiauth\MultiauthServiceProvider. And deleted the reminder provider. My code in app/config/auth.php

<?php
return array(
        'multi' => array(
        'account' => array(
            'driver' => 'eloquent',
            'model' => 'Account'
        ),
        'user' => array(
            'driver' => 'database',
            'table' => 'user'
        ),
        'admin' => array(
            'driver' => 'database',
            'table' => 'admin'
        ),
        'superadmin' => array(
            'driver' => 'database',
            'table' => 'super_admin'
        )
    ),
    'reminder' => array(

        'email' => 'emails.auth.reminder',

        'table' => 'password_reminders',

        'expire' => 60,

    ),
);
?>

In the tables user, admin and super_admin the primary key is auto_increment with name 'id'. This is the code for logging in.

<?php 
class LoginController extends \BaseController
{

    public function showLogin()
    {
        return View::make('login');
    }

    public function doLogin() {
        $rules = array(
            'email'    => 'required|email',
            'password' => 'required|min:3'
        );

        $validator = Validator::make(Input::all(), $rules);

        if ($validator->fails()) {
            return Redirect::to('login')
                        ->withErrors($validator)
                        ->withInput(Input::except('password'));
        } else {
            $remember = Input::get('remember',0);
            $userdata = array(
                'email'     => Input::get('email'),
                'password'  => Input::get('password')
            );

            $remember = ($remember == 1)?true:false;

            if (Auth::superadmin()->attempt($userdata,$remember)) {
                $superAdmin = Auth::superadmin()->get();
                return Redirect::to('/adminpanel');

            } else if (Auth::admin()->attempt($userdata,$remember)) {
                return Redirect::to('/adminpanel');
            } else {        
             return Redirect::to('login');
            }
        }
     }

     public function doLogout() {
        Auth::logout();
        return Redirect::to('login');
    }
 }

?>

It works fine on localhost. But when I upload it to a shared hosting, the logging works just in the first request (sessions files are created). But when I try to Auth::admin()->check() and get data Auth::admin()->get(), it doesn't work. My DataBase configurations works, I checked file permissions and I set those to 777. I have searched on google and I can't find the answer. I also checked PHP versions, on localhost I got 5.4.24 and on shared hosting 5.4.38. Thanks!

ollieread commented 9 years ago

I'm not sure what to suggest. This isn't a multiauth bug from what I can see, it sounds like a configuration issue, even if you were to revert to default Auth you'd have the same issue.