Beispiel #1
0
     //check of post operation is not empty. if a field is empty display message indicating the field is required
     foreach ($err as $key => $value) {
         if (empty($_POST[$key])) {
             $valid = false;
             $err[$key] = "This field is required";
         }
     }
 }
 if (isset($_POST['new_password']) && isset($_POST['password_confirm'])) {
     // check if the password and confirmation match, if not display message uponn post operation
     if ($valid and $_POST["password_confirm"] != $_POST["new_password"]) {
         $err["password_confirm"] = "Passwords must match";
         $valid = false;
     }
 }
 $form->load_by_pk($_SESSION['usr_id']);
 //load the data from the table by using the user type
 $panel_head = false;
 if ($valid && isset($_POST['new_password']) && isset($_POST['password_confirm']) && isset($_POST['old_password'])) {
     //if old and new password are set, check if the old
     $pass = new PasswordField();
     //password matches the one that's currently in the database, if so check if the newpassowrd and the confirmation match. if they do, save it to the database
     $pass->new_password($_POST['old_password']);
     if ($pass->value == $form->fields['password']->value) {
         if ($_POST['new_password'] == $_POST['password_confirm']) {
             $form->fields['password']->new_password($_POST['new_password']);
             if ($form->save()) {
                 $panel_head = true;
             } else {
                 echo "Password not changed.";
             }
Beispiel #2
0
} else {
    header('Location: index.php');
}
include "models/admin_model.php";
$admins = new AdminForm();
$to_edit = new AdminForm();
if (isset($_POST['add_admin'])) {
    $to_edit->load_from_post();
    $valid = $to_edit->validate();
    if ($_POST['password2'] != $to_edit->fields['password']->value) {
        $valid = false;
    } else {
        $to_edit->fields['password']->hash_pass();
    }
    if ($valid) {
        $to_edit->save();
    }
} elseif (isset($_POST['admin_id'])) {
    $to_edit->load_by_pk($_POST['admin_id']);
    $to_edit->load_from_post();
    $valid = $to_edit->validate();
    if ($valid) {
        $to_edit->save();
        $to_edit = new AdminForm();
    }
}
$admins->load_by_filter("");
$page_title = "Manage Administrators";
$panel_heading = "Manage Administrators";
$page_body = "manage_admins_template.php";
include "templates/template.php";