jamesmills / laravel-timezone

Enable user Timezones in your application.
MIT License
677 stars 91 forks source link

Not setting TimeZone #3

Closed movepixels closed 5 years ago

movepixels commented 5 years ago

I just installed to Laravel 5.6 and the time zone is not being set to the Users Table. Timezone field is in the database (confirmed)

User logs into 'App\Http\Controllers\Auth' @ 'LoginController' using method 'login'

Login goes fine, but the timezone field is never filled.

Even added \Log::info('handle login timezone called'); inside the UpdateUsersTimezone to see if its catching the event

public function handle(Login $event)
    {
        \Log::info('handle login timezone called');
        $geoip_info = geoip()->getLocation(request()->server->get('REMOTE_ADDR', null));

        if (auth()->user()->timezone != $geoip_info['timezone']) {
            $user = auth()->user();
            $user->timezone = $geoip_info['timezone'];
            $user->save();

            if (config('timezone.flash') == 'laracasts') {
                flash()->success('We have set your timezone to ' . $geoip_info['timezone']);
            } else {
                request()->session()->flash('success', 'We have set your timezone to ' . $geoip_info['timezone']);
            }
        }
    }

But no go.

I am not using the default Auth Login that comes with Laravel, so I am sure that is the main problem since that event is never fired 'use Illuminate\Auth\Events\Login;'

Any suggestions? Thanks,

Dave

jamesmills commented 5 years ago

Hi Dave,

Sorry about this.

I listen for the LogIn event in the Service Provider

Event::listen(\Illuminate\Auth\Events\Login::class, UpdateUsersTimezone::class);

I wonder if 5.6 changes the way you register event listeners? If your login is working OK and your logging test is not logging anything then the event is not being listened to correctly.

I will spin up a 5.6 locally and give this a test.

jamesmills commented 5 years ago

I was not able to replicate this error, can you provide me with any further information?