当前位置: 首页>>代码示例>>PHP>>正文


PHP User::extend方法代码示例

本文整理汇总了PHP中backend\models\User::extend方法的典型用法代码示例。如果您正苦于以下问题:PHP User::extend方法的具体用法?PHP User::extend怎么用?PHP User::extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在backend\models\User的用法示例。


在下文中一共展示了User::extend方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: boot

 public function boot()
 {
     \Backend\Models\User::extend(function ($model) {
         $model->belongsTo['team'] = ['Rafie\\SitepointDemo\\Models\\Team'];
     });
     \Backend\Controllers\Users::extendListColumns(function ($list) {
         $list->addColumns(['team' => ['label' => 'Team', 'relation' => 'team', 'select' => 'name']]);
     });
 }
开发者ID:danielbsabr,项目名称:OctoberCMS_Sitepoint_plugin_demo,代码行数:9,代码来源:Plugin.php

示例2: boot

 /**
  * Run when the Plugin is loaded
  * Difine the extention of user plugin
  * @return [type] [description]
  */
 public function boot()
 {
     UserModel::extend(function ($model) {
         $model->hasOne['profile'] = ['XNok\\Membership\\Models\\Profile'];
     });
     UsersController::extendFormFields(function ($form, $model, $context) {
         $this->extendUserFormFields($form, $model, $context);
     });
     MembersController::extendFormFields(function ($form, $model, $context) {
         $this->extendUserFormFields($form, $model, $context);
     });
     MembersController::extendListColumns(function ($list, $model) {
         if (!$model instanceof UserModel) {
             return;
         }
         $list->addColumns(['is_activated' => ['label' => 'activated', 'type' => 'switch']]);
     });
 }
开发者ID:xNok,项目名称:membership,代码行数:23,代码来源:Plugin.php

示例3: boot

 public function boot()
 {
     /*
      * Add MFA column to Administrators list
      */
     BackendUsers::extendListColumns(function (\Backend\Widgets\Lists $list, $model) {
         if (!$model instanceof BackendUser) {
             return;
         }
         $list->addColumns(['mfa_enabled' => ['label' => 'MFA?', 'type' => 'switch']]);
     });
     // Conditionally required fields
     //Event::listen('eloquent.validating: Backend\Models\User', function($model) {
     BackendUser::validating(function ($model) {
         if (!$model->mfa_enabled) {
             return;
         }
         // Get the original values from this model straight from the DB
         $original = $model->getOriginal();
         $model->rules['mfa_secret'] = 'required';
         $model->rules['mfa_question_1'] = 'required';
         $model->rules['mfa_question_2'] = 'required';
         // If no MFA is set in the DB yet, we need one set on the form
         if ($original['mfa_answer_1'] === '') {
             $model->rules['mfa_answer_1'] = 'required';
         }
         if ($original['mfa_answer_2'] === '') {
             $model->rules['mfa_answer_2'] = 'required';
         }
     });
     BackendUser::extend(function ($model) {
         $model->addHashableAttribute('mfa_answer_1');
         $model->addHashableAttribute('mfa_answer_2');
         $model->setHidden(array_merge($model->getHidden(), ['mfa_answer_1', 'mfa_answer_2']));
         $model->attributeNames['mfa_question_1'] = 'MFA security question 1';
         $model->attributeNames['mfa_question_2'] = 'MFA security question 2';
         $model->attributeNames['mfa_answer_1'] = 'MFA security answer 1';
         $model->attributeNames['mfa_answer_2'] = 'MFA security answer 2';
         // Like a password field, mfa_answers shouldn't be changed in the DB
         // when they're left blank
         $model->bindEvent('model.setAttribute', function ($key, $value) use($model) {
             if (in_array($key, ['mfa_answer_1', 'mfa_answer_2']) && $value === '') {
                 unset($model->attributes[$key]);
             }
         });
     });
     /*
      * Add MFA fields to admin/profile forms
      */
     Event::listen('backend.form.extendFields', function (\Backend\Widgets\Form $widget) {
         if (!$widget->getController() instanceof BackendUsers) {
             return;
         }
         // Profile form
         if ($widget->getContext() == 'myaccount') {
             $widget->addFields(['mfa_enabled' => ['label' => 'Use Multi-Factor Authentication?', 'type' => 'checkbox', 'tab' => 'MFA', 'comment' => "Use Google Authenticator as an extra login check after entering your username and password."], 'mfa_secret' => ['label' => 'MFA Secret', 'type' => 'Flynsarmy\\Mfa\\FormWidgets\\MfaSecret', 'tab' => 'MFA', 'attributes' => ['disabled' => 'disabled'], 'commentAbove' => "Note: Regenerating this will invalidate your existing Google Authenticator account. You'll need to re-add it."], 'mfa_question_1' => ['label' => 'Security Question 1', 'type' => 'text', 'tab' => 'MFA', 'span' => 'left', 'comment' => "This question must be answered to access your account in the event of a lost MFA device."], 'mfa_answer_1' => ['label' => 'Security Answer 1', 'type' => 'password', 'tab' => 'MFA', 'span' => 'right', 'comment' => "Leave this field blank to continue using your current answer."], 'mfa_question_2' => ['label' => 'Security Question 2', 'type' => 'text', 'tab' => 'MFA', 'span' => 'left', 'comment' => "This question must be answered to access your account in the event of a lost MFA device."], 'mfa_answer_2' => ['label' => 'Security Answer 2', 'type' => 'password', 'tab' => 'MFA', 'span' => 'right', 'comment' => "Leave this field blank to continue using your current answer."]], 'primary');
         } elseif ($widget->getContext() == 'update') {
             $widget->addFields(['mfa_enabled' => ['label' => 'Disable Multi-Factor Authentication', 'type' => 'Flynsarmy\\Mfa\\FormWidgets\\DisableMfa', 'tab' => 'MFA', 'comment' => "This administrator has MFA turned on. Click the button above to turn it off for them."]], 'primary');
         }
     });
     /*
      * Add MFA fields to frontend user form - requires rainlab.user
      */
     //Event::listen('backend.form.extendFields', function(\Backend\Widgets\Form $widget) {
     //    if (!$widget->getController() instanceof \RainLab\User\Controllers\Users) return;
     //    if ($widget->getContext() != 'update') return;
     //
     //    $widget->addFields([
     //        'mfa_enabled' => [
     //            'label'       => 'Use MFA?',
     //            'type'        => 'checkbox',
     //            'span'        => 'left',
     //            'description' => "Use Google Authenticator as an extra login check after entering your username and password."
     //        ],
     //        'mfa_secret' => [
     //            'label'       => 'MFA Secret',
     //            'type'        => 'text',
     //            'span'        => 'right',
     //            'description' => "Changing this will invalidate your existing Google Authenticator account. You will need to re-add it."
     //        ],
     //    ], 'primary');
     //});
     /**
      * @param \Cms\Classes\Controller $controller
      * @param string $url
      * @param \Cms\Classes\Page $page
      */
     //Event::listen('cms.page.beforeDisplay', function(Controller $controller, $url, Page $page) {
     //
     //    if ( Auth::check()  )
     //    dd($url, $page, $controller);
     //
     //});
     /**
      * @param \Backend\Classes\Controller $controller
      * @param string $action
      * @param array $params
      */
     Event::listen('backend.page.beforeDisplay', function (\Backend\Classes\Controller $controller, $action, array $params) {
         // Admin isn't logged in yet or is accessing a public action. Nothing to do here.
//.........这里部分代码省略.........
开发者ID:aydancoskun,项目名称:octobercms,代码行数:101,代码来源:Plugin.php

示例4: boot

 public function boot()
 {
     User::extend(function ($model) {
         $model->hasMany['piratmac_smmm_portfolios'] = ['Piratmac\\Smmm\\Models\\Portfolio'];
     });
 }
开发者ID:Piratmac,项目名称:oc-smmm-plugin,代码行数:6,代码来源:Plugin.php


注:本文中的backend\models\User::extend方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。