-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin.php
42 lines (36 loc) · 1.2 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php namespace Crm\Userbackend;
use System\Classes\PluginBase;
use RainLab\User\Models\User;
use Backend\Models\User as BackendUser;
use Hash;
class Plugin extends PluginBase
{
public function registerComponents()
{
}
public function registerSettings()
{
}
public function boot()
{
User::extend(function($model){
$model->bindEvent('model.beforeSave', function() use ($model) {
$backendUser = BackendUser::where('email', $model->email)->first();
if (!$backendUser) {
$backendUser = new BackendUser();
if ($model->name) {
$backendUser->first_name = $model->name;
}
if ($model->surname) {
$backendUser->last_name = $model->surname;
}
$backendUser->email = $model->email;
$backendUser->login = $model->email;
$backendUser->password = post('User[password]');
$backendUser->password_confirmation = post('User[password]');
$backendUser->save();
}
});
});
}
}