From e90f68906e52fb100a10df23c158b72243eb8e4c Mon Sep 17 00:00:00 2001 From: frederic34 Date: Fri, 30 Oct 2015 17:59:45 +0100 Subject: [PATCH] SQL tables for oauth --- htdocs/core/modules/modOauth.class.php | 26 ++++++++++++++++++- .../modules/oauth/getgoogleoauthcallback.php | 2 +- .../modules/printing/printgcp.modules.php | 8 ++---- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/htdocs/core/modules/modOauth.class.php b/htdocs/core/modules/modOauth.class.php index 9320e45b0b9..c2c164d81a6 100644 --- a/htdocs/core/modules/modOauth.class.php +++ b/htdocs/core/modules/modOauth.class.php @@ -49,7 +49,7 @@ class modOauth extends DolibarrModules $this->family = "technic"; // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) $this->name = preg_replace('/^mod/i','',get_class($this)); - // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module) + // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module) $this->description = "Enable Oauth."; $this->version = 'dolibarr'; // 'development' or 'experimental' or 'dolibarr' or version $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); @@ -120,4 +120,28 @@ class modOauth extends DolibarrModules } + + + /** + * Function called when module is enabled. + * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. + * It also creates data directories + * + * @param string $options Options when enabling module ('', 'noboxes') + * @return int 1 if OK, 0 if KO + */ + function init($options='') + { + global $conf; + + // Clean before activation + $this->remove($options); + + $sql = array( + "CREATE TABLE IF NOT EXISTS llx_oauth_state (rowid int(11) NOT NULL AUTO_INCREMENT, service varchar(36), state varchar(128), fk_user int(11), fk_adherent int(11), entity int(11), PRIMARY KEY (rowid)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;", + "CREATE TABLE IF NOT EXISTS llx_oauth_token (rowid int(11) NOT NULL AUTO_INCREMENT, service varchar(36), token text, fk_user int(11), fk_adherent int(11), entity int(11), PRIMARY KEY (rowid)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;", + ); + + return $this->_init($sql,$options); + } } diff --git a/htdocs/core/modules/oauth/getgoogleoauthcallback.php b/htdocs/core/modules/oauth/getgoogleoauthcallback.php index 82d83aa1e44..e514f6abe32 100644 --- a/htdocs/core/modules/oauth/getgoogleoauthcallback.php +++ b/htdocs/core/modules/oauth/getgoogleoauthcallback.php @@ -72,7 +72,7 @@ if (! empty($_GET['code'])) { // retrieve the CSRF state parameter $state = isset($_GET['state']) ? $_GET['state'] : null; try { - //$token = $storage->retrieveAccessToken('Google'); + $token = $storage->retrieveAccessToken('Google'); } catch (Exception $e) { print $e->getMessage(); } diff --git a/htdocs/core/modules/printing/printgcp.modules.php b/htdocs/core/modules/printing/printgcp.modules.php index d7f44ae243f..56f8d8068f9 100644 --- a/htdocs/core/modules/printing/printgcp.modules.php +++ b/htdocs/core/modules/printing/printgcp.modules.php @@ -95,8 +95,6 @@ class printing_printgcp extends PrintingDriver $storage->storeAccessToken('Google', $token); } catch (Exception $e) { $this->errors[] = $e->getMessage(); - print '
MissingRefreshToken: '.$e->getMessage().'
'; - //print '
'.print_r($e,true).'
'; } } if (!$conf->oauth->enabled) { @@ -212,8 +210,6 @@ class printing_printgcp extends PrintingDriver $storage->storeAccessToken('Google', $token); } catch (Exception $e) { $this->errors[] = $e->getMessage(); - print '
MissingRefreshToken: '.$e->getMessage().'
'; - //print '
'.print_r($e,true).'
'; } } // Send a request with api @@ -248,7 +244,7 @@ class printing_printgcp extends PrintingDriver function print_file($file, $module, $subdir='') { global $conf, $user, $db; - // si $module=commande_fournisseur alors $conf->fournisseur->commande->dir_output + $fileprint=$conf->{$module}->dir_output; if ($subdir!='') $fileprint.='/'.$subdir; $fileprint.='/'.$file; @@ -314,7 +310,7 @@ class printing_printgcp extends PrintingDriver 'content' => base64_encode($contents), // encode file content as base64 'contentType' => $contenttype ); - // Token storage + // Dolibarr Token storage $storage = new DoliStorage($this->db, $this->conf); // Setup the credentials for the requests $credentials = new Credentials(