mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-22 22:14:26 +00:00
new: add classes required to create basic user entry. #1
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
|
||||
class RegistrationObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
private $name;
|
||||
|
||||
/** @var string */
|
||||
private $email;
|
||||
|
||||
/** @var string */
|
||||
private $password;
|
||||
|
||||
/** @var string */
|
||||
private $passwordConfirmation;
|
||||
|
||||
/** @var int|null */
|
||||
private $type;
|
||||
|
||||
/** @var int|null */
|
||||
private $status;
|
||||
|
||||
/**
|
||||
* UserObject constructor.
|
||||
* @param string $name
|
||||
* @param string $email
|
||||
* @param string $password
|
||||
* @param string $passwordConfirmation
|
||||
* @param int|null $type
|
||||
* @param int|null $status
|
||||
*/
|
||||
public function __construct(string $name, string $email, string $password, string $passwordConfirmation, ?int $type = RoleTypes::USER, ?int $status = ApprovalStatus::PENDING_VERIFICATION)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->email = $email;
|
||||
$this->password = $password;
|
||||
$this->passwordConfirmation = $passwordConfirmation;
|
||||
$this->type = $type;
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPassword(): string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPasswordConfirmation(): string
|
||||
{
|
||||
return $this->passwordConfirmation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getType(): int
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getStatus(): int
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\Processors;
|
||||
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\RegistrationObject;
|
||||
use App\Classes\Modules\Accounts\Services\CreatesUser;
|
||||
use App\Classes\Modules\Accounts\Standards\Rules\CanRegisterUser;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CreateUserProcessor
|
||||
{
|
||||
/** @var CanRegisterUser */
|
||||
private $canRegisterUser;
|
||||
|
||||
/** @var CreatesUser */
|
||||
private $createsUser;
|
||||
|
||||
/**
|
||||
* CreateUserProcessor constructor.
|
||||
* @param CanRegisterUser $canRegisterUser
|
||||
* @param CreatesUser $createsUser
|
||||
*/
|
||||
public function __construct(CanRegisterUser $canRegisterUser, CreatesUser $createsUser)
|
||||
{
|
||||
$this->canRegisterUser = $canRegisterUser;
|
||||
$this->createsUser = $createsUser;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param $roleType
|
||||
* @param $status
|
||||
* @return Model
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function execute(Request $request, $roleType, $status): Model {
|
||||
|
||||
$userObject = new RegistrationObject($request->input('name'), $request->input('email'),
|
||||
$request->input('password'), $request->input('password_confirmation'),
|
||||
$roleType, $status);
|
||||
|
||||
$this->canRegisterUser->passes($userObject);
|
||||
|
||||
/** @var User $user_query */
|
||||
return $this->createsUser->execute($userObject);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\RegistrationObject;
|
||||
use App\Models\User;
|
||||
|
||||
class CreatesUser extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param RegistrationObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(RegistrationObject $object) {
|
||||
$model = new User();
|
||||
$model->name = $object->getName();
|
||||
$model->email = $object->getEmail();
|
||||
$model->password = bcrypt($object->getPassword());
|
||||
$model->type = $object->getType();
|
||||
$model->status = $object->getStatus();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\RegistrationObject;
|
||||
use App\Classes\Modules\Accounts\Standards\Validators\UserRegistrationValidation;
|
||||
|
||||
class CanRegisterUser extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var UserRegistrationValidation */
|
||||
private $userValidation;
|
||||
|
||||
/**
|
||||
* CanCreateUser constructor.
|
||||
* @param UserRegistrationValidation $userValidation
|
||||
*/
|
||||
public function __construct(UserRegistrationValidation $userValidation)
|
||||
{
|
||||
$this->userValidation = $userValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RegistrationObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->userValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RegistrationObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\Standards\Validators;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\RegistrationObject;
|
||||
|
||||
class UserRegistrationValidation extends AbstractValidation
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param RegistrationObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array
|
||||
{
|
||||
return [
|
||||
'name' => $object->getName(),
|
||||
'email' => $object->getEmail(),
|
||||
'password' => $object->getPassword(),
|
||||
'password_confirmation' => $object->getPasswordConfirmation(),
|
||||
'type' => $object->getType(),
|
||||
'status' => $object->getStatus(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required',
|
||||
'email' => 'required|email|max:255|unique:users,email',
|
||||
'password' => 'required|min:6|confirmed',
|
||||
'type' => 'required',
|
||||
'status' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
final class ApprovalStatus {
|
||||
|
||||
public const PENDING_SUBMISSION = 0;
|
||||
|
||||
public const PENDING_VERIFICATION = 1;
|
||||
|
||||
public const APPROVED = 2;
|
||||
|
||||
public const COMPLETED = 3;
|
||||
|
||||
public const REJECTED = 4;
|
||||
|
||||
public const SUSPENDED = 5;
|
||||
|
||||
public const EXPIRED = 6;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
|
||||
final class RoleTypes
|
||||
{
|
||||
|
||||
public const SHADOW_ADMIN = 0;
|
||||
|
||||
public const SUPER_ADMIN = 1;
|
||||
|
||||
public const ADMIN = 2;
|
||||
|
||||
public const ADMIN_ROLES = [self::SHADOW_ADMIN, self::SUPER_ADMIN, self::ADMIN];
|
||||
|
||||
public const USER = 3;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user