Skip to content

Commit

Permalink
Merge pull request #111 from DasunThathsara/dasun
Browse files Browse the repository at this point in the history
Update table
  • Loading branch information
DasunThathsara authored Oct 31, 2023
2 parents 2f0db39 + 36812d7 commit 7b81b8c
Show file tree
Hide file tree
Showing 5 changed files with 314 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function history(){
$this->view('driver/history', $vehicles);
}

// ------------------------ Bookings ------------------------
// ------------------------ Rating ------------------------
public function rating(){
$vehicles = $this->driverModel->viewVehicles();

Expand Down
208 changes: 208 additions & 0 deletions app/controllers/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,109 @@ public function register(){
$this->view('users/register', $data);
}

public function parkingOwnerRegister(){
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
// Submitted form data
// input data
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);

$data = [
'name' => trim($_POST['name']),
'email' => trim($_POST['email']),
'password' => trim($_POST['password']),
'username' => trim($_POST['username']),
'confirm_password' => trim($_POST['confirm_password']),
'user_type' => trim($_POST['user_type']),
'contact_no' => trim($_POST['contact_no']),
'err' => ''
];

// Validate data
// Validate name
if (empty($data['name'])){
$data['err'] = 'Please enter name';
}

// Validate email
if (empty($data['email'])){
$data['err'] = 'Please enter email';
} else {
// Check email
if ($this->userModel->findUserByEmail($data['email'])){
$data['err'] = 'Email is already taken';
}
}

// Validate username
if (empty($data['username'])){
$data['err'] = 'Please enter username';
} else {
// Check email
if ($this->userModel->findUserByUsername($data['username'])){
$data['err'] = 'Username is already taken';
}
}

// Validate password
if (empty($data['password'])){
$data['err'] = 'Please enter password';
} elseif (strlen($data['password']) < 6){
$data['err'] = 'Password must be at least 6 characters';
}

// Validate confirm password
if (empty($data['confirm_password'])){
$data['err'] = 'Please confirm password';
} else {
if ($data['password'] != $data['confirm_password']){
$data['err'] = 'Passwords do not match';
}
}

// Validate user type
if (empty($data['user_type'])){
$data['err'] = 'Please select user type';
}

// Validate contact number
if (empty($data['contact_no'])){
$data['err'] = 'Please enter contact number';
}

// Validation is completed and no error found
if (empty($data['err'])){
// Hash password
$data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);

// Register user
if ($this->userModel->register($data)){
redirect('users/login');
} else {
die('Something went wrong');
}
} else {
// Load view with errors
$this->view('users/parkingOwnerRegister', $data);
}

} else {
// Initial form data
$data = [
'name' => '',
'email' => '',
'username' => '',
'password' => '',
'confirm_password' => '',
'user_type' => '',
'contact_no' => '',
'err' => '',
];

// Load view
$this->view('users/parkingOwnerRegister', $data);
}
}

public function driverRegister(){
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
// Submitted form data
Expand Down Expand Up @@ -114,6 +217,111 @@ public function driverRegister(){
}
}

public function merchandiserRegister(){
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
// Submitted form data
// input data
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);

$data = [
'name' => trim($_POST['name']),
'email' => trim($_POST['email']),
'password' => trim($_POST['password']),
'username' => trim($_POST['username']),
'confirm_password' => trim($_POST['confirm_password']),
'user_type' => trim($_POST['user_type']),
'contact_no' => trim($_POST['contact_no']),
'website' => trim($_POST['website']),
'website' => trim($_POST['website']),
'err' => ''
];

// Validate data
// Validate name
if (empty($data['name'])){
$data['err'] = 'Please enter name';
}

// Validate email
if (empty($data['email'])){
$data['err'] = 'Please enter email';
} else {
// Check email
if ($this->userModel->findUserByEmail($data['email'])){
$data['err'] = 'Email is already taken';
}
}

// Validate username
if (empty($data['username'])){
$data['err'] = 'Please enter username';
} else {
// Check email
if ($this->userModel->findUserByUsername($data['username'])){
$data['err'] = 'Username is already taken';
}
}

// Validate password
if (empty($data['password'])){
$data['err'] = 'Please enter password';
} elseif (strlen($data['password']) < 6){
$data['err'] = 'Password must be at least 6 characters';
}

// Validate confirm password
if (empty($data['confirm_password'])){
$data['err'] = 'Please confirm password';
} else {
if ($data['password'] != $data['confirm_password']){
$data['err'] = 'Passwords do not match';
}
}

// Validate user type
if (empty($data['user_type'])){
$data['err'] = 'Please select user type';
}

// Validate contact number
if (empty($data['contact_no'])){
$data['err'] = 'Please enter contact number';
}

// Validation is completed and no error found
if (empty($data['err'])){
// Hash password
$data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);

// Register user
if ($this->userModel->register($data)){
redirect('users/login');
} else {
die('Something went wrong');
}
} else {
// Load view with errors
$this->view('users/merchandiserRegister', $data);
}

} else {
// Initial form data
$data = [
'name' => '',
'email' => '',
'username' => '',
'password' => '',
'confirm_password' => '',
'user_type' => '',
'contact_no' => '',
'err' => '',
];

// Load view
$this->view('users/merchandiserRegister', $data);
}
}

public function login(){
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
// Form is submitting
Expand Down
1 change: 0 additions & 1 deletion app/models/DriverModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public function updateVehicle($data): bool
$this->db->bind(':id', $_SESSION['user_id']);


print_r($data);
// Execute
if ($this->db->execute()){
return true;
Expand Down
57 changes: 57 additions & 0 deletions app/views/users/merchandiserRegister.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php require APPROOT.'/views/inc/header.php'; ?>
<div class="form-container" style="margin-top: 10vh;">
<h1>Sign up</h1>
<?php if (!empty($data['err'])){?>
<div class="error-msg">
<span class="form-invalid"><?php echo $data["err"] ?></span>
</div>
<?php } ?>

<form action="<?php echo URLROOT ?>/users/register" method="post">
<!-- Username -->
<input type="text" name="username" id="username" required value="<?php echo $data['username'] ?>" placeholder="Username" />

<!-- Name -->
<input type="text" name="name" id="name" required value="<?php echo $data['name'] ?>" placeholder="Name" />

<!-- Email -->
<input type="email" name="email" id="email" required value="<?php echo $data['email'] ?>" placeholder="Email" />

<!-- Contact number -->
<input type="text" name="contact_no" id="contact_no" required value="<?php echo $data['contact_no'] ?>" placeholder="Contact number" />

<!-- Password -->
<input type="password" name="password" id="password" required placeholder="Password" />

<!-- Password Strength Indicator -->
<div class="strength-text" id="strength-text"></div>

<!-- Confirm Password -->
<input type="password" name="confirm_password" id="confirm_password" required placeholder="Confirm Password" />

<!-- Website -->
<input type="text" name="website" id="website" required value="<?php echo $data['website'] ?>" placeholder="Website" />

<!-- Merchant Name -->
<input type="text" name="merchantName" id="merchantName" required value="<?php echo $data['merchantName'] ?>" placeholder="merchantName" />

<!-- Type -->
<input type="text" name="type" id="type" required value="<?php echo $data['type'] ?>" placeholder="Type" />

<br><br>

<!-- Submit -->
<input type="submit" value="Submit">
</form>

<div class="other-options">
<p>If you already have an account? <a href="<?php echo URLROOT ?>/users/login">Login</a></p>
</div>
</div>

<!--?xml version="1.0" standalone="no"?-->
<div class="svg">
<img class="svg-1" src="<?php echo URLROOT ?>/images/svg-1.png" alt="">
<img class="svg-2" src="<?php echo URLROOT ?>/images/svg-7.png" alt="">
</div>
<?php require APPROOT.'/views/inc/footer.php'; ?>
48 changes: 48 additions & 0 deletions app/views/users/parkingOwnerRegister.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php require APPROOT.'/views/inc/header.php'; ?>
<div class="form-container" style="margin-top: 10vh;">
<h1>Sign up</h1>
<?php if (!empty($data['err'])){?>
<div class="error-msg">
<span class="form-invalid"><?php echo $data["err"] ?></span>
</div>
<?php } ?>

<form action="<?php echo URLROOT ?>/users/register" method="post">
<!-- Username -->
<input type="text" name="username" id="username" required value="<?php echo $data['username'] ?>" placeholder="Username" />

<!-- Name -->
<input type="text" name="name" id="name" required value="<?php echo $data['name'] ?>" placeholder="Name" />

<!-- Email -->
<input type="email" name="email" id="email" required value="<?php echo $data['email'] ?>" placeholder="Email" />

<!-- Contact number -->
<input type="text" name="contact_no" id="contact_no" required value="<?php echo $data['contact_no'] ?>" placeholder="Contact number" />

<!-- Password -->
<input type="password" name="password" id="password" required placeholder="Password" />

<!-- Password Strength Indicator -->
<div class="strength-text" id="strength-text"></div>

<!-- Confirm Password -->
<input type="password" name="confirm_password" id="confirm_password" required placeholder="Confirm Password" />

<br><br>

<!-- Submit -->
<input type="submit" value="Submit">
</form>

<div class="other-options">
<p>If you already have an account? <a href="<?php echo URLROOT ?>/users/login">Login</a></p>
</div>
</div>

<!--?xml version="1.0" standalone="no"?-->
<div class="svg">
<img class="svg-1" src="<?php echo URLROOT ?>/images/svg-1.png" alt="">
<img class="svg-2" src="<?php echo URLROOT ?>/images/svg-7.png" alt="">
</div>
<?php require APPROOT.'/views/inc/footer.php'; ?>

0 comments on commit 7b81b8c

Please sign in to comment.