Major incomplete Change

This commit is contained in:
Omair Saleh
2019-02-16 06:42:42 +08:00
parent 7745b580fb
commit 02cdc30640
15 changed files with 151 additions and 72 deletions
@@ -3,6 +3,8 @@
namespace App\Classes\Modules\Accounts\DataTransferObjects;
use App\Classes\common;
class UserInvitationObject
{
@@ -12,16 +14,20 @@ class UserInvitationObject
/** @var string */
private $inviteeEmail;
/** @var string|null */
private $hash;
/**
* UserInvitationObject constructor.
* @param int $role
* @param string $inviteeEmail
* @param null|string $hash
*/
public function __construct(int $role, string $inviteeEmail)
public function __construct(int $role, string $inviteeEmail, ?string $hash = null)
{
$this->role = $role;
$this->inviteeEmail = $inviteeEmail;
$this->hash = $hash ? $hash : Common::generateRandomHash(50);
}
/**
@@ -40,5 +46,13 @@ class UserInvitationObject
return $this->inviteeEmail;
}
/**
* @return string
*/
public function getHash(): string
{
return $this->hash;
}
}
@@ -15,62 +15,76 @@ final class UserObject {
/** @var string */
private $password;
private $roleId;
/** @var bool */
private $isVerified;
/**
* UserObject constructor.
* @param string $firstName
* @param string $lastName
* @param string $email
* @param string $password
* @param bool $isVerified
* @param $roleId
* @param bool $isVerified
*/
public function __construct(
string $firstName,
string $lastName,
string $email,
string $password,
bool $isVerified = false
) {
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->email = $email;
$this->password = $password;
public function __construct(string $firstName, string $lastName, string $email, string $password, $roleId, bool $isVerified)
{
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->email = $email;
$this->password = $password;
$this->roleId = $roleId;
$this->isVerified = $isVerified;
}
/**
* @return string
*/
public function getFirstName(): string {
public function getFirstName(): string
{
return $this->firstName;
}
/**
* @return string
*/
public function getLastName(): string {
public function getLastName(): string
{
return $this->lastName;
}
/**
* @return string
*/
public function getEmail(): string {
public function getEmail(): string
{
return $this->email;
}
/**
* @return string
*/
public function getPassword(): string {
public function getPassword(): string
{
return $this->password;
}
/**
* @return mixed
*/
public function getRoleId()
{
return $this->roleId;
}
/**
* @return bool
*/
public function isVerified(): bool {
public function isVerified(): bool
{
return $this->isVerified;
}
}
@@ -44,23 +44,23 @@ class CreatesUserAccount {
if($this->repository->where('email', $object->getEmail())->get()->count()){
throw new ResourceConflictException();
}
/** @var User $user */
$user = $this->repository->create([
'first_name' => $object->getFirstName(),
'last_name' => $object->getLastName(),
'email' => $object->getEmail(),
'role_id' => $object->getRoleId(),
'password' => Hash::make($object->getPassword())
]);
// create an email verification attempt if needed
if ($object->isVerified() === false) {
$this->service->execute($object->getEmail());
}
// // create an email verification attempt if needed
// if ($object->isVerified() === false) {
// $this->service->execute($object->getEmail());
// }
return $user;
} catch (\Exception $exception) {
dd($exception);
throw new CannotCreateUserException($exception->getMessage());
}
}
@@ -6,8 +6,6 @@ namespace App\Classes\Modules\Accounts\Services;
use App\Classes\common;
use App\Classes\Modules\Accounts\DataTransferObjects\UserInvitationObject;
use App\Classes\Modules\Accounts\Exceptions\InvitationAlreadyExistsException;
use App\Classes\Modules\ControllerLogic\Exceptions\ResourceConflictException;
use App\Models\User;
use App\Models\UserInvitation;
final class CreatesUserInvitation
@@ -16,30 +14,26 @@ final class CreatesUserInvitation
/** @var UserInvitation */
private $repository;
/** @var User */
private $user;
/**
* CreatesUserInvitation constructor.
* @param UserInvitation $repository
* @param User $user
*/
public function __construct(UserInvitation $repository, User $user) {
public function __construct(UserInvitation $repository)
{
$this->repository = $repository;
$this->user = $user;
}
/**
* @param UserInvitationObject $object
* @return UserInvitation|null
* @throws ResourceConflictException
*/
public function execute(UserInvitationObject $object): ?UserInvitation {
$model = $this->repository->create([
'email' => $object->getInviteeEmail(),
'hash' => Common::generateRandomHash(50),
'hash' => $object->getHash(),
'role_id' => $object->getRole(),
'sender_id' => $this->user->getAuthIdentifier(),
'sender_id' => auth()->user()->getAuthIdentifier(),
'is_complete' => false,
]);
@@ -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()}");
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Account;
use App\Classes\Modules\ControllersLogic\Accounts\RegisterAccountLogic;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
class RegisterAccountController extends Controller
@@ -12,11 +13,11 @@ class RegisterAccountController extends Controller
/**
* @param Request $request
* @param RegisterAccountLogic $logic
* @return JsonResponse
* @return RedirectResponse
* @throws \App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException
* @throws \App\Classes\Modules\ControllerLogic\Exceptions\MalformedRequestException
*/
public function register(Request $request, RegisterAccountLogic $logic): JsonResponse {
public function register(Request $request, RegisterAccountLogic $logic): RedirectResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,34 @@
<?php
namespace App\Http\Controllers\Account;
use App\Models\UserInvitation;
class ShowRegistrationFormController
{
/** @var UserInvitation */
private $repository;
/**
* ShowRegistrationFormController constructor.
* @param UserInvitation $repository
*/
public function __construct(UserInvitation $repository)
{
$this->repository = $repository;
}
public function show(string $email, string $hash){
$invite = $this->repository->where('email', $email)->where('hash', $hash)->first();
if($invite){
return view('pages.authentication.registration', ['invite' => $invite]);
}
return redirect()->route('login');
}
}
+1 -1
View File
@@ -15,7 +15,7 @@ class User extends AbstractUserModel
* @var array
*/
protected $fillable = [
'first_name', 'last_name', 'email', 'password', 'verified', 'role'
'first_name', 'last_name', 'email', 'password', 'verified', 'role_id'
];
/**
+1 -1
View File
@@ -29,7 +29,7 @@ class InvitationEmail extends AbstractEmail
}
private function invitationUrl(){
return url(route('auth.registration', ['hash' => $this->invitation->getInvitation()->hash]));
return url(route('auth.registration', ['email' => $this->invitation->getInvitation()->email, 'hash' => $this->invitation->getInvitation()->hash]));
}
private function senderName(){
@@ -11,9 +11,10 @@ trait DeterminesIfUserPasswordMatchesRequirements {
private function doesPasswordMeetRequirements(string $password): bool {
$matches = [];
preg_match('/^.*(?=.{3,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d]).*$/', $password, $matches);
// preg_match('/^.*(?=.{3,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d]).*$/', $password, $matches);
return count($matches) > 0;
// return count($matches) > 0;
return true;
}
/**
Binary file not shown.

After

Width:  |  Height:  |  Size: 417 KiB

@@ -19,7 +19,7 @@
<label class="muted block">Marking</label>
<input class="form-control block" v-model="order.marking">
</div>
<div class="col-auto no-padding">
<div class="col-auto no-padding" @click="generateMarking()">
<div class="input-group-addon pointer inline">
<div class="row align-items-center justify-content-center h-100">
<div class="col">
@@ -125,6 +125,9 @@
})
},
generateMarking(){
this.order.marking = Math.floor(Math.random() * 799999) + 200000;
},
toggleIncludeWarehouse(){
this.order.warehouse_id = null;
this.showWarehouse = !this.showWarehouse;
@@ -3,17 +3,24 @@
@section('content')
<div class="fluid-container h-100">
<div class="row no-margin" style=" min-height: 100%; ">
<div class="col no-padding" style="background-image: url({{asset('images/login_bg.jpg')}}); background-position: center; background-size: cover;">
<div class="col no-padding" style="background-image: url({{asset('images/shipping_bg.jpeg')}}); background-position: center; background-size: cover;">
<div class="w-100 h-100 bg-primary" style="position: absolute; opacity: 0.1;"></div>
</div>
<div class="col-4 padding-50 bg-white">
<div class="row m-t-50">
<div class="col">
<img src="{{asset('images/logo.png')}}" alt="logo" height="45">
<div class="col m-t-50 p-l-0">
<img src="{{asset('images/logo.png')}}" alt="logo" height="35">
</div>
</div>
<div class="row m-t-35">
<div class="row m-t-50">
<div class="col">
<div class="inline v-align-middle">
<h4 class="font-heading no-margin lh-28">User Login</h4>
<p class="no-margin hint-text lh-18">Sign in using your credentials</p>
</div>
</div>
</div>
<div class="row m-t-10">
<div class="col">
<div class="row">
<div class="col">
@@ -3,16 +3,17 @@
@section('content')
<div class="fluid-container h-100">
<div class="row no-margin" style=" min-height: 100%; ">
<div class="col no-padding" style="background-image: url({{asset('images/login_bg.jpg')}}); background-position: center; background-size: cover;">
<div class="w-100 h-100 bg-primary" style="position: absolute; opacity: 0.4;"></div>
<div class="col no-padding" style="background-image: url({{asset('images/shipping_bg.jpeg')}}); background-position: center; background-size: cover;">
<div class="w-100 h-100 bg-master" style="position: absolute; opacity: 0.6;"></div>
</div>
<div class="col-5 padding-50 bg-white">
<div class="row">
<div class="col">
<img src="{{asset('images/logo.png')}}" alt="logo" height="50">
<div class="col-4 padding-50 bg-white">
<div class="row m-t-50">
<div class="col m-t-50 p-l-0">
<img src="{{asset('images/logo.png')}}" alt="logo" height="35">
</div>
</div>
<div class="row m-t-50 m-b-15">
<div class="row m-t-50">
<div class="col">
<div class="inline v-align-middle">
<h4 class="font-heading no-margin lh-28">New User</h4>
@@ -28,9 +29,10 @@
<form id="registration-form" class="p-t-15" method="post" action="{{route('auth.registration.create')}}">
<div class="row">
<div class="col-md-12">
<div class="form-group form-group-default">
<label class="text-primary">Company Name</label>
<input name="company_name" placeholder="enter your company name" class="form-control" value="{{ old('company_name') }}">
<div class="form-group form-group-default disabled">
<label class="muted ">Email Address</label>
<input class="form-control text-black hint-text" value="{{$invite->email}}" disabled>
<input name="email" type="hidden" value="{{$invite->email}}">
</div>
</div>
</div>
@@ -48,14 +50,6 @@
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group form-group-default">
<label class="text-primary">Email</label>
<input name="email" placeholder="enter your email address" class="form-control" value="{{ old('email') }}">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group form-group-default">
@@ -67,6 +61,7 @@
</div>
<div class="row m-t-5">
<div class="col no-padding">
<input type="hidden" name="hash" value="{{$invite->hash}}">
{{ csrf_field() }}
<button class="btn btn-default bg-primary b-primary btn-cons pull-right text-white no-margin">
Sign Up
+3 -2
View File
@@ -6,8 +6,9 @@ Route::get('/storage')->name('storage');
Route::group(['prefix' => 'auth'], function () {
Route::post('/login', 'Auth\LoginController@login')->name('auth.login');
Route::get('/registration/{hash}', 'Auth\RegisterController@showRegistrationForm')->name('auth.registration');
Route::post('/registration/create', 'Auth\RegisterController@register')->name('auth.registration.create');
Route::get('/registration/{email}/{hash}', 'Account\ShowRegistrationFormController@show')->name('auth.registration');
Route::post('/registration/create', 'Account\RegisterAccountController@register')->name('auth.registration.create');
Route::get('/logout', 'Auth\LoginController@logout')->name('auth.logout');
});