Пример #1
0
<?php

require_once 'libcollection.php';
startSession();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    /***read book****/
    if (isset($_POST['delete'])) {
        delete_all_user_books();
        delete_user();
        logout();
        header('location: index.php');
        /***edit book***/
    } else {
        if (validatePass($_POST['password'])) {
            update_user_pass($_POST['password']);
        } else {
            $_SESSION['message'] = 'Password must contain at least 1 character and no more than 20 characters.<br/>';
            $_SESSION['password'] = $_POST['password'];
        }
        header('location: accountsettings.php');
    }
}
Пример #2
0
        db_connect();
        if (is_username_unique($usr)) {
            db_add_new_user($usr, $pass);
            db_close();
            $_SESSION['username'] = $usr;
            header('Location: home.php');
        } else {
            $_SESSION['message'] = '';
            $_SESSION['message'] = $usr . ' already exists';
        }
        db_close();
    }
}
if (!isset($_SESSION['username'])) {
    $_SESSION['user'] = $usr;
    $_SESSION['pass'] = $pass;
    $_SESSION['conf'] = $passConfirm;
    if (!isset($_SESSION['message'])) {
        $_SESSION['message'] = '';
    }
    if (!validatePass($pass)) {
        $_SESSION['message'] .= 'Password must contain at least 1 character and no more than 20 characters.<br/>';
    }
    if (!validateEmail($usr)) {
        $_SESSION['message'] .= 'Not a valid email.<br/>';
    }
    if ($pass != $passConfirm) {
        $_SESSION['message'] .= 'Password fields do not match.<br/>';
    }
    header('Location: newuser.php');
}
Пример #3
0
 private function edit()
 {
     if (empty($_GET['id'])) {
         $this->show_all();
     } else {
         if (empty($_POST)) {
             $id_user = $_GET['id'];
             $user = $this->model->get($id_user);
             if ($user) {
                 $section = file_get_contents('Views/User/edit.html');
                 //$rolName = $user['rol'] == 'admin' ? 'Administrador' : ($user['rol'] == 'employee' ? 'Empleado' : 'Cliente');
                 $dicc = array('{id}' => $user['id_user'], '{nombre}' => $user['user_name'], '{password}' => $user['password'], '{email}' => $user['user_email']);
                 $section = strtr($section, $dicc);
                 $this->template($section);
             } else {
                 echo 'no existe ese usuario para editarlo';
             }
         } else {
             $id_user = $_GET['id'];
             require_once "Controllers/Validaciones.php";
             $name = validateNameUser($_POST['name']);
             $password = md5(validatePass($_POST['password']));
             $password_confirm = md5(validatePass($_POST['password_confirm']));
             $email = validateEmail($_POST['email']);
             $rol = validateName($_POST['rol']);
             $join = isset($_POST['join']) ? $_POST['join'] : NULL;
             $option = $rol == 'admin' ? 'id_employee' : ($rol == 'employee' ? 'id_employee' : ($rol == 'client' ? 'id_client' : NULL));
             $user = new User($name, $password, $email, $rol);
             $result = $this->model->edit($user, $id_user, $option, $join);
             if ($result) {
                 $this->show_message("success", "El usuario se edito correctamente");
             } else {
                 $this->show_message("danger", "No se edito no puede haber duplicados en el nombre o el correo");
             }
         }
     }
 }
Пример #4
0
            echo "<script>\n                        \$('#alert').addClass('alert alert-danger').html('Password must be a minimum of 8 characters!');\n                  </script>";
        }
        return false;
    } else {
        return true;
    }
}
$file = "users.json";
$mail = $_POST["mail"];
$pass = $_POST["pass"];
$sex = $_POST["sex"];
$subscribe = $_POST["subscribe"];
if (empty($subscribe)) {
    $subscribe = "no";
}
if (!empty($mail) && !empty($pass) && !empty($sex) && validateMail($mail) && validatePass($pass)) {
    $formData = array("mail" => $mail, "pass" => $pass, "sex" => $sex, "subscribe" => $subscribe);
    $arrayData = array();
    if (file_exists($file)) {
        $json = file_get_contents($file);
        $arrayData = json_decode($json, true);
    }
    $arrayData[] = $formData;
    $json = json_encode($arrayData, JSON_PRETTY_PRINT);
    if (file_put_contents($file, $json)) {
        echo "<script>\n            \$('#alert').addClass('alert alert-success').html('You have successfully registered!');\n            \$('#mail').val('');\n            \$('#pass').val('');\n            \$('input[name=sex][value=" . $sex . "]').attr('checked', false);" . "\n            \$('input[name=subscribe][value=" . $subscribe . "]').attr('checked', false);" . "\n          </script>";
    }
} else {
    echo "<script>\n            \$('#mail').val('{$mail}');\n            \$('#pass').val('{$pass}');\n            \$('input[name=sex][value=" . $sex . "]').attr('checked', true);" . "\n            \$('input[name=subscribe][value=" . $subscribe . "]').attr('checked', true);" . "\n          </script>";
    if (!validateMail($mail) && !empty($mail)) {
        echo "<script>\n                    \$('#alert').addClass('alert alert-danger').html('Incorrect e-mail address!');\n              </script>";
Пример #5
0
        }
        if (!$lowerCase) {
            $_SESSION['reg_error'] = 'Password must contain at least one lowercase character!';
        }
        if (!$number) {
            $_SESSION['reg_error'] = 'Password must contain at least 1 number!';
        }
        if (strlen($pass) < 8) {
            $_SESSION['reg_error'] = 'Password must be a minimum of 8 characters!';
        }
        return false;
    } else {
        return true;
    }
}
if (isset($mail) && isset($pass) && isset($sex) && validateMail($mail) && validatePass($pass)) {
    $formData = array("mail" => $mail, "pass" => $pass, "sex" => $sex, "subscribe" => $subscribe, "avatar" => $path);
    $arrayData = array();
    $json = file_get_contents($file);
    $arrayData = json_decode($json, true);
    $arrayData[] = $formData;
    $json = json_encode($arrayData, JSON_PRETTY_PRINT);
} else {
    $correct_reg = 0;
    if (!validateMail($mail) && isset($mail)) {
        $_SESSION['reg_error'] = 'Incorrect e-mail address!';
    }
    if (empty($sex)) {
        $_SESSION['reg_error'] = 'Choose your sex!';
    }
}