Changeset 6367 for sandbox


Ignore:
Timestamp:
05/31/12 16:52:19 (12 years ago)
Author:
cristiano
Message:

Ticket #2768 - Criação do modulo REST API

Location:
sandbox/2.4.1-3
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • sandbox/2.4.1-3/phpgwapi/templates/default/login_default.php

    r6352 r6367  
    183183                        $ch = curl_init(); 
    184184 
     185                        $restConf = parse_ini_file( __DIR__ . '/../../../prototype/config/REST.ini', true ); 
     186 
    185187                        $param  = 'grant_type=password'; 
    186                         $param .= '&client_id=' . $GLOBALS['oauth']['client_id']; 
    187                         $param .= '&client_secret=' . $GLOBALS['oauth']['client_secret']; 
     188                        $param .= '&client_id=' . $restConf['oauth']['client_id']; 
     189                        $param .= '&client_secret=' . $restConf['oauth']['client_secret']; 
    188190                        $param .= '&username=' . $_POST['user']; 
    189191                        $param .= '&password=' . $_POST['passwd']; 
    190192 
    191193                        // set URL and other appropriate options 
    192                         curl_setopt($ch, CURLOPT_URL, $GLOBALS['oauth']['url_token']); 
     194                        curl_setopt($ch, CURLOPT_URL, $restConf['oauth']['url_token']); 
    193195                        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: */*')); 
    194196                        curl_setopt($ch, CURLOPT_POST, TRUE); 
     
    210212                                $_SESSION['oauth']['scope'] = $a->scope; 
    211213                                $_SESSION['oauth']['refresh_token'] = $a->refresh_token; 
    212                                  
    213214                                 
    214215                        } 
  • sandbox/2.4.1-3/prototype/api/config.php

    r6357 r6367  
    55class Config  
    66{ 
    7     static $register; 
    8     static $sessionStarted; 
     7        static $register; 
     8        static $sessionStarted; 
    99   
    10     static function module($config , $module = false) 
    11     { 
    12         //Todo: registrar na nova api o currentapp 
    13         if(!$module) 
    14             $module =  $_SESSION['flags']['currentapp']; 
     10        static function module($config , $module = false) 
     11        { 
     12                //Todo: registrar na nova api o currentapp 
     13                if(!$module) 
     14                                $module =  $_SESSION['flags']['currentapp']; 
    1515   
    16         if( !isset( $_SESSION['config'][$module] ) || !isset( $_SESSION['config'][$module][$config] )) 
    17             $_SESSION['config'][$module] = parse_ini_file( ROOTPATH."/config/$module.ini", true ); 
     16                if( !isset( $_SESSION['config'][$module] ) || !isset( $_SESSION['config'][$module][$config] )) 
     17                                $_SESSION['config'][$module] = parse_ini_file( ROOTPATH."/config/$module.ini", true ); 
    1818         
    19         return isset($_SESSION['config'][$module][$config]) ? $_SESSION['config'][$module][$config] : false; 
     19                return isset($_SESSION['config'][$module][$config]) ? $_SESSION['config'][$module][$config] : false; 
    2020      
    21     } 
     21        } 
    2222     
    23     static function me($config) 
    24     { 
     23        static function me($config) 
     24        { 
    2525         
    26         return isset($_SESSION['wallet']['user'][$config]) ? $_SESSION['wallet']['user'][$config] : false; 
    27     } 
     26                return isset($_SESSION['wallet']['user'][$config]) ? $_SESSION['wallet']['user'][$config] : false; 
     27        } 
    2828     
    29     static function service( $service , $config ) 
    30     { 
    31         if( !isset( $_SESSION['wallet'][$service] ) || !isset( $_SESSION['wallet'][$service][$config] )) 
    32             $_SESSION['wallet'][$service] = parse_ini_file( ROOTPATH."/config/$service.srv", true ); 
     29        static function service( $service , $config ) 
     30        { 
     31                if( !isset( $_SESSION['wallet'][$service] ) || !isset( $_SESSION['wallet'][$service][$config] )) 
     32                                $_SESSION['wallet'][$service] = parse_ini_file( ROOTPATH."/config/$service.srv", true ); 
    3333        
    34         return (isset($_SESSION['wallet'][$service][$config])) ? $_SESSION['wallet'][$service][$config] : false; 
    35     } 
     34                return (isset($_SESSION['wallet'][$service][$config])) ? $_SESSION['wallet'][$service][$config] : false; 
     35        } 
    3636     
    37     static function get( $concept , $config = false , $module = false ) 
    38     { 
    39         $load = parse_ini_file( ROOTPATH."/config/$concept.ini", true ); 
     37        static function get( $concept , $config = false , $module = false ) 
     38        { 
     39                $load = parse_ini_file( ROOTPATH."/config/$concept.ini", true ); 
    4040         
    41         if($config === false) return $load; 
     41                if($config === false) return $load; 
    4242         
    43         return (isset($load[$config])) ? $load[$config] : false; 
    44     } 
     43                return (isset($load[$config])) ? $load[$config] : false; 
     44        } 
    4545     
    46     static function regSet( $name , $value) 
    47     { 
    48         self::$register[$name] = $value; 
    49     } 
    50     static function regGet ($name ) 
    51     { 
    52         return (isset(self::$register[$name]) ? self::$register[$name] : false ); 
    53     } 
     46        static function regSet( $name , $value) 
     47        { 
     48                self::$register[$name] = $value; 
     49        } 
     50        static function regGet ($name ) 
     51        { 
     52                return (isset(self::$register[$name]) ? self::$register[$name] : false ); 
     53        } 
    5454 
    55     static function init( ) 
    56     { 
     55        static function init( ) 
     56        { 
     57     
     58                if( !defined( 'ROOTPATH' ) ) 
     59                                define( 'ROOTPATH', dirname(__FILE__).'/..' ); 
    5760         
    58         if( !defined( 'ROOTPATH' ) ) 
    59             define( 'ROOTPATH', dirname(__FILE__).'/..' ); 
    60          
    61         if ( isset( $_COOKIE[ 'sessionid' ] ) )  
    62         { 
    63             session_id( $_COOKIE[ 'sessionid' ] );  
    64             $GLOBALS['phpgw']->session->sessionid = $_COOKIE[ 'sessionid' ]; 
    65         } 
     61                if ( isset( $_COOKIE[ 'sessionid' ] ) )  
     62                { 
     63                                session_id( $_COOKIE[ 'sessionid' ] );  
     64                                $GLOBALS['phpgw']->session->sessionid = $_COOKIE[ 'sessionid' ]; 
     65                } 
    6666                 
    6767        if( !self::$sessionStarted ) 
    68             self::$sessionStarted = session_start(); 
    69 //               
    70 //      if( $header === true ) 
    71 //      { 
    72 //            require_once (dirname(__FILE__).'/../../header.inc.php'); 
    73 // 
    74 //            $_SESSION['wallet']['Sieve']['user']          =  $GLOBALS['phpgw_info']['user']['account_lid']; 
    75 //            $_SESSION['wallet']['Sieve']['password']      =  $GLOBALS['phpgw_info']['user']['passwd']; 
    76 // 
    77 //            $_SESSION['wallet']['Cyrus']['user']          =  $GLOBALS['phpgw_info']['user']['account_lid']; 
    78 //            $_SESSION['wallet']['Cyrus']['password']      =  $GLOBALS['phpgw_info']['user']['passwd']; 
    79 // 
    80 //            $_SESSION['wallet']['user']['uid']                  =  $GLOBALS['phpgw_info']['user']['userid']; 
    81 //            $_SESSION['wallet']['user']['uidNumber']      =  $GLOBALS['phpgw_info']['user']['account_id']; 
    82 //            $_SESSION['wallet']['user']['password']       =  $GLOBALS['phpgw_info']['user']['passwd']; 
    83 //            $_SESSION['wallet']['user']['cn']             =  $GLOBALS['phpgw_info']['user']['cn']; 
    84 //            $_SESSION['wallet']['user']['mail']           =  $GLOBALS['phpgw_info']['user']['email']; 
    85 // 
    86 //            $_SESSION['wallet']['PostgreSQL']['user']     = $GLOBALS['phpgw_info']['server']['db_user']; 
    87 //            $_SESSION['wallet']['PostgreSQL']['password'] = $GLOBALS['phpgw_info']['server']['db_pass']; 
    88 //            $_SESSION['wallet']['PostgreSQL']['dbname']   = $GLOBALS['phpgw_info']['server']['db_name']; 
    89 //            $_SESSION['wallet']['PostgreSQL']['host']     = $GLOBALS['phpgw_info']['server']['db_host']; 
    90 //             
    91 //            $_SESSION['wallet']['OpenLDAP']['context']   =  $GLOBALS['phpgw_info']['server']['ldap_context']; 
    92 //            $_SESSION['wallet']['OpenLDAP']['host']      =  $GLOBALS['phpgw_info']['server']['ldap_host']; 
    93 //            
    94 //      } 
     68                                self::$sessionStarted = session_start(); 
    9569                 
    96     } 
     70        } 
     71     
     72        public static function writeIniFile($assoc_arr, $path, $has_sections) 
     73        { 
     74                $content = ''; 
     75 
     76                if (!$handle = fopen($path, 'w')) 
     77                { 
     78                        trigger_error("Permission failure when trying to open the file: $path ", E_USER_WARNING); 
     79                        return FALSE; 
     80                }        
     81 
     82                self::_writeIniFile($content, $assoc_arr, $has_sections); 
     83 
     84                if (!fwrite($handle, $content)) 
     85                { 
     86                        trigger_error("Permission failure when trying to write in the file: $path ", E_USER_WARNING); 
     87                }       return FALSE; 
     88 
     89                fclose($handle); 
     90                return TRUE; 
     91        } 
     92 
     93        private static function _writeIniFile(&$content, $assoc_arr, $has_sections) 
     94        { 
     95                foreach ($assoc_arr as $key => $val) 
     96                { 
     97                        if (is_array($val)) 
     98                        { 
     99                                if($has_sections) 
     100                                { 
     101                                        $content .= "[$key]\n"; 
     102                                        self::_writeIniFile(&$content, $val, false); 
     103                                } 
     104                                else                             
     105                                        foreach($val as $iKey => $iVal) 
     106                                        { 
     107                                                if (is_int($iKey)) 
     108                                                        $content .= $key ."[] = $iVal\n"; 
     109                                                else 
     110                                                        $content .= $key ."[$iKey] = $iVal\n"; 
     111                                        } 
     112                        } 
     113                        else 
     114                                $content .= "$key = $val\n"; 
     115                } 
     116        } 
    97117 
    98118} 
    99119 
    100     Config::init(); 
     120        Config::init(); 
    101121         
    102122 
  • sandbox/2.4.1-3/prototype/config/oauthCliente.ini

    r6351 r6367  
    11service = PostgreSQL 
    2 PostgreSQL.concept = clients 
     2PostgreSQL.concept = rest_client 
    33 
    44[PostgreSQL.mapping] 
  • sandbox/2.4.1-3/prototype/config/oauthCode.ini

    r6351 r6367  
    11service = PostgreSQL 
    2 PostgreSQL.concept = auth_codes 
     2PostgreSQL.concept = rest_auth_code 
    33 
    44[PostgreSQL.mapping] 
  • sandbox/2.4.1-3/prototype/config/oauthRefreshToken.ini

    r6351 r6367  
    11service = PostgreSQL 
    2 PostgreSQL.concept = refresh_tokens 
     2PostgreSQL.concept = rest_refresh_token 
    33 
    44[PostgreSQL.mapping] 
     
    88expires = expires 
    99scope = scope 
    10 refresh_token = refresh_token 
     10refresh_token = refresh_tokenr 
  • sandbox/2.4.1-3/prototype/config/oauthToken.ini

    r6351 r6367  
    11service = PostgreSQL 
    2 PostgreSQL.concept = access_tokens 
     2PostgreSQL.concept = rest_access_token 
    33 
    44[PostgreSQL.mapping] 
  • sandbox/2.4.1-3/prototype/rest/dispatch.php

    r6361 r6367  
    3737 
    3838// handle request, passing the current env baseUri and autoload mapping; 
     39 
     40$restConf = parse_ini_file( __DIR__ . '/../config/REST.ini', true ); 
    3941$request = new Request(array( 
    40         'baseUri'=> '/gustavo/expressoDFD/rest', 
     42        'baseUri'=> $restConf['baseUri'], 
    4143        'autoload' => $autoload, 
    4244)); 
Note: See TracChangeset for help on using the changeset viewer.