Code

Updated registration process
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 10 Nov 2010 06:45:48 +0000 (06:45 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 10 Nov 2010 06:45:48 +0000 (06:45 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@20209 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/include/class_GOsaRegistration.inc
gosa-core/plugins/generic/dashBoard/Register/class_RegistrationDialog.inc
gosa-core/plugins/generic/dashBoard/Register/register.tpl
gosa-core/plugins/generic/dashBoard/class_dashBoard.inc
gosa-core/plugins/generic/statistics/class_statistics.inc
gosa-core/plugins/generic/statistics/statistics.tpl

index efadc48b380a08f8a6d0fe5f3e906a91aa768cf6..7609fe5eeab6d01e5ec98ab7f3020a8563d21544 100644 (file)
@@ -2,18 +2,84 @@
 
 class GOsaRegistration 
 {
+    
     private $config;
+    private $server = "http://10.3.64.59:4000";
+    private $user = "gosa";
+    private $password = "gosa";
+
+    private $isRegistered = NULL;    
 
     function __construct(&$config)
     {
         $this->config = $config;
     }    
 
-    
+    function getRegistrationServer()
+    {
+        return($this->server);
+    }   
+
+    function getConnection($user = NULL, $password ="")
+    {
+        if($user === NULL){
+            return($this->config->getRpcHandle($this->server, $this->user,$this->password, TRUE, FALSE));
+        }else{
+            return($this->config->getRpcHandle($this->server, $user,$password, TRUE, FALSE));
+        }
+    }
+
+    function isServerAccessible()
+    {
+            $con = $this->getConnection();
+            $res = $con->isInstanceRegistered("dummy");
+            if($con->success()){
+                return(TRUE);
+            }else{
+                return(FALSE);
+            }
+    }
+
+    function registrationRequired()
+    {
+        $date = $this->config->configRegistry->getPropertyValue('GOsaRegistration','askForRegistration');
+        if($date == -1){
+            return(FALSE);
+        }else{
+            return($date < time());
+        }
+    }
 
     function isInstanceRegistered()
     {
-        return(FALSE);
+        if($this->isRegistered === NULL){
+            $con = $this->getConnection();
+            $res = $con->isInstanceRegistered($this->config->getInstanceUuid());
+            if($con->success()){
+                $this->isRegistered = $res;
+            }else{
+                return(FALSE);
+            }
+        }
+        return($this->isRegistered);
+    }
+
+
+    static function plInfo()
+    {
+        return (array(
+                    "plProperties"  => array(
+                        array(
+                            "name"          => "askForRegistration",
+                            "type"          => "integer",
+                            "default"       => "0",
+                            "description"   => _("Represents a unix-timestamp which points to the date, GOsa will ask for a registration again. -1 = Never, 0 = Now else once we reached the gieven timestamp"), 
+                            "check"         => "gosaProperty::isInteger",
+                            "migrate"       => "",
+                            "group"         => "registration",
+                            "mandatory"     => FALSE),
+                        ))); 
     }
 } 
 
index fd87e6bd825570de015012db373c2577846ee510..be319f2f10a7e7ffcf19785feeeb6f073cfe9313 100644 (file)
@@ -8,7 +8,7 @@
 
 class RegistrationDialog extends plugin
 {
-    protected $selectedRegistrationType = "registered";
+    protected $selectedRegistrationType = "registrate";
     protected $isRegistered = FALSE; 
     protected $step = 0;
 
@@ -43,7 +43,7 @@ class RegistrationDialog extends plugin
                 msg_dialog::displayChecks($msgs); 
             }else{
 
-                if($this->selectedRegistrationType == "registered"){
+                if($this->selectedRegistrationType == "registrate"){
 
                     // Try to registrate the instance with the given username and password.
                     $rpcHandle = $this->config->registration->getConnection($this->values['username'],$this->values['password']);
@@ -80,14 +80,17 @@ class RegistrationDialog extends plugin
         if(isset($_POST['registrationType']))  $this->selectedRegistrationType = get_post('registrationType');
 
         // Registration type selected and next page choosen.
-        if(isset($_POST['startRegistration'])){
-            if($this->selectedRegistrationType == "none"){
-                $this->step = 100;
-            }else{
-                $this->step = 1;
+        if(isset($_POST['startRegistration'])) $this->step = 1;
+        if(isset($_POST['registerComplete'])){
+            $this->finished = TRUE;
+
+            // Tell GOsa not to ask for a regsitration again.
+            if($this->selectedRegistrationType == "dontWant"){
+                $prop =  $this->config->configRegistry->getProperty('GOsaRegistration','askForRegistration');
+                $prop->setValue(-1);
+                $prop->save();
             }
         }
-        if(isset($_POST['registerComplete'])) $this->finished = TRUE;
         if(isset($_POST['stepBack'])) $this->step -= 1;
     }
 }
index c4c532963016be776bddbd7b7d4e1af01d4b457a..7d0bbe7539adff9d7895c6e1b97de12a3f26ce47 100644 (file)
@@ -6,14 +6,15 @@
 
     {t}Do you want to register GOsa and benefit from the features it brings?{/t}
     <p>
-     <input type='radio' name='registrationType' value='' id="registrationType_"
-         {if $default == ""} checked {/if}><b><LABEL for="registrationType_">{t}I do not want to register{/t}</LABEL></b>
+     <input type='radio' name='registrationType' value='dontWant' id="registrationType_dontWant"
+         {if $default == "dontWant"} checked {/if}>
+            <b><LABEL for="registrationType_dontWant">{t}I do not want to register{/t}</LABEL></b>
         <p style='padding-left:20px;'>
             <!-- Add a descritive text later -->
         </p>
 
-        <input type='radio' name='registrationType' value='registered' id="registrationType_registered"
-            {if $default == "registered"} checked {/if}><b><LABEL for="registrationType_registered">{t}Register{/t}</LABEL></b>
+        <input type='radio' name='registrationType' value='registrate' id="registrationType_registrate"
+            {if $default == "registrate"} checked {/if}><b><LABEL for="registrationType_registrate">{t}Register{/t}</LABEL></b>
         <p style='padding-left:20px;'>
         {t}Additionally to the 'Annonomous' account you can:{/t}
         <ul>
@@ -42,7 +43,7 @@
 
 {/if}
 
-{if $step == 1}
+{if $step == 1 && $default == "registrate"}
     <table>
         <tr>
             <td><LABEL for="username">{t}Login{/t}</LABEL></td>
@@ -64,7 +65,7 @@
     </div>
 {/if}
 
-{if $step == 2}
+{if $step == 2 && $default == "registrate"}
     <h3>{t}Registration complete{/t}</h3>
     <p>
         {t}GOsa instance sucessfully registered{/t}
     </div>
 {/if}
 
-{if $step == 100}
+{if $step == 1 && $default == "dontWant"}
     <h3>{t}Registration complete{/t}</h3>
     <p>
         {t}GOsa instance will not be registered{/t}
     </p>
     <hr>
     <div class="plugin-actions">
+        <button name='stepBack'>{msgPool type=backButton}</button>        
         <button name='registerComplete'>{msgPool type=okButton}</button>        
     </div>
 {/if}
index 8d1e791a1d0797149822bcdf60796a1ee0934548..acec1156bbf68c35bb86d40b4cac5701ad5c8319 100644 (file)
@@ -23,7 +23,7 @@ class dashBoard extends plugin
         $this->dbInformation = new dbInformation($config);
 
         // Check if we've access to the registration server
-        if($config->registration->isServerAccessible()){
+        if($this->config->registration->registrationRequired() && $config->registration->isServerAccessible()){
             if(!$config->registration->isInstanceRegistered()){
                 $this->dialog = new RegistrationDialog($config);
             }
@@ -35,7 +35,6 @@ class dashBoard extends plugin
         // Seems that we haven't registered our GOsa instance yet.
         // Ask the user to do so, now.
         if($this->dialog instanceOf RegistrationDialog){
-            $this->dialog->save_object();
 
             // Check if the registration is complete/canceled
             if(!$this->dialog->finished()){
index df1f8182e43f2580158ca58ebf6143664b234aa9..0ee6f35937678f5389664f3a12a0436cc01ba9bc 100644 (file)
@@ -26,14 +26,18 @@ class statistics extends plugin
     var $graphs = array();
     var $selectedGraphType = 0;
 
-    var $registered = FALSE;
+    var $serverAccessible = FALSE;
+    var $instanceRegistered = FALSE;
 
     function __construct($config)
     {
         plugin::plugin($config, NULL);
 
         // Detect registration status first
-        if(!$this->config->registration->isRegistered()){
+        $this->serverAccessible = $config->registration->isServerAccessible();
+        $this->instanceRegistered = $this->config->registration->isInstanceRegistered();
+
+        if(!$this->serverAccessible || !$this->instanceRegistered){
             $this->graphs[] = new categoryActionsOverTime($config); 
             $this->graphs[] = new memoryUsageChart($config); 
             $this->graphs[] = new cpuLoadChart($config); 
@@ -137,9 +141,9 @@ class statistics extends plugin
         $smarty = get_smarty();
        
         // Check registration status, we need at least 'registered'. 
-        $smarty->assign("registered", $this->config->registration->isRegistered());
-        if(!$this->registered){
-    
+        $smarty->assign("instanceRegistered", $this->instanceRegistered);
+        $smarty->assign("serverAccessible", $this->serverAccessible);
+        if(!$this->serverAccessible || !$this->instanceRegistered){
             $plist = session::get('plist');
  
             $id = array_search('dashBoard', $plist->pluginList);
@@ -419,7 +423,7 @@ class statistics extends plugin
     function save_object()
     {
         // Nothing to do for not registered accounts.
-        if(!$this->config->registration->isRegistered()) return;
+        if(!$this->serverAccessible || !$this->instanceRegistered) return;
 
         plugin::save_object();
         if(isset($_POST['graph1DatePicker1'])) $this->graph1DatePicker1 = get_post('graph1DatePicker1');
index 166863164243b49a3effdcb7fbd16f5cd84dfc59..377d172932f26fb599eb535c3c937ec5e982ba34 100644 (file)
@@ -1,14 +1,16 @@
 
 <h3>{t}Usage statistics{/t}</h3>
-{if !$registered}
+{if !$serverAccessible}
 
     {t}This feature is disabled. To enable it you have to register GOsa, you can initiate a registration using the dash-board plugin.{/t}
 
     <button type='button' onClick="openPlugin({$dashBoardId});">{t}Dash board{/t}</button>
 
-{else if !$rpcConfigured}
+{else if !$instanceRegistered}
 
-    {t}This feature is disabled. To enable it you can use the GOsa properties plugin, just activate the remote procedure call (RPC) configuration flags.{/t}
+    {t}This feature is disabled. To enable it you have to register GOsa, you can initiate a registration using the dash-board plugin.{/t}
+
+    <button type='button' onClick="openPlugin({$dashBoardId});">{t}Dash board{/t}</button>
 
 {else if !$validRpcHandle || $rpcHandle_Error}