related to #2165 new add user popin

- add field for add user
- in the `pwg.users.add` method, the params `send_password_by_mail` does nothing anymore. Because we no longer want to send passwords in clear text.
- in the `pwg.users.add` add a new `auto_password` parameter to generate a random password when a user is created
- use this parameter (`auto_password`) in user_list.js
- change mail content et password page on first login
This commit is contained in:
Linty
2024-06-28 18:49:34 +02:00
parent 834b339860
commit c8d7503d4e
9 changed files with 385 additions and 119 deletions
+37
View File
@@ -1041,6 +1041,43 @@ function pwg_generate_reset_password_mail($username, $reset_password_link, $gall
);
}
/**
* Generate content mail for set 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_set_password_mail($username, $set_password_link, $gallery_title)
{
set_make_full_url();
$message = l10n('Someone requested that the password be set 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 set your password, visit the following address:') . "\r\n";
$message.= $set_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' => l10n('Welcome to ') . '['.$gallery_title.']',
'content' => $message,
'email_format' => 'text/plain',
);
}
trigger_notify('functions_mail_included');
?>
+22
View File
@@ -1905,4 +1905,26 @@ function userprefs_get_param($param, $default_value=null)
return $default_value;
}
/**
* See if this is the first time the user has logged on
*
* @since 15
* @param int $user_id
* @return bool true if first connexion else false
*/
function first_connexion($user_id)
{
$query = '
SELECT COUNT(*)
FROM '.ACTIVITY_TABLE.'
WHERE action = \'login\' and performed_by = '.$user_id.'';
list($logged_in) = pwg_db_fetch_row(pwg_query($query));
if ($logged_in > 0)
{
return false;
}
return true;
}
?>
+15 -2
View File
@@ -392,13 +392,18 @@ function ws_users_add($params, &$service)
}
}
if ($params['auto_password'])
{
$params['password'] = generate_key(rand(15, 20));
}
$user_id = register_user(
$params['username'],
$params['password'],
$params['email'],
false, // notify admin
$errors,
$params['send_password_by_mail']
false // $params['send_password_by_mail']
);
if (!$user_id)
@@ -1006,7 +1011,15 @@ function ws_users_generate_reset_password_link($params, &$service)
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']);
$first_login = first_connexion($params['user_id']);
if ($first_login)
{
$email_params = pwg_generate_set_password_mail($user_lost['username'], $generate_link['reset_password_link'], $conf['gallery_title']);
}
else
{
$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))
{