user creation portal
This commit is contained in:
parent
2e21773018
commit
86bb50cc47
|
|
@ -8,7 +8,7 @@ class Routes extends \CSY2028\Routes {
|
|||
$this->setDbTables();
|
||||
$this->controllers = [
|
||||
"jobs" => new \jobs\controllers\Jobs($this->databaseTables["jobs"], $this->databaseTables["categories"], $this->databaseTables["applicants"]),
|
||||
"portal" => new \jobs\controllers\Portal($this->databaseTables["categories"], $this->databaseTables["jobs"], $this->databaseTables["applicants"]),
|
||||
"portal" => new \jobs\controllers\Portal($this->databaseTables["categories"], $this->databaseTables["jobs"], $this->databaseTables["applicants"], $this->databaseTables['users']),
|
||||
"user" => new \jobs\controllers\User($this->databaseTables["users"], $this->databaseTables["categories"])
|
||||
];
|
||||
$this->loginControllers = [
|
||||
|
|
|
|||
|
|
@ -4,12 +4,14 @@ class Portal {
|
|||
private $catsTable;
|
||||
private $jobsTable;
|
||||
private $appsTable;
|
||||
private $usersTable;
|
||||
private $vars;
|
||||
|
||||
public function __construct(\jobs\JobDatabaseTable $catsTable, \jobs\JobDatabaseTable $jobsTable, \jobs\JobDatabaseTable $appsTable) {
|
||||
public function __construct(\jobs\JobDatabaseTable $catsTable, \jobs\JobDatabaseTable $jobsTable, \jobs\JobDatabaseTable $appsTable, \jobs\JobDatabaseTable $usersTable) {
|
||||
$this->catsTable = $catsTable;
|
||||
$this->jobsTable = $jobsTable;
|
||||
$this->appsTable = $appsTable;
|
||||
$this->usersTable = $usersTable;
|
||||
$this->vars['cats'] = $this->catsTable->findAll();
|
||||
$this->vars['table'] = 'job_table.html.php';
|
||||
}
|
||||
|
|
@ -63,18 +65,19 @@ class Portal {
|
|||
}
|
||||
return $this->categories();
|
||||
}
|
||||
if (isset($_POST['user_id'])) {
|
||||
if($_POST['user_type'] == 'client') {
|
||||
$this->usersTable->delete('id', $_POST['user_id']);
|
||||
$jobs = $this->jobsTable->find(['clientId'], ['value0' => $_POST['user_id']]);
|
||||
foreach ($jobs as $job) {
|
||||
$this->jobsTable->delete('id', $job->id);
|
||||
}
|
||||
return $this->users();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function secondHomeSubmit() {
|
||||
|
||||
$this->vars['response'] = 'Update successful';
|
||||
return ['template' => 'response.html.php',
|
||||
'title' => 'Jo\'s Jobs- Success',
|
||||
'vars' => $this->vars
|
||||
];
|
||||
}
|
||||
|
||||
public function categories() {
|
||||
if ($_SESSION['userType'] == 'admin') {
|
||||
$this->vars['table'] = 'category_table.html.php';
|
||||
|
|
@ -95,8 +98,54 @@ class Portal {
|
|||
'vars' => $this->vars];
|
||||
}
|
||||
|
||||
public function edit() { //TODO: finish this function
|
||||
public function users() {
|
||||
if ($_SESSION['userType'] == 'admin') {
|
||||
$this->vars['table'] = 'user_table.html.php';
|
||||
$this->vars['users'] = $this->usersTable->findAll();
|
||||
return ['template' => 'portal.html.php',
|
||||
'title' => 'Jo\'s Jobs- Users',
|
||||
'vars' => $this->vars
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function addUser() {
|
||||
if ($_SESSION['userType'] == 'admin') {
|
||||
if (isset($_GET['user_id'])) {
|
||||
$this->vars['user'] = $this->usersTable->find(['id'], ['value0' => $_GET['user_id']])[0];
|
||||
$this->vars['update'] = true;
|
||||
}
|
||||
else {
|
||||
$this->vars['update'] = false;
|
||||
}
|
||||
return ['template' => 'user_add.html.php',
|
||||
'title' => 'Jo\'s Jobs- Edit user',
|
||||
'vars' => $this->vars
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function addUserSubmit() {
|
||||
if ($_SESSION['userType'] == 'admin') {
|
||||
$record = [
|
||||
'username' => $_POST['username'],
|
||||
'password' => password_hash($_POST['password'], PASSWORD_DEFAULT),
|
||||
'userType' => $_POST['type']
|
||||
];
|
||||
if ($_POST['submit'] == 'Update') {
|
||||
$record['id'] = $_POST['user_id'];
|
||||
$this->vars['response'] = 'User Updated Successfully';
|
||||
}
|
||||
else {
|
||||
$this->vars['response'] = 'User Created Successfully';
|
||||
}
|
||||
$this->usersTable->save($record);
|
||||
return [
|
||||
'template' => 'response.html.php',
|
||||
'title' => 'Jo\'s Jobs- Edit user',
|
||||
'vars' => $this->vars
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function addJob() {
|
||||
|
|
@ -110,7 +159,7 @@ class Portal {
|
|||
$this->vars['update'] = false;
|
||||
}
|
||||
return ['template' => 'job_add.html.php',
|
||||
'title' => 'Jo\'s Jobs- Add Job',
|
||||
'title' => 'Jo\'s Jobs- Edit Job',
|
||||
'vars' => $this->vars
|
||||
];
|
||||
}
|
||||
|
|
@ -158,7 +207,7 @@ class Portal {
|
|||
$this->vars['update'] = false;
|
||||
}
|
||||
return ['template' => 'category_add.html.php',
|
||||
'title' => 'Jo\'s Jobs- Add Category',
|
||||
'title' => 'Jo\'s Jobs- Edit Category',
|
||||
'vars' => $this->vars
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
<li><a href="/portal">Jobs</a></li>
|
||||
<?php if ($_SESSION['userType'] == 'admin') { ?>
|
||||
<li><a href="/portal/categories">Categories</a></li>
|
||||
<li><a href="/portal/users">Users</a></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</section>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
<main class="home">
|
||||
<form method="post" action="/portal/addUser">
|
||||
<?php if ($update) {?>
|
||||
<label>Enter Username</label>
|
||||
<input type="username" name="username" value="<?=$user->username?>"/>
|
||||
<label>Enter Password</label>
|
||||
<input type="password" name="password" value="<?=$user->password?>"/>
|
||||
<label>Enter User Type</label>
|
||||
<input type="text" name="type" value="<?=$user->userType?>"/>
|
||||
<input type="hidden" name="user_id" value="<?=$user->id?>" />
|
||||
<input type="submit" name="submit" value="Update"/>
|
||||
<?php }
|
||||
else { ?>
|
||||
<label>Enter Username</label>
|
||||
<input type="username" name="username" />
|
||||
<label>Enter Password</label>
|
||||
<input type="password" name="password" />
|
||||
<label>Enter User Type</label>
|
||||
<input type="text" name="type" />
|
||||
<input type="submit" name="submit" value="Create"/>
|
||||
<?php } ?>
|
||||
</form>
|
||||
</main>
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<h2>Users</h2>
|
||||
<a class="new" href="/portal/addUser">Add new user</a>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Username</th>
|
||||
<th>User Type</th>
|
||||
<th style="width: 5%"> </th>
|
||||
<th style="width: 5%"> </th>
|
||||
</tr>
|
||||
<?php foreach ($users as $user) { ?>
|
||||
<tr>
|
||||
<td><?=$user->username?></td>
|
||||
<td><a style="float: right" href="/portal/addUser?user_id=<?=$user->id?>">Edit</a></td>
|
||||
<td><form method="post" action="/portal/">
|
||||
<input type="hidden" name="user_id" value="<?=$user->id?>" />
|
||||
<input type="hidden" name="user_type" value="<?=$user->userType?>" />
|
||||
<input type="submit" name="submit" value="Delete" />
|
||||
</form></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</thead>
|
||||
</table>
|
||||
4
todo
4
todo
|
|
@ -14,8 +14,8 @@ Assignment 2:
|
|||
- Fix Adding categories @done
|
||||
- Archive jobs instead of delete @done
|
||||
- Relist archived jobs with new closing date @done
|
||||
- Add admin user control to admin portal
|
||||
- User accounts made in admin portal
|
||||
- Add admin user control to admin portal @done
|
||||
- User accounts made in admin portal @done
|
||||
- Client user accounts @done
|
||||
- restricted admin panel @done
|
||||
- add and archive jobs @done
|
||||
|
|
|
|||
Loading…
Reference in New Issue