Exemplo n.º 1
0
function addAdminUser()
{
    $controller = new ControllerAuthentication();
    if (!$controller->checkUsername($_POST['username'])) {
        $itm = new Authentication();
        $itm->name = trim(strip_tags($_POST['name']));
        $itm->username = trim(strip_tags($_POST['username']));
        $pass = trim(strip_tags($_POST['password']));
        $password_confirm = trim(strip_tags($_POST['password_confirm']));
        $itm->password = md5($pass);
        if (strlen($pass) < 8) {
            echo "<script >alert('Password field must be atleast 8 alphanumeric characters.');</script>";
        } else {
            if ($pass != $password_confirm) {
                echo "<script >alert('Password does not match.');</script>";
            } else {
                $controller->insertAccessUser($itm);
                echo "<script type='text/javascript'>location.href='admin_access.php';</script>";
            }
        }
    } else {
        echo "<script >alert('Username already taken.');</script>";
    }
}
$controller = new ControllerAuthentication();
if (isset($_POST['submit'])) {
    if (!$controller->checkUsername($_POST['username'])) {
        $itm = new Authentication();
        $itm->name = trim(strip_tags($_POST['name']));
        $itm->username = trim(strip_tags($_POST['username']));
        $pass = trim(strip_tags($_POST['password']));
        $password_confirm = trim(strip_tags($_POST['password_confirm']));
        $itm->password = md5($pass);
        if (strlen($pass) < 8) {
            echo "<script >alert('Password field must be atleast 8 alphanumeric characters.');</script>";
        } else {
            if ($pass != $password_confirm) {
                echo "<script >alert('Password does not match.');</script>";
            } else {
                $controller->insertAccessUser($itm);
                echo "<script type='text/javascript'>location.href='admin_access.php';</script>";
            }
        }
    } else {
        echo "<script >alert('Username already taken.');</script>";
    }
}
?>


<!DOCTYPE html>
<html lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">