Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
616 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
database/migrations/2017_07_13_172230_create_google_users_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
/** | ||
* Class CreateProgressBatchesTable. | ||
*/ | ||
class CreateGoogleUsersTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('google_users', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('customerId'); | ||
$table->string('kind'); | ||
$table->integer('google_id')->unsigned()->nullable(); | ||
$table->string('etag'); | ||
$table->string('primaryEmail')->unique(); | ||
$table->string('givenName'); | ||
$table->string('familyName'); | ||
$table->string('fullName'); | ||
$table->string('orgUnitPath'); | ||
$table->json('organizations')->nullable(); | ||
$table->boolean('isAdmin'); | ||
$table->boolean('isDelegatedAdmin'); | ||
$table->dateTime('lastLoginTime'); | ||
$table->dateTime('creationTime'); | ||
$table->dateTime('deletionTime')->nullable(); | ||
$table->dateTime('agreedToTerms'); | ||
$table->string('password')->nullable(); | ||
$table->string('hashFunction')->nullable(); | ||
$table->boolean('suspended'); | ||
$table->string('suspensionReason')->nullable(); | ||
$table->boolean('changePasswordAtNextLogin'); | ||
$table->json('emails'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('google_users'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@extends('adminlte::page') | ||
|
||
@section('htmlheader_title') | ||
Google Apps Users Management | ||
@endsection | ||
|
||
@section('main-content') | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
|
||
<google-apps-dashboard user-admin="{{ config('users.google_apps_admin_user_email') }}"></google-apps-dashboard> | ||
|
||
<google-apps-users-list api-url="{{ env('APP_URL') . env('API_URI','/api/v1/management/users') }}"></google-apps-users-list> | ||
|
||
</div> | ||
</div> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
<?php | ||
|
||
namespace Acacha\Users\Http\Controllers; | ||
|
||
use Acacha\Users\Services\GoogleApps\GoogleAppsService; | ||
|
||
use Acacha\Users\Traits\HasPaginator; | ||
use Google; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Pagination\LengthAwarePaginator; | ||
|
||
/** | ||
* Class GoogleAppsUsersController. | ||
* | ||
* @package Acacha\Users\Http\Controllers | ||
*/ | ||
class GoogleAppsUsersController extends Controller | ||
{ | ||
|
||
use HasPaginator; | ||
|
||
/** | ||
* Google apps service. | ||
* | ||
* @var | ||
*/ | ||
public $service; | ||
|
||
/** | ||
* GoogleAppsUsersController constructor. | ||
* | ||
* @param $service | ||
*/ | ||
public function __construct(GoogleAppsService $service) | ||
{ | ||
$this->service = $service; | ||
} | ||
|
||
|
||
/** | ||
* Show Google apps users. | ||
*/ | ||
public function index() | ||
{ | ||
$this->authorize('see-google-apps-users'); | ||
$data = []; | ||
|
||
return view('acacha_users::googleApps.google', $data); | ||
} | ||
|
||
/** | ||
* Sync local database from Google Apps/Suite data. | ||
*/ | ||
public function localSync(Request $request) | ||
{ | ||
$this->authorize('sync-google-apps-users'); | ||
|
||
return $this->service->localSync(); | ||
} | ||
|
||
/** | ||
* List Google apps users. | ||
*/ | ||
public function all(Request $request) | ||
{ | ||
$this->authorize('list-google-apps-users'); | ||
|
||
$perPage = config('users.google_apps_users_per_page' , 15); | ||
if ($request->has('perPage')) { | ||
$perPage = $request->input('perPage'); | ||
} | ||
|
||
$users = $this->service->getUsers($perPage); | ||
|
||
return $this->paginate($users, $perPage); | ||
} | ||
|
||
/** | ||
* Check google apps connection. | ||
* | ||
* @return array | ||
*/ | ||
public function check() | ||
{ | ||
$this->authorize('check-google-apps-connection'); | ||
|
||
return $this->service->getConnectionState(); | ||
} | ||
|
||
public function google3() | ||
{ | ||
$directory = Google::make('directory'); | ||
dump($directory->users); | ||
} | ||
|
||
public function google5() | ||
{ | ||
//List all users: https://developers.google.com/apps-script/advanced/admin-sdk-directory | ||
|
||
// page = AdminDirectory.Users.list({ | ||
// domain: 'example.com', | ||
// orderBy: 'givenName', | ||
// maxResults: 100, | ||
// pageToken: pageToken | ||
// }); | ||
} | ||
|
||
public function google4() | ||
{ | ||
//Example list 100 users | ||
$directory = Google::make('directory'); | ||
dump(get_class($directory->users)); | ||
dump($directory); | ||
try { | ||
$r = $directory->users->listUsers([ | ||
'domain' => 'iesebre.com', | ||
'maxResults' => 500 | ||
]); | ||
dump($r); | ||
} catch (\Exception $e) { | ||
dd($e); | ||
} | ||
} | ||
|
||
public function google7() | ||
{ | ||
//Example list 500 users. max results maxim value is 500 | ||
$directory = Google::make('directory'); | ||
dump(get_class($directory->users)); | ||
try { | ||
$r = $directory->users->listUsers([ | ||
'domain' => 'iesebre.com', | ||
'maxResults' => 500 | ||
]); | ||
dump($r); | ||
} catch (\Exception $e) { | ||
dd($e); | ||
} | ||
} | ||
|
||
public function google8() | ||
{ | ||
// Count total number of users | ||
$directory = Google::make('directory'); | ||
$count = 0; | ||
$pageToken = null; | ||
do { | ||
try { | ||
$r = $directory->users->listUsers([ | ||
'domain' => 'iesebre.com', | ||
'maxResults' => 500, | ||
'pageToken' => $pageToken | ||
]); | ||
$pageToken = $r->nextPageToken; | ||
// dump($pageToken); | ||
// dump($r); | ||
// dump($r->users); | ||
$count = $count + count($r->users); | ||
dump('count: ' . $count); | ||
} catch (\Exception $e) { | ||
dd($e); | ||
} | ||
} while ($pageToken); | ||
|
||
dd($count); | ||
} | ||
|
||
public function google10() | ||
{ | ||
return $this->service->localSync(); | ||
} | ||
|
||
public function esborrar() | ||
{ | ||
$googleClient = Google::getClient(); | ||
// dd($googleClient); | ||
$directory = Google::make('directory'); | ||
// dd($directory); | ||
|
||
$email = "stur@iesebre.com"; | ||
try { | ||
$r = $directory->users->get($email); | ||
if($r) { | ||
echo "Name: ".$r->name->fullName."<br/>"; | ||
echo "Suspended?: ".(($r->suspended === true) ? 'Yes' : 'No')."<br/>"; | ||
echo "Org/Unit/Path: ".$r->orgUnitPath."<br/>"; | ||
} else { | ||
echo "User does not exist: $email<br/>"; | ||
} | ||
} catch (\Exception $e) { | ||
dd('exception!!!'); | ||
} | ||
|
||
// if the user doesn't exist, it's safe to create the new user | ||
|
||
// $user_to_impersonate = 'adminaccount@example.com'; | ||
// $scopes = array('https://www.googleapis.com/auth/admin.directory.user'); | ||
// $cred = new Google_Auth_AssertionCredentials( | ||
// $service_account_name, | ||
// $scopes, | ||
// $key, | ||
// 'notasecret', // Default P12 password | ||
// 'http://oauth.net/grant_type/jwt/1.0/bearer', // Default grant type | ||
// $user_to_impersonate | ||
// ); | ||
|
||
//$dir = new Google_Service_Directory($client); | ||
//$email = "possiblities@example.com"; | ||
//$r = $dir->users->get($email); | ||
//if($r) { | ||
// echo "Name: ".$r->name->fullName."<br/>"; | ||
// echo "Suspended?: ".(($r->suspended === true) ? 'Yes' : 'No')."<br/>"; | ||
// echo "Org/Unit/Path: ".$r->orgUnitPath."<br/>"; | ||
//} else { | ||
// echo "User does not exist: $email<br/>"; | ||
// // if the user doesn't exist, it's safe to create the new user | ||
//} | ||
} | ||
|
||
} |
Oops, something went wrong.