forked from Wavyzz/dolibarr
SQL tables for oauth
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -95,8 +95,6 @@ class printing_printgcp extends PrintingDriver
|
||||
$storage->storeAccessToken('Google', $token);
|
||||
} catch (Exception $e) {
|
||||
$this->errors[] = $e->getMessage();
|
||||
print '<pre>MissingRefreshToken: '.$e->getMessage().'</pre>';
|
||||
//print '<pre>'.print_r($e,true).'</pre>';
|
||||
}
|
||||
}
|
||||
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 '<pre>MissingRefreshToken: '.$e->getMessage().'</pre>';
|
||||
//print '<pre>'.print_r($e,true).'</pre>';
|
||||
}
|
||||
}
|
||||
// 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(
|
||||
|
||||
Reference in New Issue
Block a user