定制 delboy1978uk/bone-user 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

delboy1978uk/bone-user

Composer 安装命令:

composer require delboy1978uk/bone-user

包简介

Integration of delboy1978uk/user for Bone Framework

README 文档

README

Latest Stable Version Total Downloads License build status Code Coverage Scrutinizer Code Quality

User registration and login package for Bone Framework

setup

Simply add the Package to Bone's module config

<?php

// use statements here
use Bone\BoneDoctrine\BoneDoctrinePackage;
use Bone\Mail\MailPackage;
use Bone\Paseto\PasetoPackage;
use Bone\Passport\PassportPackage as BonePassportPackage;
use Bone\User\BoneUserPackage;
use Del\Passport\PassportPackage;
use Del\Person\PersonPackage;
use Del\UserPackage;

return [
    'packages' => [
        // packages here (order is important)...,
        MailPackage::class,
        BoneDoctrinePackage::class,
        PasetoPackage::class,
        PersonPackage::class,
        UserPackage::class,
        BonePassportPackage::class
        BoneUserPackage::class,
    ],
    // ...
];

And once you have done that, setup the DB using the migration commands:

vendor/bin/bone migrant:diff
vendor/bin/bone migrant:migrate
vendor/bin/bone migrant:generate-proxies

Quick point of order here. If you always type vendor/bin/whatever, save yourself the hassle by adding the following to your ~/.bashrc or ~.zshrc or whichever shell file:

export PATH=$PATH:bin:vendor/bin

Then you can close and reopen your terminal, and from now on you can just type bone. The same for any executable stored in a bin/ directory in your current folder.

The last setup stage is to deploy the public assets (CSS, JS, etc.)

vendor/bin/bone assets:deploy

(You added your PATH so didn't have to type vendor/bin/bone, right?)

usage

Once installed head to your site (by default using the Bone Framework Docker development environment (it's https://awesome.scot/user) and register yourself as a user. Again if using the provided dev environment, check your MailHog server at https://awesome.scot:8025 to see any outgoing mails in a convenient web inbox. Activate your account etc! You can see all of the available endpoints in src/BoneUserPackage.php in the addRoutes() section.

authorization middleware

You can lock down a route to make it available to a logged in user by adding the session authorization middleware Bone\User\Http\Middleware\SessionAuth or Bone\User\Http\Middleware\SessionAuthRedirect like so:

$sessionAuth = $c->get(SessionAuth::class); // of course there's a use statement above, right? With the full name?
$router->map('GET', '/my/route', [MyController::class, 'whateverAction'])->middleware($sessionAuth);

Once a route is locked down, in your controller you can get a User object by calling:

$user = $request->getAttribute('user');

There is also a SessionAuthRedirect middleware class, which you can add and which will take the visitor to the login page, but redirect back there once logged in.

service and repository classes

You can also fetch the Del\Service\UserService from your packages container regsistration class to inject into your classes. This allows you to perform various funcions, most cases of which are mostly covered, but in practical terms allows you to access the database repository and save data. A user object also has a Del\Entity\Person ando you can also fetch the Del\Person\Service\PersonService from the container.

    /** @var UserService $userService */
    $userService = $c->get(UserService::class);
   
    /** @var PersonService $personService */
    $personService = $c->get(PersonService::class);

views

Obviously, you probably won't want the default Bone view with the pirate theme! So head into your config folder and override the views. Email templates are also in there. Hack away.

<?php

/*
 *  You can override views from vendor packages
 *  You should copy the vendor view folder into your src and tweak from there
 */
return [
    'views' => [
        'boneuser' => 'src/App/View/bone-user',
    ],
];

admin pages and api routes

If enabled, admin pages will be available on /admin/users and /admin/people. API REST routes can also be enabled. Admin routes require delboy1978uk/bone-passportinstalled. API routes require delboy1978uk/bone-oauth2.

config settings

If you'd like to go to your own controller upon login, create a config with the key bone-user, and add the URL you wish to redirect to. You can also disable the /user/register end point, and you can make filling in a profile a requirement.

<?php /* config/bone-user.php */

return [
    'bone-user' => [
        'loginRedirectRoute' => '/admin',
        'enableRegistration' => true,
        'requireProfile' => false,
        'rememberMeCookie' => true,
        'admin' => true,
        'api' => true
    ],
];

That's about it! The rest should autocomplete in your IDE, and it's all pretty straightforward! Have fun.

delboy1978uk/bone-user 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-13