From c3f4fb63f0c18cc70b32c658198dff3cc105c682 Mon Sep 17 00:00:00 2001
From: Gina Haeussge <osd@foosel.net>
Date: Mon, 1 Sep 2008 19:00:41 +0200
Subject: [PATCH] Usermanager: Add autogeneration of password

    The password of a newly added user account is now autogenerated
    if the backend supports it, the password field is left empty and
    the notification of the user is enabled. A corresponding note was
    added to the dialog to inform admins about this behaviour.

darcs-hash:20080901170041-2b4f5-e66173fe74395a1dab8e6deaf59541d258d4bacb.gz
---
 lib/plugins/usermanager/admin.php        | 10 +++++++++-
 lib/plugins/usermanager/lang/de/lang.php |  1 +
 lib/plugins/usermanager/lang/en/lang.php |  1 +
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/plugins/usermanager/admin.php b/lib/plugins/usermanager/admin.php
index 1d35c7abe..8f1016cbf 100644
--- a/lib/plugins/usermanager/admin.php
+++ b/lib/plugins/usermanager/admin.php
@@ -283,6 +283,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
         $this->_htmlInputField($cmd."_usergroups","usergroups",$this->lang["user_groups"],$groups,$this->_auth->canDo("modGroups"),$indent+6);
 
         if ($this->_auth->canDo("modPass")) {
+          $notes[] = $this->lang['note_pass'];
           if ($user) {
             $notes[] = $this->lang['note_notify'];
           }
@@ -341,7 +342,14 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
 
         list($user,$pass,$name,$mail,$grps) = $this->_retrieveUser();
         if (empty($user)) return false;
-        if (empty($pass) || empty($name) || empty($mail)){
+        if (empty($pass)){
+          if(!empty($_REQUEST['usernotify'])){
+            $pass = auth_pwgen();
+          } else {
+            return false;
+          }
+        }
+        if (empty($name) || empty($mail)){
           msg($this->lang['add_fail'], -1);
           return false;
         }
diff --git a/lib/plugins/usermanager/lang/de/lang.php b/lib/plugins/usermanager/lang/de/lang.php
index 71742b397..bef64eea6 100644
--- a/lib/plugins/usermanager/lang/de/lang.php
+++ b/lib/plugins/usermanager/lang/de/lang.php
@@ -43,6 +43,7 @@ $lang['edit_usermissing']      = 'Der ausgewählte Nutzer wurde nicht gefunden.
 $lang['user_notify']           = 'Nutzer benachrichtigen';
 $lang['note_notify']           = 'Benachrichtigungsmails werden nur versandt wenn ein neues Passwort vergeben wurde.';
 $lang['note_group']            = 'Neue Nutzer werden der Standard-Gruppe (%s) hinzugefügt, wenn keine Gruppe angegeben wurde.';
+$lang['note_pass']             = 'Das Password wird automatisch generiert wenn das entsprechende Feld leergelassen wird und die Benachrichtigung des Nutzers aktiviert ist.';
 $lang['add_ok']                = 'Nutzer erfolgreich angelegt';
 $lang['add_fail']              = 'Nutzer konnte nicht angelegt werden';
 $lang['notify_ok']             = 'Benachrichtigungsmail wurde versandt';
diff --git a/lib/plugins/usermanager/lang/en/lang.php b/lib/plugins/usermanager/lang/en/lang.php
index f15e38f2a..189a1db20 100644
--- a/lib/plugins/usermanager/lang/en/lang.php
+++ b/lib/plugins/usermanager/lang/en/lang.php
@@ -50,6 +50,7 @@ $lang['edit_usermissing'] = 'Selected user not found, the specified user name ma
 $lang['user_notify'] = 'Notify user';
 $lang['note_notify'] = 'Notification emails are only sent if the user is given a new password.';
 $lang['note_group'] = 'New users will be added to the default group (%s) if no group is specified.';
+$lang['note_pass'] = 'The password will be autogenerated if the field is left empty and notification of the user is enabled.';
 $lang['add_ok'] = 'User added successfully';
 $lang['add_fail'] = 'User addition failed';
 $lang['notify_ok'] = 'Notification email sent';
-- 
GitLab