mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-08-07 09:13:02 +02:00
related to #2158 update user and guest pop in
- Implementation of a new modal for modifying a user or guest - Addition of a function to allow plugins to add a tab to the new user modal - Fix bug: "badger-number" is updated when a user is added or deleted - Fix bug: When the user who is editing has permissions to delete the user he is modifying, the delete icon is now displayed correctly - Added a new api method for modifying the main user and generating a link to reset a password - Passed $conf[‘webmaster_id’] in database configuration
This commit is contained in:
@@ -579,9 +579,6 @@ $conf['default_user_id'] = $conf['guest_id'];
|
||||
// if language isn't available PHPWG_DEFAULT_LANGUAGE is used as previously
|
||||
$conf['browser_language'] = true;
|
||||
|
||||
// webmaster_id : webmaster'id.
|
||||
$conf['webmaster_id'] = 1;
|
||||
|
||||
// does the guest have access ?
|
||||
// (not a security feature, set your categories "private" too)
|
||||
// If false it'll be redirected from index.php to identification.php
|
||||
|
||||
@@ -1004,6 +1004,43 @@ function pwg_send_mail_test($success, $mail, $args)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate content mail for reset password
|
||||
*
|
||||
* Return the content mail to send
|
||||
* @since 15
|
||||
* @param string $username
|
||||
* @param string $reset_password_link
|
||||
* @param string $gallery_title
|
||||
* @return string mail content
|
||||
*/
|
||||
function pwg_generate_reset_password_mail($username, $reset_password_link, $gallery_title)
|
||||
{
|
||||
set_make_full_url();
|
||||
|
||||
$message = l10n('Someone requested that the password be reset for the following user account:') . "\r\n\r\n";
|
||||
$message.= l10n(
|
||||
'Username "%s" on gallery %s',
|
||||
$username,
|
||||
get_gallery_home_url()
|
||||
);
|
||||
$message.= "\r\n\r\n";
|
||||
$message.= l10n('To reset your password, visit the following address:') . "\r\n";
|
||||
$message.= $reset_password_link;
|
||||
$message.= "\r\n\r\n";
|
||||
$message.= l10n('If this was a mistake, just ignore this email and nothing will happen.')."\r\n";
|
||||
|
||||
unset_make_full_url();
|
||||
|
||||
$message = trigger_change('render_lost_password_mail_content', $message);
|
||||
|
||||
return array(
|
||||
'subject' => '['.$gallery_title.'] '.l10n('Password Reset'),
|
||||
'content' => $message,
|
||||
'email_format' => 'text/plain',
|
||||
);
|
||||
}
|
||||
|
||||
trigger_notify('functions_mail_included');
|
||||
|
||||
?>
|
||||
|
||||
@@ -1733,6 +1733,41 @@ function deactivate_password_reset_key($user_id)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate reset password link
|
||||
*
|
||||
* @since 15
|
||||
* @param int $user_id
|
||||
* @param string $user_email
|
||||
* @return array activation_key and reset password link
|
||||
*/
|
||||
function generate_reset_password_link($user_id)
|
||||
{
|
||||
$activation_key = generate_key(20);
|
||||
|
||||
list($expire) = pwg_db_fetch_row(pwg_query('SELECT ADDDATE(NOW(), INTERVAL 1 HOUR)'));
|
||||
|
||||
single_update(
|
||||
USER_INFOS_TABLE,
|
||||
array(
|
||||
'activation_key' => pwg_password_hash($activation_key),
|
||||
'activation_key_expire' => $expire,
|
||||
),
|
||||
array('user_id' => $user_id)
|
||||
);
|
||||
|
||||
set_make_full_url();
|
||||
|
||||
$reset_password_link = get_root_url().'password.php?key='.$activation_key;
|
||||
|
||||
unset_make_full_url();
|
||||
|
||||
return array(
|
||||
'activation_key' => $activation_key,
|
||||
'reset_password_link' => $reset_password_link,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last visit (datetime) of a user, based on history table
|
||||
*
|
||||
|
||||
@@ -961,4 +961,108 @@ SELECT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* API method
|
||||
* Returns the reset password link of the current user
|
||||
* @since 15
|
||||
* @param mixed[] $params
|
||||
* @option int user_id
|
||||
* @option string pwg_token
|
||||
* @option boolean send_by_mail
|
||||
*/
|
||||
function ws_users_generate_reset_password_link($params, &$service)
|
||||
{
|
||||
global $user, $conf;
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||
include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
|
||||
|
||||
if (get_pwg_token() != $params['pwg_token'])
|
||||
{
|
||||
return new PwgError(403, 'Invalid security token');
|
||||
}
|
||||
|
||||
// check if user exist
|
||||
if (get_username($params['user_id']) === false)
|
||||
{
|
||||
return new PwgError(WS_ERR_INVALID_PARAM, 'This user does not exist.');
|
||||
}
|
||||
|
||||
$user_lost = getuserdata($params['user_id']);
|
||||
|
||||
// Cannot perform this action for a guest or generic user
|
||||
if (is_a_guest($user_lost['status']) or is_generic($user_lost['status']))
|
||||
{
|
||||
return new PwgError(403, 'Password reset is not allowed for this user');
|
||||
}
|
||||
|
||||
// Only webmaster can perform this action for another webmaster
|
||||
if ('admin' === $user['status'] && 'webmaster' === $user_lost['status'])
|
||||
{
|
||||
return new PwgError(403, 'You cannot perform this action');
|
||||
}
|
||||
|
||||
$generate_link = generate_reset_password_link($params['user_id']);
|
||||
$send_by_mail_response = null;
|
||||
|
||||
if ($params['send_by_mail'] and !empty($user_lost['email']))
|
||||
{
|
||||
$email_params = pwg_generate_reset_password_mail($user_lost['username'], $generate_link['reset_password_link'], $conf['gallery_title']);
|
||||
// Here we remove the display of errors because they prevent the response from being parsed
|
||||
if (@pwg_mail($user_lost['email'], $email_params))
|
||||
{
|
||||
$send_by_mail_response = 'Mail sent at : ' . $user_lost['email'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$send_by_mail_response = false;
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'generated_link' => $generate_link['reset_password_link'],
|
||||
'send_by_mail' => $send_by_mail_response,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* API method
|
||||
* Set a user as the main user
|
||||
* @since 15
|
||||
* @param mixed[] $params
|
||||
* @option int user_id
|
||||
* @option string pwg_token
|
||||
*/
|
||||
function ws_set_main_user($params, &$service)
|
||||
{
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||
|
||||
// check if not webmaster
|
||||
if (!is_webmaster())
|
||||
{
|
||||
return new PwgError(403, 'You cannot perform this action');
|
||||
}
|
||||
|
||||
//check pwg_token
|
||||
if (get_pwg_token() != $params['pwg_token'])
|
||||
{
|
||||
return new PwgError(403, 'Invalid security token');
|
||||
}
|
||||
|
||||
// checl if user exist
|
||||
if (get_username($params['user_id']) === false)
|
||||
{
|
||||
return new PwgError(WS_ERR_INVALID_PARAM, 'This user does not exist.');
|
||||
}
|
||||
|
||||
$new_main_user = getuserdata($params['user_id']);
|
||||
|
||||
// check if the user to set as main user is not webmaster
|
||||
if ('webmaster' !== $new_main_user['status'])
|
||||
{
|
||||
return new PwgError(403, 'This user cannot become a main user because he is not a webmaster.');
|
||||
}
|
||||
|
||||
conf_update_param('webmaster_id', $params['user_id']);
|
||||
return 'The main user has been changed.';
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user