From 6b394420dcaf65d8fae8bfb7f4affcfb2d22361e Mon Sep 17 00:00:00 2001 From: CheeSiong Date: Fri, 6 Nov 2020 15:26:53 +0800 Subject: [PATCH] registration step 2 front end --- .../RegistrationStep2Logic.php | 157 ++++++++++++++++++ .../ControllerLogic/UpdateUserLogic.php | 1 - .../Accounts/RegistrationStep2Controller.php | 19 +++ resources/assets/sass/_responsive.scss | 53 ++++++ .../accounts/forms/LoginFormComponent.vue | 5 +- .../forms/RegistrationStep2FormComponent.vue | 122 ++++++++++++++ .../accounts/registration_step_2.blade.php | 4 + routes/account.php | 5 +- routes/web.php | 7 +- 9 files changed, 363 insertions(+), 10 deletions(-) create mode 100644 app/Classes/Modules/Accounts/ControllerLogic/RegistrationStep2Logic.php create mode 100644 app/Http/Controllers/Accounts/RegistrationStep2Controller.php create mode 100644 resources/assets/vue/components/accounts/forms/RegistrationStep2FormComponent.vue create mode 100644 resources/views/pages/accounts/registration_step_2.blade.php diff --git a/app/Classes/Modules/Accounts/ControllerLogic/RegistrationStep2Logic.php b/app/Classes/Modules/Accounts/ControllerLogic/RegistrationStep2Logic.php new file mode 100644 index 00000000..06f1286b --- /dev/null +++ b/app/Classes/Modules/Accounts/ControllerLogic/RegistrationStep2Logic.php @@ -0,0 +1,157 @@ + 'Registration Step 2', + 'message' => 'You have completed registration step 2' + ]; + } + + /** @var FetchesUser */ + private $fetchesUser; + + /** @var CanUpdateCompany */ + private $canUpdateCompany; + + /** @var UpdatesCompany */ + private $updatesCompany; + + /** @var CanCreateDocument */ + private $canCreateDocument; + + /** @var CreatesDocument */ + private $createsDocument; + + /** @var CanCreateFile */ + private $canCreateFIle; + + /** @var CreatesFile */ + private $createsFile; + + /** @var Convert64ToFile */ + private $convert64ToFile; + + /** + * UpdateUserControllerLogic constructor. + * @param FetchesUser $fetchesUser + * @param CanUpdateCompany $canUpdateCompany + * @param UpdatesCompany $updatesCompany + * @param CanCreateDocument $canCreateDocument + * @param CreatesDocument $createsDocument + * @param CanCreateFile $canCreateFile + * @param CreatesFile $createsFile + */ + public function __construct( + FetchesUser $fetchesUser, + CanUpdateCompany $canUpdateCompany, + UpdatesCompany $updatesCompany, + CanCreateDocument $canCreateDocument, + CreatesDocument $createsDocument, + CanCreateFile $canCreateFile, + CreatesFile $createsFile, + Convert64ToFile $convert64ToFile + ) + { + $this->fetchesUser = $fetchesUser; + $this->canUpdateCompany = $canUpdateCompany; + $this->updatesCompany = $updatesCompany; + $this->canCreateDocument = $canCreateDocument; + $this->createsDocument = $createsDocument; + $this->canCreateFile = $canCreateFile; + $this->createsFile = $createsFile; + $this->convert64ToFile = $convert64ToFile; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $user_query = $this->fetchesUser->execute(['id' => \Auth::user()->id]); + $company_query = $user_query->company()->first(); + + $company_object = new CompanyObject( + $request->input('company_name', $company_query->name), + $request->input('company_reference', $company_query->refence), + $request->input('type', $company_query->type) + ); + $this->canUpdateCompany->passes($company_object); + $company_query = $this->updatesCompany->execute($company_query, $company_object); + + $document_type = $company_query->type == 1 ? DocumentType::COMPANY_PUBLIC_SMS_REGISTER : DocumentType::COMPANY_PERSONAL_IC; + $document_object = new DocumentObject( + $user_query->id, + OwnerType::COMPANY, + $document_type, + $request->input('document_reference'), + ObjectStatus::PENDING, + null, + null, + null, + null + ); + $this->canCreateDocument->passes($document_object); + $document_query = $this->createsDocument->execute($document_object); + + $file = $this->convert64ToFile->convert($request->input('file')); + $file_type = $company_query->type == 1 ? FileType::COMPANY_PUBLIC_SMS_REGISTER : FileType::COMPANY_PERSONAL_IC; + + $file_object = new FileObject( + $document_query->id, + !empty($file[0]) ? json_encode($file[0]) : null, + $file_type + ); + $this->canCreateFile->passes($file_object); + $file_query = $this->createsFile->execute($file_object); + + DB::commit(); + + return $this->resourceResponse(new UserResource(\Auth::user())); + + } catch (\Exception $exception) { + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Accounts/ControllerLogic/UpdateUserLogic.php b/app/Classes/Modules/Accounts/ControllerLogic/UpdateUserLogic.php index f40a527c..e28e7a35 100644 --- a/app/Classes/Modules/Accounts/ControllerLogic/UpdateUserLogic.php +++ b/app/Classes/Modules/Accounts/ControllerLogic/UpdateUserLogic.php @@ -150,7 +150,6 @@ class UpdateUserLogic extends AbstractControllerLogic return $this->resourceResponse(new UserResource(\Auth::user())); } catch (\Exception $exception) { - dd($exception); throw new ErrorException($exception->getMessage(), $exception->getCode()); } diff --git a/app/Http/Controllers/Accounts/RegistrationStep2Controller.php b/app/Http/Controllers/Accounts/RegistrationStep2Controller.php new file mode 100644 index 00000000..2b2aa9ec --- /dev/null +++ b/app/Http/Controllers/Accounts/RegistrationStep2Controller.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/resources/assets/sass/_responsive.scss b/resources/assets/sass/_responsive.scss index 33498b91..622c734a 100644 --- a/resources/assets/sass/_responsive.scss +++ b/resources/assets/sass/_responsive.scss @@ -1131,4 +1131,57 @@ .hidden-xs { display: none; } +} + + +.upload-box { + width: 250px; + /*margin: auto;*/ + position: relative; +} + +.file-container { + overflow: hidden; + position: relative; +} + +.file-container [type=file] { + cursor: inherit; + display: block; + filter: alpha(opacity=0); + min-height: 100%; + min-width: 100%; + opacity: 0; + position: absolute; + right: 0; + text-align: right; + top: 0; +} + +.file-container { + text-align: center; + border: 1px dashed #d9d9d9; + background: #f3f3f4; + /*border-radius: 10px;*/ + /* float: left; */ + padding: .5em; +} + +.file-container:hover { + border-color: #1AB394; +} + +.file-container [type=file] { + cursor: pointer; +} + +.upload-img { + margin: 0 !important; +} + +.upload-img img { + width: 100%; + border: 1px solid #d9d9d9; + border-top: none; + pointer-events: none; } \ No newline at end of file diff --git a/resources/assets/vue/components/accounts/forms/LoginFormComponent.vue b/resources/assets/vue/components/accounts/forms/LoginFormComponent.vue index d0842ccc..98aa3746 100644 --- a/resources/assets/vue/components/accounts/forms/LoginFormComponent.vue +++ b/resources/assets/vue/components/accounts/forms/LoginFormComponent.vue @@ -79,14 +79,11 @@ methods:{ successHandler(response){ localStorage.setItem('user-token', response.payload.access_token); - console.log(response.payload.access_token); - this.$store.dispatch('userAuthentication', {access_token: response.payload.access_token}); - this.error = ''; this.$store.dispatch('toggleSection', {name: 'loginSuccess', status: true}) setTimeout(function(){ - // window.location.href = response.payload.redirect_url; + window.location.href = response.payload.redirect_url; }, 2000); }, errorHandler(error){ diff --git a/resources/assets/vue/components/accounts/forms/RegistrationStep2FormComponent.vue b/resources/assets/vue/components/accounts/forms/RegistrationStep2FormComponent.vue new file mode 100644 index 00000000..f0429fc9 --- /dev/null +++ b/resources/assets/vue/components/accounts/forms/RegistrationStep2FormComponent.vue @@ -0,0 +1,122 @@ + + diff --git a/resources/views/pages/accounts/registration_step_2.blade.php b/resources/views/pages/accounts/registration_step_2.blade.php new file mode 100644 index 00000000..8f6ff010 --- /dev/null +++ b/resources/views/pages/accounts/registration_step_2.blade.php @@ -0,0 +1,4 @@ +@extends('layouts.base_login') +@section('inner_content') + +@endSection \ No newline at end of file diff --git a/routes/account.php b/routes/account.php index 176023d5..76c96fa8 100644 --- a/routes/account.php +++ b/routes/account.php @@ -10,18 +10,15 @@ Route::group(['prefix' => 'account', 'namespace' => 'Accounts', 'as' => 'account Route::post('/attempt', 'UserAuthenticationController@authenticate')->name('attempt'); }); - - // Route::group(['prefix' => 'password', 'as' => 'password.'], function () { // Route::post('/forget', 'GeneratePasswordResetController@generate')->name('forget'); // Route::post('/reset', 'ResetPasswordController@reset')->name('reset'); // }); - }); Route::group(['middleware' => 'valid.token'], function () { - Route::post('/registration-setp-2', 'UpdateUserController@update')->name('registration'); + Route::post('/registration-setp-2', 'RegistrationStep2Controller@create')->name('registration-step-2'); }); Route::post('/registration', 'CreateUserController@create')->name('registration'); diff --git a/routes/web.php b/routes/web.php index b4758315..1c0aaa42 100644 --- a/routes/web.php +++ b/routes/web.php @@ -22,10 +22,15 @@ Route::get('account/registration', function () { return view('pages.accounts.registration'); })->name('registration'); +Route::get('account/registration-step-2', function () { + return view('pages.accounts.registration_step_2'); +})->name('registration-step-2'); + + Route::get('account/password/reset/{token}', function ($token){ return view('pages.accounts.authentication.reset_password',['token' => $token]); })->name('account.password.reset'); route::get('dashboard/', function (){ - return 'dashboard page here'; + return redirect()->route('registration-step-2'); })->name('dashboard');