From 1b5d6d44f298306f0e4a6d5f72ca18dc9ae904b4 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 22 Mar 2021 07:21:51 +1100 Subject: [PATCH 1/3] Set default time out --- app/Factory/CompanyFactory.php | 2 +- app/Http/Requests/Client/StoreClientRequest.php | 4 ++++ config/app.php | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Factory/CompanyFactory.php b/app/Factory/CompanyFactory.php index 6eb846084dc7..a7c8a5d2acec 100644 --- a/app/Factory/CompanyFactory.php +++ b/app/Factory/CompanyFactory.php @@ -35,7 +35,7 @@ class CompanyFactory $company->custom_fields = (object) []; $company->subdomain = ''; $company->enabled_modules = config('ninja.enabled_modules'); //32767;//8191; //4095 - $company->default_password_timeout = 30; + $company->default_password_timeout = 1800000; return $company; } diff --git a/app/Http/Requests/Client/StoreClientRequest.php b/app/Http/Requests/Client/StoreClientRequest.php index b9cb4f1a15d6..59c06f72f720 100644 --- a/app/Http/Requests/Client/StoreClientRequest.php +++ b/app/Http/Requests/Client/StoreClientRequest.php @@ -46,6 +46,10 @@ class StoreClientRequest extends Request $rules['documents'] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000'; } + if (isset($this->number)) { + $rules['number'] = Rule::unique('clients')->where('company_id', auth()->user()->company()->id); + } + /* Ensure we have a client name, and that all emails are unique*/ //$rules['name'] = 'required|min:1'; $rules['id_number'] = 'unique:clients,id_number,'.$this->id.',id,company_id,'.$this->company_id; diff --git a/config/app.php b/config/app.php index c1dd0812a8ef..b5a5b1bbabe7 100644 --- a/config/app.php +++ b/config/app.php @@ -53,7 +53,7 @@ return [ */ 'url' => env('APP_URL', 'http://localhost'), - + 'mix_url' => env('APP_URL', 'http://localhost'), /* |-------------------------------------------------------------------------- | Application Timezone From 8197a87ad0b6d7b557e8b3612c1c54144c274ab1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 22 Mar 2021 07:23:21 +1100 Subject: [PATCH 2/3] remove unique constraint on payment hash --- ...21_03_19_221024_add_unique_constraints_on_all_entities.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/database/migrations/2021_03_19_221024_add_unique_constraints_on_all_entities.php b/database/migrations/2021_03_19_221024_add_unique_constraints_on_all_entities.php index a1a1d2d01921..8f68e23e89df 100644 --- a/database/migrations/2021_03_19_221024_add_unique_constraints_on_all_entities.php +++ b/database/migrations/2021_03_19_221024_add_unique_constraints_on_all_entities.php @@ -37,10 +37,6 @@ class AddUniqueConstraintsOnAllEntities extends Migration $table->unique(['company_id', 'number']); }); - Schema::table('payment_hashes', function (Blueprint $table) { - $table->unique(['hash']); - }); - Schema::table('recurring_invoices', function (Blueprint $table) { $table->string('number')->change(); $table->unique(['company_id', 'number']); From 32b8575ce1c83587173b8bf9897e629a32944e5c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 22 Mar 2021 08:06:26 +1100 Subject: [PATCH 3/3] Connected Gmail Account --- .../ConnectedAccountController.php | 59 +++++++++++++++++-- routes/api.php | 1 + 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ConnectedAccountController.php b/app/Http/Controllers/ConnectedAccountController.php index 8f6585533dec..6bd8fabc883d 100644 --- a/app/Http/Controllers/ConnectedAccountController.php +++ b/app/Http/Controllers/ConnectedAccountController.php @@ -95,13 +95,15 @@ class ConnectedAccountController extends BaseController $client->setClientId(config('ninja.auth.google.client_id')); $client->setClientSecret(config('ninja.auth.google.client_secret')); $client->setRedirectUri(config('ninja.app_url')); - $token = $client->authenticate(request()->input('server_auth_code')); + // $token = $client->authenticate(request()->input('server_auth_code')); $refresh_token = ''; - if (array_key_exists('refresh_token', $token)) { - $refresh_token = $token['refresh_token']; - } + // if (array_key_exists('refresh_token', $token)) { + // $refresh_token = $token['refresh_token']; + // } + + $token = ''; $connected_account = [ 'email' => $google->harvestEmail($user), @@ -125,4 +127,53 @@ class ConnectedAccountController extends BaseController ->header('X-App-Version', config('ninja.app_version')) ->header('X-Api-Version', config('ninja.minimum_client_version')); } + + public function handleGmailOauth(Request $request) + { + + $user = false; + + $google = new Google(); + + $user = $google->getTokenResponse($request->input('id_token')); + + if ($user) { + + $client = new Google_Client(); + $client->setClientId(config('ninja.auth.google.client_id')); + $client->setClientSecret(config('ninja.auth.google.client_secret')); + $client->setRedirectUri(config('ninja.app_url')); + $token = $client->authenticate($request->input('server_auth_code')); + + $refresh_token = ''; + + if (array_key_exists('refresh_token', $token)) { + $refresh_token = $token['refresh_token']; + } + + $token = ''; + + $connected_account = [ + 'email' => $google->harvestEmail($user), + 'oauth_user_id' => $google->harvestSubField($user), + 'oauth_user_token' => $token, + 'oauth_user_refresh_token' => $refresh_token, + 'oauth_provider_id' => 'google', + 'email_verified_at' =>now() + ]; + + auth()->user()->update($connected_account); + auth()->user()->email_verified_at = now(); + auth()->user()->save(); + + return $this->itemResponse(auth()->user()); + + } + + return response() + ->json(['message' => ctrans('texts.invalid_credentials')], 401) + ->header('X-App-Version', config('ninja.app_version')) + ->header('X-Api-Version', config('ninja.minimum_client_version')); + + } } diff --git a/routes/api.php b/routes/api.php index f3c18e421f60..26136e5009ee 100644 --- a/routes/api.php +++ b/routes/api.php @@ -37,6 +37,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a Route::post('clients/bulk', 'ClientController@bulk')->name('clients.bulk'); Route::post('connected_account', 'ConnectedAccountController@index'); + Route::post('connected_account/gmail', 'ConnectedAccountController@handleGmailOauth'); Route::resource('client_statement', 'ClientStatementController@statement'); // name = (client_statement. index / create / show / update / destroy / edit