Code

Updated pwd class
[gosa.git] / plugins / personal / password / main.inc
index 76704c1e5ba94e45f1533dfbdd6ec6ca39667eb7..b8135bc6a271dbc69fe6da47a39080380cd4e763 100644 (file)
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-if (!$remove_lock){
-
-  /* Assign headline image */
-  $smarty->assign ('headimage', get_template_path('images/password.png'));
-  $display= "";
+/* Clear display */
+$display= "";
 
-  /* Check for interaction */
-  if ($_SERVER["REQUEST_METHOD"] == "POST"){
-    if (isset($_POST['password_finish'])){
-      $message= array();
-
-      /* Is current password correct? */
-      if ($_POST['current_password'] != ""){
-        $tldap = new LDAP($ui->dn, $_POST['current_password'],
-            $config->current['SERVER'],
-            isset($config->current['RECURSIVE']) && $config->current['RECURSIVE'] == "true",
-            isset($config->current['TLS'])
-            && $config->current['TLS'] == "true");
-        if ($tldap->error != "Success"){
-          $message[]= _("The password you've entered as your current password doesn't match the real one.");
-        }
-      } else {
-        $message[]= _("You need to specify your current password in order to proceed.");
-      }
+if (!$remove_lock){
 
-      /* Do new and repeated password fields match? */
-      if ($_POST['new_password'] != $_POST['repeated_password']){
-        $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
-      } else {
-        if ($_POST['new_password'] == ""){
-          $message[]= _("The password you've entered as 'New password' is empty.");
-        }
-      }
+  /* Reset requested? */
+  if (isset($_POST['edit_cancel']) ||
+      (isset($_GET['reset']) && $_GET['reset'] == 1)){
 
-      /* Password policy fulfilled? */
-      if (isset($config->data['MAIN']['PWDIFFER'])){
-        $l= $config->data['MAIN']['PWDIFFER'];
-        if (substr($_POST['current_password'], 0, $l) == substr($_POST['new_password'], 0, $l)){
-          $message[]= _("The password used as new and current are too similar.");
-        }
-      }
-      if (isset($config->data['MAIN']['PWMINLEN'])){
-        if (strlen($_POST['new_password']) < $config->data['MAIN']['PWMINLEN']){
-          $message[]= _("The password used as new is to short.");
-        }
-      }
+    del_lock ($ui->dn);
+    sess_del ('edit');
+    sess_del ('password');
+  }
 
-      $ca= get_permissions ($ui->dn, $ui->subtreeACL);
-      $ca= get_module_permission($ca, "user", $ui->dn);
-      if (chkacl($ca, "password") != ""){
-        $message[]= _("You have no permissions to change your password.");
-      }
+  /* Create password object on demand */
+  if (!isset($_SESSION['password']) || (isset($_GET['reset']) && $_GET['reset'] == 1)){
+    $_SESSION['password']= new password ($config, $ui->dn);
+  }
+  $password= $_SESSION['password'];
 
-      if (count ($message) != 0){
-        /* Show error message and continue editing */
-        show_errors($message);
-      } else {
+  /* Execute formular */
+  $display.= $password->execute ();
 
-        /* Passed quality check, just try to change the password now */
-        $output= "";
-        if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
-          exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$ui->username." ".
-               $_POST['current_password']." ".$_POST['new_password'], $resarr);
-          if(count($resarr) > 0) {
-            $output= join('\n', $resarr);
-          }
-        }
-        if ($output != ""){
-          $message[]= _("External password changer reported a problem: ".$output);
-          show_errors($message);
-        } else {               
-          change_password ($ui->dn, $_POST['new_password']);
-          gosa_log ("User/password has been changed");
-          $ui->password= $_POST['new_password'];
-          $_SESSION['ui']= $ui;
-          $display= $smarty->fetch(get_template_path("changed.tpl", TRUE));
-        }
-      }
-    }
-  }
+  /* Page header*/
+  $display= print_header(get_template_path('images/password.png'),
+                         _("Password settings"), "").$display;
 
-  if ($display == ""){
-    $display= $smarty->fetch(get_template_path("password.tpl", TRUE));
-  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: