diff options
-rw-r--r-- | admin/include/add_core_tabs.inc.php | 4 | ||||
-rw-r--r-- | admin/themes/default/template/user_list.tpl | 118 | ||||
-rw-r--r-- | admin/user_list.php | 14 | ||||
-rw-r--r-- | include/functions_user.inc.php | 92 | ||||
-rw-r--r-- | include/ws_functions.inc.php | 19 | ||||
-rw-r--r-- | register.php | 38 | ||||
-rw-r--r-- | ws.php | 2 |
7 files changed, 211 insertions, 76 deletions
diff --git a/admin/include/add_core_tabs.inc.php b/admin/include/add_core_tabs.inc.php index 443775d38..9769cb32c 100644 --- a/admin/include/add_core_tabs.inc.php +++ b/admin/include/add_core_tabs.inc.php @@ -61,6 +61,10 @@ function add_core_tabs($sheets, $tab_id) case 'comments': $sheets[''] = array('caption' => l10n('User comments'), 'url' => ''); break; + + case 'users': + $sheets[''] = array('caption' => '<span class="icon-users"> </span>'.l10n('User list'), 'url' => ''); + break; case 'configuration': global $conf_link; diff --git a/admin/themes/default/template/user_list.tpl b/admin/themes/default/template/user_list.tpl index 11a97c29d..6cd7de900 100644 --- a/admin/themes/default/template/user_list.tpl +++ b/admin/themes/default/template/user_list.tpl @@ -8,7 +8,9 @@ var selectedMessage_pattern = "{'%d of %d photos selected'|@translate}"; var selectedMessage_none = "{'No photo selected, %d photos in current set'|@translate}"; var selectedMessage_all = "{'All %d photos are selected'|@translate}"; var applyOnDetails_pattern = "{'on the %d selected users'|@translate}"; +var newUser_pattern = "✔ {'User %s added'|translate}"; var missingConfirm = "{'You need to confirm deletion'|translate}"; +var missingUsername = "{'Please, enter a login'|translate}"; var allUsers = [{$all_users}]; var selection = [{$selection}]; @@ -16,6 +18,67 @@ var selection = [{$selection}]; {footer_script}{literal} jQuery(document).ready(function() { + /** + * Add user + */ + jQuery("#addUser").click(function() { + jQuery("#addUserForm").toggle(); + jQuery("#showAddUser .infos").hide(); + jQuery("input[name=username]").focus(); + return false; + }); + + jQuery("#addUserClose").click(function() { + jQuery("#addUserForm").hide(); + return false; + }); + + jQuery("#addUserForm").submit(function() { + jQuery.ajax({ + url: "ws.php?format=json&method=pwg.users.add", + type:"POST", + data: jQuery(this).serialize(), + beforeSend: function() { + jQuery("#addUserForm .errors").hide(); + + if (jQuery("input[name=username]").val() == "") { + jQuery("#addUserForm .errors").html('✘ '+missingUsername).show(); + return false; + } + + jQuery("#addUserForm .loading").show(); + }, + success:function(data) { + oTable.fnDraw(); + jQuery("#addUserForm .loading").hide(); + + var data = jQuery.parseJSON(data); + if (data.stat == 'ok') { + jQuery("#addUserForm input[type=text], #addUserForm input[type=password]").val(""); + + var new_user = data.result.users[0]; + allUsers.push(parseInt(new_user.id)); + jQuery("#showAddUser .infos").html(sprintf(newUser_pattern, new_user.username)).show(); + checkSelection(); + + jQuery("#addUserForm").hide(); + } + else { + jQuery("#addUserForm .errors").html('✘ '+data.message).show(); + } + }, + error:function(XMLHttpRequest, textStatus, errorThrows) { + jQuery("#addUserForm .loading").hide(); + } + }); + + return false; + }); + + /** + * Table with users + */ + /* first column must be prefixed with the open/close icon */ var aoColumns = [ { @@ -264,8 +327,9 @@ jQuery(document).ready(function() { .dataTables_wrapper, .dataTables_info {clear:none;} table.dataTable {clear:right;padding-top:10px;} .bulkAction {margin-top:10px;} -.actionButtons {margin-left:0;} -#applyActionBlock .infos {background-image:none; padding:2px 5px; margin:0;border-radius:5px;} +#addUserForm p {margin-left:0;} +#applyActionBlock .actionButtons {margin-left:0;} +span.infos, span.errors {background-image:none; padding:2px 5px; margin:0;border-radius:5px;} </style> {/literal} @@ -273,19 +337,47 @@ table.dataTable {clear:right;padding-top:10px;} <h2>{'User list'|@translate}</h2> </div> -<form style="display:none" class="filter" method="post" name="add_user" action="{$F_ADD_ACTION}"> +<p class="showCreateAlbum" id="showAddUser"> + <a href="#" id="addUser">{'Add a user'|translate}</a> + <span class="infos" style="display:none"></span> +</p> + +<form id="addUserForm" style="display:none" method="post" name="add_user" action="{$F_ADD_ACTION}"> <fieldset> <legend>{'Add a user'|@translate}</legend> - <label>{'Username'|@translate} <input type="text" name="login" maxlength="50" size="20"></label> - {if $Double_Password} - <label>{'Password'|@translate} <input type="password" name="password"></label> - <label>{'Confirm Password'|@translate} <input type="password" name="password_conf" id="password_conf"></label> - {else} - <label>{'Password'|@translate} <input type="text" name="password"></label> - {/if} - <label>{'Email address'|@translate} <input type="text" name="email"></label> - <label>{'Send connection settings by email'|@translate} <input type="checkbox" name="send_password_by_mail" value="1" checked="checked"></label> - <label> <input class="submit" type="submit" name="submit_add" value="{'Submit'|@translate}"></label> + + <p> + <strong>{'Username'|translate}</strong><br> + <input type="text" name="username" maxlength="50" size="20"> + </p> + + <p> + <strong>{'Password'|translate}</strong><br> + <input type="{if $Double_Password}password{else}text{/if}" name="password"> + </p> + +{if $Double_Password} + <p> + <strong>{'Confirm Password'|@translate}</strong><br> + <input type="password" name="password_confirm"> + </p> +{/if} + + <p> + <strong>{'Email address'|@translate}</strong><br> + <input type="text" name="email"> + </p> + + <p> + <label><input type="checkbox" name="send_password_by_mail"> <strong>{'Send connection settings by email'|@translate}</strong></label> + </p> + + <p class="actionButtons"> + <input class="submit" name="submit_add" type="submit" value="{'Submit'|@translate}"> + <a href="#" id="addUserClose">{'Cancel'|@translate}</a> + <span class="loading" style="display:none"><img src="themes/default/images/ajax-loader-small.gif"></span> + <span class="errors" style="display:none"></span> + </p> </fieldset> </form> diff --git a/admin/user_list.php b/admin/user_list.php index a9744a0d2..3c0b6488d 100644 --- a/admin/user_list.php +++ b/admin/user_list.php @@ -26,6 +26,19 @@ */ // +-----------------------------------------------------------------------+ +// | tabs | +// +-----------------------------------------------------------------------+ + +include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); + +$my_base_url = get_root_url().'admin.php?page='; + +$tabsheet = new tabsheet(); +$tabsheet->set_id('users'); +$tabsheet->select('user_list'); +$tabsheet->assign(); + +// +-----------------------------------------------------------------------+ // | groups list | // +-----------------------------------------------------------------------+ @@ -73,6 +86,7 @@ $template->assign( array( 'users' => $users, 'all_users' => join(',', $user_ids), + 'Double_Password' => $conf['double_password_type_in_admin'] ) ); diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index d48f4362d..f6e2cd925 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -125,12 +125,12 @@ function search_case_username($username) * @param string $login * @param string $password * @param string $mail_adress - * @param bool $with_notifications + * @param bool $notify_admin * @param &array $errors + * @param bool $notify_user * @return int|bool */ -function register_user($login, $password, $mail_address, - $with_notification = true, &$errors = array()) +function register_user($login, $password, $mail_address, $notify_admin=true, &$errors = array(), $notify_user=false) { global $conf; @@ -169,24 +169,24 @@ function register_user($login, $password, $mail_address, } } - $errors = trigger_event('register_user_check', - $errors, - array( - 'username'=>$login, - 'password'=>$password, - 'email'=>$mail_address, - ) - ); + $errors = trigger_event( + 'register_user_check', + $errors, + array( + 'username'=>$login, + 'password'=>$password, + 'email'=>$mail_address, + ) + ); // if no error until here, registration of the user if (count($errors) == 0) { - $insert = - array( - $conf['user_fields']['username'] => pwg_db_real_escape_string($login), - $conf['user_fields']['password'] => $conf['password_hash']($password), - $conf['user_fields']['email'] => $mail_address - ); + $insert = array( + $conf['user_fields']['username'] => pwg_db_real_escape_string($login), + $conf['user_fields']['password'] => $conf['password_hash']($password), + $conf['user_fields']['email'] => $mail_address + ); single_insert(USERS_TABLE, $insert); $user_id = pwg_db_insert_id(); @@ -203,9 +203,9 @@ SELECT id $inserts = array(); while ($row = pwg_db_fetch_assoc($result)) { - $inserts[] = array( - 'user_id' => $user_id, - 'group_id' => $row['id'] + $inserts[] = array( + 'user_id' => $user_id, + 'group_id' => $row['id'] ); } @@ -215,40 +215,66 @@ SELECT id } $override = null; - if ($with_notification and $conf['browser_language']) + if ($notify_admin and $conf['browser_language']) { - if ( !get_browser_language($override['language']) ) + if (!get_browser_language($override['language'])) + { $override=null; + } } create_user_infos($user_id, $override); - if ($with_notification and $conf['email_admin_on_new_user']) + if ($notify_admin and $conf['email_admin_on_new_user']) { include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); - $admin_url = get_absolute_root_url() - .'admin.php?page=user_list&username='.$login; + $admin_url = get_absolute_root_url().'admin.php?page=user_list&username='.$login; - $keyargs_content = array - ( + $keyargs_content = array( get_l10n_args('User: %s', stripslashes($login)), get_l10n_args('Email: %s', $_POST['mail_address']), get_l10n_args('', ''), get_l10n_args('Admin: %s', $admin_url) - ); + ); - pwg_mail_notification_admins - ( + pwg_mail_notification_admins( get_l10n_args('Registration of %s', stripslashes($login)), $keyargs_content - ); + ); + } + + if ($notify_user and email_check_format($mail_address)) + { + include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); + + $keyargs_content = array( + get_l10n_args('Hello %s,', $login), + get_l10n_args('Thank you for registering at %s!', $conf['gallery_title']), + get_l10n_args('', ''), + get_l10n_args('Here are your connection settings', ''), + get_l10n_args('Username: %s', $login), + get_l10n_args('Password: %s', $password), + get_l10n_args('Email: %s', $mail_address), + get_l10n_args('', ''), + get_l10n_args('If you think you\'ve received this email in error, please contact us at %s', get_webmaster_mail_address()), + ); + + pwg_mail( + $mail_address, + array( + 'subject' => '['.$conf['gallery_title'].'] '.l10n('Registration'), + 'content' => l10n_args($keyargs_content), + 'content_format' => 'text/plain', + ) + ); } - trigger_action('register_user', + trigger_action( + 'register_user', array( 'id'=>$user_id, 'username'=>$login, 'email'=>$mail_address, - ) + ) ); return $user_id; diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php index b86fe6fd6..8faf96260 100644 --- a/include/ws_functions.inc.php +++ b/include/ws_functions.inc.php @@ -3561,7 +3561,24 @@ SELECT user_id, group_id */ function ws_users_add($params, &$service) { - $user_id = register_user($params['username'], $params['password'], $params['email'], false, $errors); + global $conf; + + if ($conf['double_password_type_in_admin']) + { + if ($params['password'] != $params['password_confirm']) + { + return new PwgError(WS_ERR_INVALID_PARAM, l10n('The passwords do not match')); + } + } + + $user_id = register_user( + $params['username'], + $params['password'], + $params['email'], + false, // notify admin + $errors, + $params['send_password_by_mail'] + ); if (!$user_id) { diff --git a/register.php b/register.php index 4e55fe70d..a4c8f910b 100644 --- a/register.php +++ b/register.php @@ -60,40 +60,20 @@ if (isset($_POST['submit'])) $page['errors'][] = l10n('The passwords do not match'); } - register_user($_POST['login'], - $_POST['password'], - $_POST['mail_address'], - true, - $page['errors']); + register_user( + $_POST['login'], + $_POST['password'], + $_POST['mail_address'], + true, + $page['errors'], + isset($_POST['send_password_by_mail']) + ); if (count($page['errors']) == 0) { // email notification - if (isset($_POST['send_password_by_mail']) and isset($_POST['mail_address'])) + if (isset($_POST['send_password_by_mail']) and email_check_format($_POST['mail_address'])) { - include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); - - $keyargs_content = array( - get_l10n_args('Hello %s,', $_POST['login']), - get_l10n_args('Thank you for registering at %s!', $conf['gallery_title']), - get_l10n_args('', ''), - get_l10n_args('Here are your connection settings', ''), - get_l10n_args('Username: %s', $_POST['login']), - get_l10n_args('Password: %s', $_POST['password']), - get_l10n_args('Email: %s', $_POST['mail_address']), - get_l10n_args('', ''), - get_l10n_args('If you think you\'ve received this email in error, please contact us at %s', get_webmaster_mail_address()), - ); - - pwg_mail( - $_POST['mail_address'], - array( - 'subject' => '['.$conf['gallery_title'].'] '.l10n('Registration'), - 'content' => l10n_args($keyargs_content), - 'content_format' => 'text/plain', - ) - ); - $_SESSION['page_infos'][] = l10n('Successfully registered, you will soon receive an email with your connection settings. Welcome!'); } @@ -826,7 +826,9 @@ function ws_addDefaultMethods( $arr ) array( 'username' => array(), 'password' => array('default'=>null), + 'password_confirm' => array('flags'=>WS_PARAM_OPTIONAL), 'email' => array('default'=>null), + 'send_password_by_mail' => array('default'=>false, 'type'=>WS_TYPE_BOOL), ), '<b>Admin & POST only.</b> Registers a new user.', null, |