承接 filsh/yii2-user 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

filsh/yii2-user

Composer 安装命令:

composer require filsh/yii2-user

包简介

Yii 2 user authentication module

README 文档

README

Yii 2 User - User authentication module

Demo

See here

Features

  • Quick setup - works out of the box so you can see what it does
  • Easily extendable (instructions below)
  • Registration using email and/or username
  • Login using email and/or username
  • Email confirmation (+resend functionality)
  • Account page
    • Updates email, username, and password
    • Requires current password
  • Profile page
    • Lists custom fields for users, e.g., full_name
  • Password recovery
  • Admin crud via GridView

Installation

  • Install Yii 2 using your preferred method
  • Install package via composer "filsh/yii2-user": "dev-master"
  • Update config file config/web.php and config/db.php
// app/config/web.php
return [
    'components' => [
        'user' => [
            'class' => 'filsh\yii2\user\components\User',
        ],
        'mail' => [
            // set up mail for emails
        ]
    ],
    'modules' => [
        'user' => [
            'class' => 'filsh\yii2\user\Module',
            // set custom module properties here ...
        ],
    ],
];
// app/config/db.php
return [
        'class' => 'yii\db\Connection',
        // set up db info
];
  • Run migration file
    • php yii migrate --migrationPath=@vendor/filsh/yii2-user/migrations
  • Go to your application in your browser
    • http://localhost/pathtoapp/web/user
  • Log in as admin using neo/neo (change it!)
  • Set up module properties as desired
  • Optional - Update the nav links in your main layout app/views/layouts/main.php
// app/views/layouts/main.php
<?php
'items' => [
    ['label' => 'Home', 'url' => ['/site/index']],
    ['label' => 'About', 'url' => ['/site/about']],
    ['label' => 'Contact', 'url' => ['/site/contact']],
    ['label' => 'User', 'url' => ['/user']],
    Yii::$app->user->isGuest ?
        ['label' => 'Login', 'url' => ['/user/login']] :
        ['label' => 'Logout (' . Yii::$app->user->displayName . ')',
            'url' => ['/user/logout'],
            'linkOptions' => ['data-method' => 'post']],
],

Development

How do I check user permissions?

This package contains a very simple permissions system. Every user has a role, and that role has permissions in the form of database columns. It should follow the format: can_{permission name}.

For example, the role table has a column named can_admin by default. To check if the user can perform admin actions:

if (!Yii::$app->user->can("admin")) {
    throw new HttpException(403, 'You are not allowed to perform this action.');
}
// --- or ----
$user = User::findOne(1);
$user->can("admin");

Add more database columns for permissions as needed. If you need something more powerful, look into setting up [RBAC] (https://github.com/yiisoft/yii2/blob/master/docs/guide/authorization.md).

Note: If you set up an authManager component for RBAC, then Yii::$app->user->can() will use that instead of this module's custom role table.

How do I extend this package?

You can extend the classes directly. Depending on which ones you need to extend, set the proper config property:

// app/config/web.php
'components' => [
    'user' => [
        'class' => 'app\components\MyUser',
    ],
],
'modules' => [
    'user' => [
        'class' => 'app\modules\MyModule',
        'controllerMap' => [
            'default' => 'app\controllers\MyDefaultController',
        ],
        'modelClasses'  => [
            'Profile' => 'app\models\MyProfile',
        ],
        'viewPath'      => '@app/views/user', // file example: @app/views/user/default/profile.php
        'emailViewPath' => '@app/mails',      // file example: @app/mails/confirmEmail.php
    ],
],

I need more control. Can I just extend the whole thing?

You can always fork the package and modify it as needed.

Or, if you want, you can integrate the package directly into your app by copying the files. This would make it more difficult to get updates, but it also guarantees that your app won't break after running composer update.

I've created a helper command to copy the files for you.

  • Add the module to your config/console.php to gain access to the command (Note: this is CONSOLE config)
// app/config/console.php
'modules' => [
    'user' => [
        'class' => 'filsh\yii2\user\Module',
    ],
],
php yii user/copy --from=@vendor/filsh/yii2-user/filsh/yii2/user --to=@app/modules/user --namespace=app\\modules\\user
  • Update config to point to your new package
// app/config/web.php + app/config/console.php
'modules' => [
    'user' => [
        'class' => 'app\modules\user\Module',
    ],
],

Alternatively, you can do this manually. Just copy/paste the files wherever you'd like and change the namespaces in the files. Replace filsh\yii2\user with app\modules\user.

Changelog

  • 2014/4/17 - Release 1.0.0-beta

Todo

  • Tests
  • Add functionality for user groups (possibly as another package)
  • Issues/requests? Submit a github issue

filsh/yii2-user 适用场景与选型建议

filsh/yii2-user 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 88 次下载、GitHub Stars 达 0, 最近一次更新时间为 2014 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Authentication」 「user」 「auth」 「yii」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 filsh/yii2-user 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 filsh/yii2-user 我们能提供哪些服务?
定制开发 / 二次开发

基于 filsh/yii2-user 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 88
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 101
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-04-24