This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

sokser+deatr10685
sokser+deatr10685

I'm trying to learn OctoberCMS and I am confused about the complete process of extending plugins. I've extended the user plugin according to the screencast (https://vimeo.com/108040919). Ultimately, I'm looking to create a new field called "category" which wold store a users category. On a new page, I have the following form which I am trying to use to register a new user based solely on their e-mail address. The "category" is populated based on the page that they registered from and the password should be automatically generated so that the user will set it upon confirming their account from an e-mail activation link. My plugin is called "Profile".

My plugin.php file looks like:


 'Profile',
            'description' => 'Handles user demographic information',
            'author'      => '',
            'icon'        => 'icon-leaf'
        ];
    }

    public function boot()
    {
        UserModel::extend(function($model){
            $model->hasOne['profile'] = ['Sokser\Profile\Models\Profile'];
        });
        // $user->profile->zip

        UserModel::deleting(function($user) {
            $user->profile->delete();
        });

        UsersController::extendFormFields(function($form,$model,$context){
            if(!$model instanceof UserModel)
            {
                return;
            }
            if(!$model->exists)
            {
                return;
            }
            //Ensures that a profile model always exists...
            ProfileModel::getFromUser($model);

            $form->addTabFields([
                'profile[age]'=>[
                    'label'=>'Age',
                    'tab'=>'Profile',
                    'type'=>'number'
                ],
                'profile[gender]'=>[
                    'label'=>'Gender',
                    'tab'=>'Profile',
                    'type'=> 'dropdown',
                    'options'=>array('male'=>'Male',
                                     'female'=>'Female')

                ],
                'profile[category]'=>[
                    'label'=>'Category',
                    'tab'=>'Profile',
                    'type'=> 'dropdown',
                    'options'=>array('sink'=>'SINK',
                                     'dink'=>'DINK')
                ],
                'profile[vag]'=>[
                    'label'=>'VAG',
                    'tab'=>'Profile',
                    'type'=> 'dropdown',
                    'options'=>array('v'=>'V',
                                     'a'=>'A',
                                     'g'=>'G')
                ]
            ]);
        });
    }

}

My profile.php file looks like:


 ['required', 'min:0']
    ];

    /**
     * @var string The database table used by the model.
     */
    public $table = 'sokser_profile_profiles';

    /**
     * @var array Guarded fields
     */
    protected $guarded = ['*'];

    /**
     * @var array Fillable fields
     */
    protected $fillable = [];

    /**
     * @var array Relations
     */
    public $hasOne = [];
    public $hasMany = [];
    public $belongsTo = [
        'user'=> ['RainLab\User\Models\User']
    ];
    public $belongsToMany = [];
    public $morphTo = [];
    public $morphOne = [];
    public $morphMany = [];
    public $attachOne = [];
    public $attachMany = [];

    public static function getFromUser($user)
    {
        if($user->profile)
        {
            return $user->profile;
        }

        $profile = new static;
        $profile->user = $user;
        $profile->save();

        $user->profile = $profile;

        return $profile;
    }

}

I am trying to create a user registration form that looks like the following:


    <form class="flexiContactForm col s12" role="form" data-request="{{ __SELF__ }}::onSignup" data-request-update="'{{ __SELF__ }}::confirm': '.confirm-container'">
        <button id="signup_button" class="waves-effect waves-light btn" style="float:right;" type="submit">Sign Up</button>
        <div style="overflow: hidden; padding-right:0em;">
        <input id="signup_email" type="email" class="validate" name="email">            
        <label id="signup_email_label" for="signup_email" data-error="" data-success="">Email Address</label>
        <input type="hidden" name="category" value="{{ data.category }}"/>
        </div>
    </form>

What I am confused about is how to make an "onSignup" component that will basically extend the functionality of the user plugins "onRegister" component and then automatically generate a password and also save the "category" field. Can anyone provide an example or link to a page that shows an example of this? Thanks.

Last updated

sokser+deatr10685
sokser+deatr10685

Does anyone have any hints?

chris10207
chris10207

in your layout or page, in the php section you will have your own custom function to handle your user registration like this for example:

public function onMySignup()
{
// do here your own stuff
// then you can call the Account component to perform the actual user registration
$this['account']->onRegister();
// get the user from here
$user = Auth::getUser();
// and do your own cooking with
}

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.