doc/sample-insert-hosted-user_types.php hosted/js lib/hosted public_html/skins

Torsten Grote grote at kolabsys.com
Tue Jul 10 16:00:36 CEST 2012


 doc/sample-insert-hosted-user_types.php         |   59 ++++--------------------
 hosted/js/kolab_hosted.js                       |   47 +++++++++++++++----
 lib/hosted/kolab_client_task_signup.php         |   26 +++++++---
 public_html/skins/default/templates/signup.html |    3 -
 4 files changed, 69 insertions(+), 66 deletions(-)

New commits:
commit 16026f336093839a8dc3fdd9559e1700ef295613
Author: Torsten Grote <grote at kolabsys.com>
Date:   Tue Jul 10 13:59:40 2012 +0200

    allow for dynamic user type switching when signing up

diff --git a/doc/sample-insert-hosted-user_types.php b/doc/sample-insert-hosted-user_types.php
index 823f0c5..897fb9e 100644
--- a/doc/sample-insert-hosted-user_types.php
+++ b/doc/sample-insert-hosted-user_types.php
@@ -53,31 +53,13 @@
                         ),
                 ),
             "form_fields" => Array(
+                    /*
+                     * Givenname is a requirement, but could
+                     * be filled with random data if not
+                     * wanted.
+                     */
                     "givenname" => Array(),
-                    "kolabdelegate" => Array(
-                            "type" => "list",
-                            "autocomplete" => true,
-                            "optional" => true,
-                        ),
-                    "kolabinvitationpolicy" => Array(
-                            "type" => "select",
-                            "values" => Array(
-                                    "",
-                                    "ACT_MANUAL",
-                                    "ACT_REJECT",
-                                ),
-                            "optional" => true,
-                        ),
-                    "kolaballowsmtprecipient" => Array(
-                            "type" => "list",
-                            "optional" => true,
-                        ),
-                    "kolaballowsmtpsender" => Array(
-                            "type" => "list",
-                            "optional" => true,
-                        ),
                     /*
-                     *
                      * The 'mailalternateaddress' is supposed
                      * to contain the original email address
                      * for the user.
@@ -152,38 +134,21 @@
                     "alias" => Array(
                             "type" => "list",
                             "optional" => true,
-                            "max_count" => 2,
+                            "maxcount" => 2,
                         ),
+                    /*
+                     * Givenname is a requirement, but could
+                     * be filled with random data if not
+                     * wanted.
+                     */
                     "givenname" => Array(),
-                    "kolabdelegate" => Array(
-                            "type" => "list",
-                            "autocomplete" => true,
-                            "optional" => true,
-                        ),
-                    "kolabinvitationpolicy" => Array(
-                            "type" => "select",
-                            "values" => Array(
-                                    "",
-                                    "ACT_MANUAL",
-                                    "ACT_REJECT",
-                                ),
-                            "optional" => true,
-                        ),
-                    "kolaballowsmtprecipient" => Array(
-                            "type" => "list",
-                            "optional" => true,
-                        ),
-                    "kolaballowsmtpsender" => Array(
-                            "type" => "list",
-                            "optional" => true,
-                        ),
                     /*
                      * The 'mailalternateaddress' is supposed
                      * to contain the original email address
                      * for the user.
                      */
                     "mailalternateaddress" => Array(
-                            "optional" => true,
+//                            "optional" => true,
                         ),
                     "sn" => Array(),
                     "uid" => Array(),
diff --git a/hosted/js/kolab_hosted.js b/hosted/js/kolab_hosted.js
index 577aa5c..7bbc35c 100644
--- a/hosted/js/kolab_hosted.js
+++ b/hosted/js/kolab_hosted.js
@@ -21,6 +21,42 @@
  +--------------------------------------------------------------------------+
 */
 
+// overwrite user_save() function
+kadm.user_save = function(reload, section)
+{
+    var data = kadm.serialize_form('#'+this.env.form_id);
+
+    // check email address
+    if(!isValidEmailAddress(data.mailalternateaddress)) {
+        // TODO use translatable error message
+        kadm.display_message('Please provide a valid email adress as this is where your password will be sent to.', 'error');
+        kadm.form_value_error('mailalternateaddress');
+        return;
+    }
+
+    // check password
+    if (data.userpassword != data.userpassword2) {
+      kadm.display_message('user.password.mismatch', 'error');
+      kadm.form_value_error('userpassword2');
+      return;
+    }
+    delete data['userpassword2'];
+
+    if (!kadm.check_required_fields(data)) {
+      kadm.display_message('form.required.empty', 'error');
+      return;
+    }
+
+    kadm.http_post('signup.add_user', {data: data});
+};
+
+kadm.change_user_type = function()
+{
+    var data = kadm.serialize_form('#'+this.env.form_id);
+
+    kadm.http_post('signup.default', {data: data});
+};
+
 kadm.check_user_availability = function()
 {
     // get form data and build new email address
@@ -50,15 +86,6 @@ kadm.check_user_availability_response = function(response)
     update_user_info(msg);
 };
 
-kadm.user_signup = function()
-{
-    if(isValidEmailAddress($('input[name="mailalternateaddress"]').val())) {
-        kadm.user_save();
-    } else{
-        kadm.display_message('Please provide a valid email adress as this is where your password will be sent to.', 'error');
-    }
-}
-
 
 function update_user_info(msg)
 {
@@ -78,7 +105,7 @@ function update_user_info(msg)
     } else {
         $('input[type="button"]').attr("disabled", "disabled");
     }
-}
+};
 
 function isValidEmailAddress(emailAddress) {
     var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
diff --git a/lib/hosted/kolab_client_task_signup.php b/lib/hosted/kolab_client_task_signup.php
index 70563d7..6ac7ef6 100644
--- a/lib/hosted/kolab_client_task_signup.php
+++ b/lib/hosted/kolab_client_task_signup.php
@@ -39,7 +39,7 @@ class kolab_client_task_signup extends kolab_client_task
         $this->output->assign('engine', $this);
         
         // Login ($result is a kolab_client_api_result instance))
-        $result = $this->api->login($this->config->get('ldap', 'bind_dn'), $this->config->get('ldap', 'bind_pw'), 'hostedtest.tld');
+        $result = $this->api->login($this->config->get('ldap', 'bind_dn'), $this->config->get('ldap', 'bind_pw'), $this->config->get('kolab', 'primary_domain') );
 
         // Set the session token we got in the API client instance, so subsequent
         // API calls are made in the same session.
@@ -69,7 +69,10 @@ class kolab_client_task_signup extends kolab_client_task
         // keep session
         $this->output->set_env('token', $_SESSION['user']['token']);
 
-        $this->output->assign('form', $this->user_form());
+        $data = $this->get_input('data', 'POST');
+        $form = $this->user_form($data);
+        $this->output->assign('form', $form);
+        $this->output->set_object('taskcontent', $form);
     }
     
     public function action_add_user() {
@@ -81,6 +84,7 @@ class kolab_client_task_signup extends kolab_client_task
         $attribs['id'] = 'signup-form';
 
         $fields_map = array(
+            'type_id'                   => 'other',
             'givenname'                 => 'other',
             'sn'                        => 'other',
             'cn'                        => 'other',
@@ -109,10 +113,16 @@ class kolab_client_task_signup extends kolab_client_task
             }
         }
 
-        // Add user type field
+        // Add user type id selector
+        $accttypes = array();
+        foreach ($types as $idx => $elem) {
+            $accttypes[$idx] = array('value' => $idx, 'content' => $elem['name']);
+        }
         $fields['type_id'] = array(
-            'type'     => kolab_form::INPUT_HIDDEN,
-            'value'    => $type,
+            'section'  => 'personal',
+            'type'     => kolab_form::INPUT_SELECT,
+            'options'  => $accttypes,
+            'onchange' => "kadm.change_user_type()",
         );
         
         // Add object type field
@@ -153,7 +163,7 @@ class kolab_client_task_signup extends kolab_client_task
         // TODO make translatable
         $fields['uid']['label'] = "Username";
         $fields['mail']['label'] = "Your Future Email Address";
-        $fields['mailalternateaddress']['label'] = "Your Current Email Address";
+        if(isset($fields['mailalternateaddress'])) $fields['mailalternateaddress']['label'] = "Your Current Email Address";
         $fields['domain']['label'] = "Domain";
 
         // Create form object and populate with fields
@@ -196,7 +206,7 @@ class kolab_client_task_signup extends kolab_client_task
             }
 
             // TODO: Perform a check to see if this domain is available for public registration somehow.
-            // Lacking business support, everything but 'kolab.net' (the primary domain) is available.
+            // or provide an account that only sees available domains
             if ($domain_name == $this->config->get('kolab', 'primary_domain')) {
                 continue;
             }
@@ -206,7 +216,7 @@ class kolab_client_task_signup extends kolab_client_task
 
         // prepare array with proper key ids for form building
         foreach ($domain_names as $domain) {
-           $domain_form_names[$domain] = $domain;
+            $domain_form_names[$domain] = $domain;
         }
 
         return $domain_form_names;
diff --git a/public_html/skins/default/templates/signup.html b/public_html/skins/default/templates/signup.html
index 0498272..d68e61a 100644
--- a/public_html/skins/default/templates/signup.html
+++ b/public_html/skins/default/templates/signup.html
@@ -28,7 +28,8 @@
         You can sign up now for a personal account at no cost.
     </p>
     
-    {$form}
+    <div id="taskcontent" class="signup">{$form}</div>
+
 
     </div>
     





More information about the commits mailing list