Laravel 5 - Steam Auth无法创建用户

时间:2017-06-07 12:47:25

标签: laravel laravel-5 steam

我正在尝试安装此https://github.com/invisnik/laravel-steam-auth(包含我自己的一些自定义字段)

它工作正常,除了它在我登录时不会创建用户(它创建表),我不知道为什么。

AuthController.php

    namespace App\Http\Controllers;

    use Invisnik\LaravelSteamAuth\SteamAuth;
    use App\User;
    use Auth;

    class AuthController extends Controller
    {
        /**
         * @var SteamAuth
         */
        private $steam;

        public function __construct(SteamAuth $steam)
        {
            $this->steam = $steam;
        }

        public function login()
        {
            if ($this->steam->validate()) {
                $info = $this->steam->getUserInfo();
                if (!is_null($info)) {
                    $user = User::where('steamid', $info->steamID64)->first();
                    if (is_null($user)) {
                        $user = User::create([
                            'username' => $info->personaname,
                            'avatar'   => $info->avatarfull,
                            'steamid'  => $info->steamID64
                        ]);
                    }
                    Auth::login($user, true);
                    return redirect('/'); // redirect to site
                }
            }
            return $this->steam->redirect(); // redirect to Steam login page
        }
    }

create_users_table.php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('nickname');
            $table->string('avatar');
            $table->string('steamid')->unique();
            $table->string('name');
            $table->string('rank');
            $table->string('community_id');
            $table->string('email')->unique();
            $table->string('password', 60);
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

web.php

Route::get('login', 'AuthController@login')->name('login');

Route::post('logout', 'Auth\LoginController@logout')->name('logout');

蒸汽auth.php

return [

    /*
     * Redirect URL after login
     */
    'redirect_url' => '/',
    /*
     * API Key (http://steamcommunity.com/dev/apikey)
     */
    'api_key' => 'xxx',
    /*
     * Is using https ?
     */
    'https' => false

];

user.php的

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['nickname', 'avatar', 'steamid', 'name', 'rank', 'community_id', 'email', 'password'];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

有什么想法吗?

更新

$info似乎返回null,我不知道为什么。

0 个答案:

没有答案