mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
#2330 oc.com role assignment at the user registration stage
This commit is contained in:
parent
a5f4191b2d
commit
d18e8fdc4f
@ -1,50 +0,0 @@
|
||||
<?php namespace Visiosoft\ProfileModule\Profile\Register2\Command;
|
||||
|
||||
use Anomaly\UsersModule\Role\Command\GetRole;
|
||||
use Visiosoft\ProfileModule\Profile\Register2\Register2FormBuilder;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
|
||||
/**
|
||||
* Class AssociateActivationRoles
|
||||
*
|
||||
* @link http://openclassify.com/
|
||||
* @author OpenClassify, Inc. <support@openclassify.com>
|
||||
* @author Visiosoft Inc <support@openclassify.com>
|
||||
*/
|
||||
class AssociateActivationRoles
|
||||
{
|
||||
|
||||
use DispatchesJobs;
|
||||
|
||||
/**
|
||||
* The form builder.
|
||||
*
|
||||
* @var RegisterFormBuilder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
/**
|
||||
* Create a new AssociateActivationRoles instance.
|
||||
*
|
||||
* @param RegisterFormBuilder $builder
|
||||
*/
|
||||
public function __construct(Register2FormBuilder $builder)
|
||||
{
|
||||
$this->builder = $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
/* @var UserInterface $user */
|
||||
$user = $this->builder->getFormEntry();
|
||||
|
||||
foreach ($this->builder->getRoles() as $role) {
|
||||
if ($role = $this->dispatch(new GetRole($role))) {
|
||||
$user->attachRole($role);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
<?php namespace Visiosoft\ProfileModule\Profile\Register2;
|
||||
|
||||
use Anomaly\Streams\Platform\Ui\Form\FormBuilder;
|
||||
use Visiosoft\ProfileModule\Profile\Register2\Command\AssociateActivationRoles;
|
||||
use Visiosoft\ProfileModule\Profile\Register2\Command\SetOptions;
|
||||
use Anomaly\UsersModule\User\UserModel;
|
||||
use Visiosoft\ProfileModule\Profile\Validation\ValidateRegister;
|
||||
@ -94,14 +93,6 @@ class Register2FormBuilder extends FormBuilder
|
||||
'activated_message' => 'anomaly.module.users::message.account_activated',
|
||||
];
|
||||
|
||||
/**
|
||||
* Fired after the form is saved.
|
||||
*/
|
||||
public function onSaved()
|
||||
{
|
||||
$this->dispatch(new AssociateActivationRoles($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the roles.
|
||||
*
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
<?php namespace Visiosoft\ProfileModule\Profile\Register2;
|
||||
|
||||
use Anomaly\UsersModule\Role\Command\GetRole;
|
||||
use Anomaly\UsersModule\User\Contract\UserInterface;
|
||||
use Anomaly\UsersModule\User\Contract\UserRepositoryInterface;
|
||||
use Anomaly\UsersModule\User\Event\UserHasRegistered;
|
||||
@ -84,6 +85,14 @@ class Register2FormHandler
|
||||
break;
|
||||
}
|
||||
|
||||
$user = $builder->getFormEntry();
|
||||
|
||||
foreach ($builder->getRoles() as $role) {
|
||||
if ($role = $this->dispatch(new GetRole($role))) {
|
||||
$user->attachRole($role);
|
||||
}
|
||||
}
|
||||
|
||||
$events->dispatch(new UserHasRegistered($user));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user