mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim.git
synced 2026-08-29 01:13:57 +00:00
Major incomplete Change
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Classes\Modules\ControllersLogic\Accounts;
|
||||
|
||||
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\UserInvitationObject;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\UserObject;
|
||||
use App\Classes\Modules\Accounts\Exceptions\CannotCreateUserException;
|
||||
use App\Classes\Modules\Accounts\Services\CreatesUserAccount;
|
||||
@@ -10,6 +11,7 @@ use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException;
|
||||
use App\Classes\Modules\ControllerLogic\Exceptions\MalformedRequestException;
|
||||
use App\Classes\ValueObjects\Constants\HttpStatus;
|
||||
use App\Events\Accounts\UserHasRegistered;
|
||||
use App\Models\UserInvitation;
|
||||
use App\Traits\DeterminesIfUserPasswordMatchesRequirements;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -46,18 +48,31 @@ class RegisterAccountLogic
|
||||
throw new MalformedRequestException('Password strength is insufficient');
|
||||
}
|
||||
|
||||
$invitation = UserInvitation::where('email', $request->input('email'))
|
||||
->where('hash', $request->input('hash'))
|
||||
->where('is_complete', false)->first();
|
||||
|
||||
if(!$invitation){
|
||||
throw new MalformedRequestException('invitation hash is invalid');
|
||||
}
|
||||
|
||||
$invite = new UserInvitationObject($invitation->role_id, $invitation->email, $invitation->hash);
|
||||
|
||||
try {
|
||||
|
||||
// the email doesn't exist in the database, so create the user
|
||||
$object = new UserObject($request->get('first_name'), $request->get('last_name'),
|
||||
$request->get('email'), $request->get('password'), false);
|
||||
$invite->getInviteeEmail(), $request->get('password'), $invite->getRole(), true);
|
||||
|
||||
|
||||
$user = $this->createsUserAccount->execute($object);
|
||||
|
||||
// dispatch event for user registered
|
||||
event(new UserHasRegistered($user));
|
||||
UserInvitation::where('email', $invite->getInviteeEmail())
|
||||
->where('hash', $invite->getHash())->update(['is_complete' => true]);
|
||||
|
||||
return new JsonResponse(null, HttpStatus::RESOURCE_CREATED);
|
||||
auth()->loginUsingId($user->id);
|
||||
|
||||
return redirect()->route('dashboard');
|
||||
|
||||
} catch (CannotCreateUserException $exception) {
|
||||
throw new InternalServerErrorException("Failed to create user because {$exception->getMessage()}");
|
||||
|
||||
Reference in New Issue
Block a user