igorgawrys/social

项目 "social" 的团队页面

安装: 23

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:

dev-master 2019-03-30 18:24 UTC

This package is auto-updated.

Last update: 2024-09-29 05:08:49 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

安装

要安装此包,您需要

  • PHP 7.1

使用 composer 安装此包是最好的方法。运行

composer require igorgawrys/social

或将其添加到 composer.json 中,然后运行 composer update

"require": {
    "igorgawrys/social": "^0.0.1",
}

设置

一旦您通过 composer 安装了此包,请确保遵循以下步骤进行配置。

注册身份验证守卫。

config/auth.php
'guards' => [
    ...,
    'social' => [
        'driver' => 'session' || 'jwt',
        'provider' => 'social',
    ],
'providers' => [
    ...,
    'social' => [
        'driver' => 'eloquent.social' || OR IS NOT WORKING 'eloquent',
        'model' => Igorgawrys\Social\User::class,
    ],
'passwords' => [
    ...,
    'social' => [
        'provider' => 'social',
        'table' => 'password_resets',
        'expire' => 60,
    ],

发布配置文件(可选)

php artisan vendor:publish --provider="Igorgawrys\Social\SocialServiceProvider"

它将发布配置文件(config/social.php),您可以在其中定义自己的连接类型,例如 social。如果您正在使用 WordPress 表的表前缀,请确保在 config/database.php 中填写 prefix 以在您的表中使用 `` 前缀。

例如

'social-mysql' => [
            'driver' => 'mysql',
            'host' => env('SOCIAL_DB_HOST', '127.0.0.1'),
            'port' => env('SOCIAL_DB_PORT', '3306'),
            'database' => env('SOCIAL_DB_DATABASE', 'forge'),
            'username' => env('SOCIAL_DB_USERNAME', 'forge'),
            'password' => env('SOCIAL_DB_PASSWORD', ''),
            'unix_socket' => env('SOCIAL_DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
],

配置

password_resets 表(来自 Laravel 默认身份验证机制)需要存储重置密码令牌。如果您没有 password_resets 表,则使用此迁移代替

<?php

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

class CreatePasswordResetsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('password_resets', function (Blueprint $table) {
            $table->string('email')->index();
            $table->string('token');
            $table->timestamp('created_at')->nullable();
        });
    }

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

扩展

或者,如果您想使用自定义用户模型,您应该让它扩展 Igorgawrys\Social\Models\WordpressUser 并在 config/auth.php 中的 providers -> social -> model 下指定您的模型名称。

建议

使用 publish Model App/User 来编写关系等

使用

您需要显式定义 social 守卫 以加载驱动程序。

示例

// or login using email and password
Auth::guard('social')->attempt([
    'user_email' => 'demo@example.com',
    'user_pass' => 'quickbrownfox'
]);

// get user object
Auth::guard('social')->user();

// Update wordpress compatible password
$user->password = app('social')->make('new_password');
$user->save();

// logout
Auth::guard('social')->logout();

变更日志

CHANGELOG

致谢

感谢 Laravel 社区。

版权和许可

版权 (c) 2019 Igor GawryśMIT 许可证