mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #5204 from turbo124/v5-develop
Connect Gmail Accounts
This commit is contained in:
commit
d86217995c
@ -35,7 +35,8 @@ class CompanyFactory
|
|||||||
$company->custom_fields = (object) [];
|
$company->custom_fields = (object) [];
|
||||||
$company->subdomain = '';
|
$company->subdomain = '';
|
||||||
$company->enabled_modules = config('ninja.enabled_modules'); //32767;//8191; //4095
|
$company->enabled_modules = config('ninja.enabled_modules'); //32767;//8191; //4095
|
||||||
$company->default_password_timeout = 30 * 60000;
|
$company->default_password_timeout = 1800000;
|
||||||
|
|
||||||
|
|
||||||
return $company;
|
return $company;
|
||||||
}
|
}
|
||||||
|
@ -95,13 +95,15 @@ class ConnectedAccountController extends BaseController
|
|||||||
$client->setClientId(config('ninja.auth.google.client_id'));
|
$client->setClientId(config('ninja.auth.google.client_id'));
|
||||||
$client->setClientSecret(config('ninja.auth.google.client_secret'));
|
$client->setClientSecret(config('ninja.auth.google.client_secret'));
|
||||||
$client->setRedirectUri(config('ninja.app_url'));
|
$client->setRedirectUri(config('ninja.app_url'));
|
||||||
$token = $client->authenticate(request()->input('server_auth_code'));
|
// $token = $client->authenticate(request()->input('server_auth_code'));
|
||||||
|
|
||||||
$refresh_token = '';
|
$refresh_token = '';
|
||||||
|
|
||||||
if (array_key_exists('refresh_token', $token)) {
|
// if (array_key_exists('refresh_token', $token)) {
|
||||||
$refresh_token = $token['refresh_token'];
|
// $refresh_token = $token['refresh_token'];
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
$token = '';
|
||||||
|
|
||||||
$connected_account = [
|
$connected_account = [
|
||||||
'email' => $google->harvestEmail($user),
|
'email' => $google->harvestEmail($user),
|
||||||
@ -125,4 +127,53 @@ class ConnectedAccountController extends BaseController
|
|||||||
->header('X-App-Version', config('ninja.app_version'))
|
->header('X-App-Version', config('ninja.app_version'))
|
||||||
->header('X-Api-Version', config('ninja.minimum_client_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'));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,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';
|
$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*/
|
/* Ensure we have a client name, and that all emails are unique*/
|
||||||
//$rules['name'] = 'required|min:1';
|
//$rules['name'] = 'required|min:1';
|
||||||
$rules['settings'] = new ValidClientGroupSettingsRule();
|
$rules['settings'] = new ValidClientGroupSettingsRule();
|
||||||
|
@ -53,7 +53,7 @@ return [
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
'url' => env('APP_URL', 'http://localhost'),
|
'url' => env('APP_URL', 'http://localhost'),
|
||||||
|
'mix_url' => env('APP_URL', 'http://localhost'),
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Application Timezone
|
| Application Timezone
|
||||||
|
@ -37,10 +37,6 @@ class AddUniqueConstraintsOnAllEntities extends Migration
|
|||||||
$table->unique(['company_id', 'number']);
|
$table->unique(['company_id', 'number']);
|
||||||
});
|
});
|
||||||
|
|
||||||
Schema::table('payment_hashes', function (Blueprint $table) {
|
|
||||||
$table->unique(['hash']);
|
|
||||||
});
|
|
||||||
|
|
||||||
Schema::table('recurring_invoices', function (Blueprint $table) {
|
Schema::table('recurring_invoices', function (Blueprint $table) {
|
||||||
$table->string('number')->change();
|
$table->string('number')->change();
|
||||||
$table->unique(['company_id', 'number']);
|
$table->unique(['company_id', 'number']);
|
||||||
|
@ -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('clients/bulk', 'ClientController@bulk')->name('clients.bulk');
|
||||||
|
|
||||||
Route::post('connected_account', 'ConnectedAccountController@index');
|
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
|
Route::resource('client_statement', 'ClientStatementController@statement'); // name = (client_statement. index / create / show / update / destroy / edit
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user