function handleRegister() { //showLog("handleLogin"); // $ret = array('op' => 'register', 'msg' => 'Registration Successful', 'error_code' => '0'); $username = $_POST["username"]; $email = $_POST["email"]; $password = $_POST["password"]; $upass = md5(mysql_real_escape_string($_POST['password'])); $dao = new DAOuser(); // ensure that user with same email does not exist in database $user = $dao->getByEmail($email); // user already exists for give email if ($user != NULL) { $ret["error_code"] = "1"; $ret["msg"] = "Email '" . $email . "' already exists"; echo json_encode($ret); return; } // ensure that user with same username does not exist in database $user = $dao->getByUsername($username); // user already exists for give username if ($user != NULL) { $ret["error_code"] = "1"; $ret["msg"] = "Username '" . $username . "' already exists"; echo json_encode($ret); return; } $user = new user($_POST['username'], $upass, $_POST['email']); $dao->save($user); echo json_encode($ret); }
<?php session_start(); // check if user logged, else redirect to index page if (!isset($_SESSION['uid'])) { header("Location: index.php"); } include "db.php"; include "admin/class.user.dao.php"; $uid = $_SESSION['uid']; $dao = new DAOuser(); $user = $dao->get($uid); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> </head> <body> <nav class="navbar navbar-inverse"> <div style = "margin:auto;"> <a href="dashboard.php" class="navbar-brand">Dashboard </a> <a href="company.php" class="navbar-brand">Company </a> <a href="customer.php" class="navbar-brand">Customer </a> <a href="driver.php" class="navbar-brand">Driver </a> <ul class="nav navbar-nav">
alert("is_active can't be empty"); return false; } return true; } </script> <?php include "header.php"; include "class.user.dao.php"; ?> <form name = "frmUser" method="POST" action="save.user.php" onsubmit = "return validateUser();"> <table cellspacing="5" cellpadding="5"> <?php if (isset($_GET["id"])) { $dao = new DAOuser(); $vo = $dao->get($_GET["id"]); ?> <tr> <td> Username </td> <td><input type = "text" name = "username" value= "<?php echo $vo->username; ?> "/></td> </tr> <tr> <td> Password </td> <td><input type = "text" name = "password" value= "<?php echo $vo->password; ?> "/></td>
<?php session_start(); include "admin/class.user.dao.php"; include_once 'db.php'; // check if user already logged in, // then redirect to main page if (isset($_SESSION['uid']) != "") { header("Location: company.php"); } $email = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $dao = new DAOuser(); $user = $dao->getByEmailAndPassword($email, $password); // login failed if ($user == null) { //echo "<script>alert('Login Failed !!!!');</script>"; header("Location: index.php?ec=1"); } else { // login OK $_SESSION["uid"] = $user->uid; header("Location: dashboard.php"); }
<?php include "db.php"; include "class.user.dao.php"; $dao = new DAOuser(); $vo = new user($_POST["username"], $_POST["password"], $_POST["email"]); if (isset($_POST["uid"])) { $vo->uid = $_POST["uid"]; } $dao->save($vo); header("Location: user.php");
<?php include "class.user.dao.php"; include_once "header.php"; $dao = new DAOuser(); ?> <a href="form.user.php">Add user</a> <table border="1" width="100%" cellspacing = "5" cellpadding = "5"> <tr> <td>uid</td> <td>username</td> <td>password</td> <td>full_name</td> <td>email</td> <td>phone</td> <td>address</td> <td>creation_date</td> <td>is_active</td> <td><b>Edit</b></td> <td><b>Delete</b></td> </tr> <?php $rec_per_page = 10; if (isset($_GET['page'])) { $page = $_GET['page']; } else { $page = 1; } $limit1 = ($page - 1) * $rec_per_page; $limit2 = $page * $rec_per_page;
public function getValidUser(&$vo) { $dao = new DAOuser(); $limit1 = 1; $limit2 = $dao->getCount(); $vlist = $dao->getAll($limit1, $limit2); //ensure that username doesn't exist foreach ($vlist as $rec) { if ($rec->username == $vo->username or $rec->email == $vo->email) { $vuser = true; } else { // login OK $vuser = false; } } return $vuser; }
<?php session_start(); include_once 'db.php'; include "admin/class.user.dao.php"; $uname = mysql_real_escape_string($_POST['username']); $email = mysql_real_escape_string($_POST['email']); $upass = md5(mysql_real_escape_string($_POST['password'])); $password = mysql_real_escape_string($_POST['password']); // todo // if user already exists // return back to login page, with pt=reg, ec=2 $vo = new user($uname, $upass, $email); $dao = new DAOuser(); //check if the user name and email are unique $useremail = $dao->getByEmail($email); $userpass = $dao->getByPassword($password); //if a valid user then open customer page else display error if ($useremail == NULL or $userpass == NULL) { $dao->save($vo); header("Location: customer.php"); } else { header("Location: index.php?pt=reg&ec=2"); } ?>