hosted/js lib/hosted public_html/skins
Torsten Grote
grote at kolabsys.com
Tue Jul 3 17:07:52 CEST 2012
hosted/js | 1
hosted/js/jquery.min.js | 1
hosted/js/kolab_admin.js | 1
hosted/js/kolab_hosted.js | 67 ++++++++++++++++++++++++
lib/hosted/kolab_client_task_signup.php | 24 ++++----
public_html/skins/default/templates/signup.html | 5 -
6 files changed, 83 insertions(+), 16 deletions(-)
New commits:
commit faa9766c57200518071e7977959f07d00487dee3
Author: Torsten Grote <grote at kolabsys.com>
Date: Tue Jul 3 15:06:54 2012 +0200
added js based checking of user alias availability
diff --git a/hosted/js b/hosted/js
deleted file mode 120000
index 0723f3a..0000000
--- a/hosted/js
+++ /dev/null
@@ -1 +0,0 @@
-../public_html/js/
\ No newline at end of file
diff --git a/hosted/js/jquery.min.js b/hosted/js/jquery.min.js
new file mode 120000
index 0000000..c3b1873
--- /dev/null
+++ b/hosted/js/jquery.min.js
@@ -0,0 +1 @@
+../../public_html/js/jquery.min.js
\ No newline at end of file
diff --git a/hosted/js/kolab_admin.js b/hosted/js/kolab_admin.js
new file mode 120000
index 0000000..ea11949
--- /dev/null
+++ b/hosted/js/kolab_admin.js
@@ -0,0 +1 @@
+../../public_html/js/kolab_admin.js
\ No newline at end of file
diff --git a/hosted/js/kolab_hosted.js b/hosted/js/kolab_hosted.js
new file mode 100644
index 0000000..5d98c13
--- /dev/null
+++ b/hosted/js/kolab_hosted.js
@@ -0,0 +1,67 @@
+/*
+ +--------------------------------------------------------------------------+
+ | This file is part of the Kolab Web Admin Panel |
+ | |
+ | Copyright (C) 2011-2012, Kolab Systems AG |
+ | |
+ | This program is free software: you can redistribute it and/or modify |
+ | it under the terms of the GNU Affero General Public License as published |
+ | by the Free Software Foundation, either version 3 of the License, or |
+ | (at your option) any later version. |
+ | |
+ | This program is distributed in the hope that it will be useful, |
+ | but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ | GNU Affero General Public License for more details. |
+ | |
+ | You should have received a copy of the GNU Affero General Public License |
+ | along with kadm program. If not, see <http://www.gnu.org/licenses/> |
+ +--------------------------------------------------------------------------+
+ | Author: Torsten Grote <grote at kolabsys.com> |
+ +--------------------------------------------------------------------------+
+*/
+
+kadm.check_user_availability = function(userid)
+{
+ // get form data and build new email address
+ data = kadm.serialize_form('#signup-form');
+ uid = data['alias'] + '@' + data['domain'];
+
+ if(isValidEmailAddress(uid)) {
+ // update future mail form field
+ $('input[name="mail"]').val(uid);
+
+ // check if user with that email address already exists
+ kadm.api_post('users.list', {'search': {'mail': {'value': uid} } }, 'check_user_availability_response');
+ } else {
+ update_user_info('This is not a valid email address!');
+ }
+};
+
+kadm.check_user_availability_response = function(response)
+{
+ if (!kadm.api_response(response))
+ return;
+
+ // setup up user message
+ var msg = '';
+ if(response['result']['count'] > 0) msg = 'User does already exist!';
+
+ update_user_info(msg);
+};
+
+function update_user_info(msg) {
+ if($('span[id="availability"]').length) {
+ // update existing span area
+ $('span[id="availability"]').html(msg);
+ }
+ else {
+ // add span area and inform about non-availability
+ $('input[name="alias"]').after(' <span id="availability" style="font-weight:bold;margin-left:1em;color:red;">' + msg + '</span>');
+ }
+}
+
+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);
+ return pattern.test(emailAddress);
+};
diff --git a/lib/hosted/kolab_client_task_signup.php b/lib/hosted/kolab_client_task_signup.php
index 91dce2f..3df4795 100644
--- a/lib/hosted/kolab_client_task_signup.php
+++ b/lib/hosted/kolab_client_task_signup.php
@@ -43,8 +43,8 @@ class kolab_client_task_signup extends kolab_client_task
// Set the session token we got in the API client instance, so subsequent
// API calls are made in the same session.
- $token = $result->get('session_token');
- $this->api->set_session_token($token);
+ $this->token = $result->get('session_token');
+ $this->api->set_session_token($this->token);
// Run security checks
// TODO figure out to reenable this
@@ -112,15 +112,15 @@ class kolab_client_task_signup extends kolab_client_task
'label' => 'Username',
'name' => 'alias',
'type' => kolab_form::INPUT_TEXT,
-// 'onchange'=> "kadm.command('signup.update_mail', 'test')",
-// 'onchange'=> "kadm.form_value_change(['mail'])",
+ 'value' => 'john.doe',
+ 'onchange'=> "kadm.check_user_availability()",
));
$form->add_element(array(
'label' => 'Domain',
'name' => 'domain',
'type' => kolab_form::INPUT_SELECT,
'options' => $domain_form_names,
-// 'onchange'=> "kadm.command('signup.update_mail', 'test')",
+ 'onchange'=> "kadm.check_user_availability()",
));
$form->add_element(array(
'label' => 'Current Email Address',
@@ -135,18 +135,18 @@ class kolab_client_task_signup extends kolab_client_task
));
$form->add_button(array(
'value' => kolab_html::escape('Sign up'),
-// 'onclick' => "kadm.command('signup.check', 'test')",
+ 'onclick' => "alert('not working yet')",
));
+ // keep session
+ $this->output->set_env('token', $this->token);
+
+ // assign form output to template variable
$this->output->assign('form', $form->output());
}
- public function action_update_mail() {
- $this->output->set_object('test', 'TEST UPDATE');
- }
-
- public function action_check() {
- $this->output->set_object('test', 'TEST CHECK');
+ public function action_add_user() {
+ // TODO actually add user here
}
}
diff --git a/public_html/skins/default/templates/signup.html b/public_html/skins/default/templates/signup.html
index 2370577..0498272 100644
--- a/public_html/skins/default/templates/signup.html
+++ b/public_html/skins/default/templates/signup.html
@@ -7,6 +7,7 @@
<link rel="shortcut icon" type="image/png" href="{$skin_path}images/favicon.png" />
<script src="js/jquery.min.js"></script>
<script src="js/kolab_admin.js"></script>
+ <script src="js/kolab_hosted.js"></script>
<script src="{$skin_path}ui.js"></script>
</head>
<body>
@@ -31,12 +32,10 @@
</div>
- <div id="test"></div>
-
</div>
<div id="footer">
{include file="footer.html"}
</div>
-</body>
{$script}
+</body>
</html>
More information about the commits
mailing list