budyaga/yii2-users

支持通过社交服务进行注册,并为每个用户分配多个社交服务的用户和权限管理模块。

安装量: 8,230

依赖项: 0

建议者: 0

安全性: 0

星标: 42

关注者: 8

分支: 39

开放性问题: 8

类型:yii2-extension

0.1.19 2017-11-08 13:55 UTC

README

支持通过社交服务进行注册并为每个用户分配多个社交服务的用户和权限管理模块。

功能

通过电子邮件和社交网络进行用户注册和授权,并能够将多个不同的社交网络账户绑定到您网站的单一账户上

Authorization widget OAuth keys manage widget

更改密码

Changing password

恢复密码

Recovering password

更改电子邮件。将向旧地址和新地址发送确认

Changing e-mai

编辑个人资料

Editinig profile

用户管理模块的行政模块

Admin module

通过GUI编辑RBAC结构和用户权限

Editing RBAC structure

Editiong user permissions

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一

php composer.phar require --prefer-dist budyaga/yii2-users "*"

或在您的 composer.json 文件的 require 部分中添加

"budyaga/yii2-users": "*"

配置

'user' => [
    'identityClass' => 'budyaga\users\models\User',
    'enableAutoLogin' => true,
    'loginUrl' => ['/login'],
],
'authClientCollection' => [
    'class' => 'yii\authclient\Collection',
    'clients' => [
        'vkontakte' => [
            'class' => 'budyaga\users\components\oauth\VKontakte',
            'clientId' => 'XXX',
            'clientSecret' => 'XXX',
            'scope' => 'email'
        ],
        'google' => [
            'class' => 'budyaga\users\components\oauth\Google',
            'clientId' => 'XXX',
            'clientSecret' => 'XXX',
        ],
        'facebook' => [
            'class' => 'budyaga\users\components\oauth\Facebook',
            'clientId' => 'XXX',
            'clientSecret' => 'XXX',
        ],
        'github' => [
            'class' => 'budyaga\users\components\oauth\GitHub',
            'clientId' => 'XXX',
            'clientSecret' => 'XXX',
            'scope' => 'user:email, user'
        ],
        'linkedin' => [
            'class' => 'budyaga\users\components\oauth\LinkedIn',
            'clientId' => 'XXX',
            'clientSecret' => 'XXX',
        ],
        'live' => [
            'class' => 'budyaga\users\components\oauth\Live',
            'clientId' => 'XXX',
            'clientSecret' => 'XXX',
        ],
        'yandex' => [
            'class' => 'budyaga\users\components\oauth\Yandex',
            'clientId' => 'XXX',
            'clientSecret' => 'XXX',
        ],
        'twitter' => [
            'class' => 'budyaga\users\components\oauth\Twitter',
            'consumerKey' => 'XXX',
            'consumerSecret' => 'XXX',
        ],
    ],
],
'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => [
        '/signup' => '/user/user/signup',
        '/login' => '/user/user/login',
        '/logout' => '/user/user/logout',
        '/requestPasswordReset' => '/user/user/request-password-reset',
        '/resetPassword' => '/user/user/reset-password',
        '/profile' => '/user/user/profile',
        '/retryConfirmEmail' => '/user/user/retry-confirm-email',
        '/confirmEmail' => '/user/user/confirm-email',
        '/unbind/<id:[\w\-]+>' => '/user/auth/unbind',
        '/oauth/<authclient:[\w\-]+>' => '/user/auth/index'
    ],
],
'authManager' => [
    'class' => 'yii\rbac\DbManager',
],

'modules' => [
    'user' => [
        'class' => 'budyaga\users\Module',
        'userPhotoUrl' => 'http://example.com/uploads/user/photo',
        'userPhotoPath' => '@frontend/web/uploads/user/photo'
    ],
],

用您的值替换 XXX。要获取这些值,您必须在社交网络上创建应用程序。

如果您正在使用高级模板和 Yandex 客户端,那么您必须在前端和后端应用程序的配置中添加 authClientCollection。然而 Yandex 客户端只能添加到应用程序中的一个。原因在于 Yandex 单个应用程序只能与一个域名一起工作,您不能在不同域名上添加两个不同的 Callback URL。

并非所有服务都返回所有用户数据。如果服务不返回某些数据,则这些数据将使用默认设置。

数据库迁移

yii migrate/up --migrationPath=@vendor/budyaga/yii2-users/migrations

此迁移创建模块运行所需的所有表和两个用户

使用方法

在主布局中

use budyaga\users\components\AuthorizationWidget;
<?= AuthorizationWidget::widget() ?>

注册: http://example.com/signup

个人资料: http://example.com/profile

恢复密码: http://example.com/requestPasswordReset

管理用户: http://example.com/user/admin

管理 RBAC: http://example.com/user/rbac

自定义视图和电子邮件模板

如果您想使用自定义视图和电子邮件模板,您可以在配置中覆盖它们。例如

'modules' => [
    'user' => [
        'class' => 'budyaga\users\Module',
        'customViews' => [
            'login' => '@app/views/site/login'
        ],
        'customMailViews' => [
            'confirmChangeEmail' => '@app/mail/confirmChangeEmail' //in this case you have to create files confirmChangeEmail-html.php and confirmChangeEmail-text.php in mail folder
        ]
    ],
],

您可以从 vendor\budyaga\yii2-users\views\uservendor\budyaga\yii2-users\mail 文件夹中覆盖所有视图。