invisnik / laravel-steam-auth

Laravel Steam Auth
MIT License
172 stars 69 forks source link

Error with middleware auth after redirect new user #19

Closed ImChiip closed 8 years ago

ImChiip commented 8 years ago

Hello, I am trying to build a site for my server altis life I use your library with Laravel 5.2 I noticed a bug with the addition of a new user when a new user is recorded via the Steam user was recording well in DB but redirect flaunted the middleware error auth In the I just removed the $ user of User :: create and I redo a request for a $ retrieved information with a new DB queries

    public function login(){
        if ($this->steam->validate()) {
            $info = $this->steam->getUserInfo();
            if (!is_null($info)) {
                $user = User::where('steamid', $info->getSteamID64())->first();
                if (!is_null($user)) {
                    Auth::login($user, true);
                    $user->lastlogin = new \DateTime('',new \DateTimeZone('Europe/Paris'));
                    $user->save();
                    return redirect(route('profil'));
                }else{
                    User::create([
                        'username' => $info->getNick(),
                        'avatar'   => $info->getProfilePictureFull(),
                        'steamid'  => $info->getSteamID64(),
                        'lastlogin'   => new \DateTime('',new \DateTimeZone('Europe/Paris'))
                    ]);
                    $user = User::where('steamid', $info->getSteamID64())->first();
                    Auth::login($user, true);
                    return redirect(route('profil'));
                }
            }
        } else {
            return $this->steam->redirect(); // redirect to Steam login page
        }
    }

I can make a pull request if it suits you

Sorry I do not speak much English

Sincerely yours, Arnaud C

Rexeh commented 8 years ago

I solved this a different way in Laravel 5.2, and added some IP logging too.

public function login()
{
    if ($this->steam->validate()) {
        $info = $this->steam->getUserInfo();
        if (!is_null($info)) {
            $user = User::where('steamid', $info->getSteamID64())->first();
            if (!is_null($user)) {
                Auth::login($user, true);
                $user->ip_address = Request::getClientIp();
                $user->save();
                return self::redirectvalid();
            } else {
                $userIP = Request::getClientIp();
                $user = User::create([
                    'name' => $info->getNick(),
                    'steamid' => $info->getSteamID64(),
                    'ip_address' => $userIP,
                ]);
                $user->uid = User::generateUUID($user->id);
                $user->save();
                Auth::login($user, true);
                return self::redirectvalid();
            }
        }
    } else {
        return $this->steam->redirect(); // redirect to Steam login page
    }
}

public function redirectvalid() {
    $playerUID = User::where('uid', '=', Auth::user()->uid)->first();
    return redirect('/player/'. $playerUID->uid); // redirect to site
}