Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web-Entwicklung Übung 7 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions BaseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App\Controllers;

use CodeIgniter\Controller;
use CodeIgniter\HTTP\CLIRequest;
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;

/**
* Class BaseController
*
* BaseController provides a convenient place for loading components
* and performing functions that are needed by all your controllers.
* Extend this class in any new controllers:
* class Home extends BaseController
*
* For security be sure to declare any new methods as protected or private.
*/
abstract class BaseController extends Controller
{
/**
* Instance of the main Request object.
*
* @var CLIRequest|IncomingRequest
*/
protected $request;

/**
* An array of helpers to be loaded automatically upon
* class instantiation. These helpers will be available
* to all other controllers that extend BaseController.
*
* @var array
*/
protected $helpers = [];

/**
* Constructor.
*/
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
// Do Not Edit This Line
parent::initController($request, $response, $logger);

// Preload any models, libraries, etc, here.

// E.g.: $this->session = \Config\Services::session();
$this->validation = \Config\Services::validation();
}
}
37 changes: 37 additions & 0 deletions Login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Controllers;

use App\Models\MitgliederModel;

class Login extends BaseController
{
private MitgliederModel $MitgliederModel;

public function __construct()
{
$this->MitgliederModel = new MitgliederModel();
}

public function index()
{
helper('form');


if (isset($_POST['username']) and isset($_POST['password']) and $this->validation->run($_POST, 'login') === true) {
$known_login = $this->MitgliederModel->login();

if (($known_login != NULL) && (password_verify($_POST['password'], $known_login['password']))) {
session()->set('logged_in', true);
session()->set('username', $_POST['username']);
return redirect()->to(base_url('/Projekte'));
}
} else {
$data['error'] = $this->validation->getErrors();
}

echo view('templates/header');
echo view('login', $data);
echo view('templates/footer');
}
}
131 changes: 131 additions & 0 deletions Mitglieder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<div class="container-fluid">
<header class="bg-light header container-fluid">Aufgabenplaner: Mitglieder</header>

<!-- Modal -->
<div id="confirm-delete" class="modal fade" role="dialog">
<div class="modal-dialog">

<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>

</div>
</div>
<div class="row">
<div class="col-2">
<?php include(APPPATH . "/Views/templates/navigation.php"); ?>
</div>
<div class="col-8">

<table class="table fs-smaller">
<thead class="table-light">
<tr>
<th scope="col">Username</th>
<th scope="col">E-Mail</th>
<th scope="col">Im Projekt:</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<?php foreach ($data['mitglieder'] as $item): ?>
<tr>
<td class="w-25"> <?= $item['username'] ?> </td>
<td> <?= $item['email'] ?> </td>
<td><input type="checkbox" id="imProjekt"
name="checkbox1" <?= (isset($item['ismember']) && ($item['ismember']) ? "checked" : "") ?>
<label for="checkbox1"></label><br></td>
<td class="">
<!-- FIXME: dirty! don't use GET! -->
<a href="<?= base_url('/Mitglieder/delete/' . $item['id']) ?>" data-toggle="modal"
data-target="#confirm-delete"><i
class="table-icon fa-regular fa-trash-can"></i></a>
<a href="<?= base_url('/Mitglieder/edit/' . $item['id']) ?>"><i
class="table-icon fa-regular fa-pen-to-square"></i></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<form action="<?= base_url($data['mode'] == 0 ? '/Mitglieder/create' : '/Mitglieder/update') ?>"
method="post" accept-charset="utf-8">
<legend class="">
<?php
if ($data['mode'] == 0) {
echo 'Erstellen';
} elseif ($data['mode'] == 1) {
echo 'Bearbeiten';
}
?>
</legend>
<div class="form-group d-none">
<label class="form-label mb-2" for="id">ID:</label>
<input class="form-control" id="id" name="id"
value="<?= $data['item']['id'] ?? "" ?>">
</div>
<div class="form-group">
<label class="form-label mb-2" for="username">Username:</label>
<input aria-label="Username" class="form-control" id="username" name="username"
placeholder="Username" value="<?= $data['item']['username'] ?? "" ?>">
</div>
<div class="form-group">
<label class="form-label mb-2" for="email">E-Mail:</label>
<input aria-label="e-mail" class="form-control" id="email" name="email"
placeholder="[email protected]" value="<?= $data['item']['email'] ?? "" ?>">
</div>
<?php if (($data['mode'] == 0) || isset($data['item']['username']) && (session()->get("username") == $data['item']['username'])): ?>
<div class="form-group">
<label class="form-label mb-2" for="password">Passwort:</label>
<input aria-label="password" class="form-control" id="password" name="password"
placeholder="********" type="password">
</div>
<?php endif; ?>
<div class="form-group">
<label class="form-label mb-2" for="firstname">Vorname:</label>
<input aria-label="first name" class="form-control" id="firstname" name="firstname"
placeholder="Max" value="<?= $data['item']['firstname'] ?? "" ?>">
</div>
<div class="form-group">
<label class="form-label mb-2" for="lastname">Nachname:</label>
<input aria-label="last name" class="form-control" id="lastname" name="lastname"
placeholder="Mustermann" value="<?= $data['item']['lastname'] ?? "" ?>">
</div>
<div class="form-group">
<label class="form-label mb-2" for="street">Straße und Hausnummer:</label>
<input aria-label="street" class="form-control" id="street" name="street"
placeholder="Musterweg 1" value="<?= $data['item']['street'] ?? "" ?>">
</div>
<div class="form-group">
<label class="form-label mb-2" for="zip">PLZ:</label>
<input aria-label="zip code" class="form-control" id="zip" name="zip"
placeholder="12345" value="<?= $data['item']['zip'] ?? "" ?>">
</div>
<div class="form-group">
<label class="form-label mb-2" for="city">Ort:</label>
<input aria-label="city" class="form-control" id="city" name="city"
placeholder="Musterstadt" value="<?= $data['item']['city'] ?? "" ?>">
</div>
<?php if (!isset($data['mode']) || ($data['mode'] == 0)) : ?>
<button type="submit" class="btn btn-success mt-2 mb-2 mr-2">
Erstellen
</button>
<?php endif ?>

<?php if ($data['mode'] == 1) : ?>
<button type="submit" class="btn btn-success mt-2 mb-2 mr-2">
Speichern
</button>
<?php endif ?>
</form>
</div>
</div>
</div>
84 changes: 84 additions & 0 deletions MitgliederModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php namespace App\Models;

use CodeIgniter\Model;

class MitgliederModel extends Model
{


public function getMembers($member_id = NULL)
{
$members = $this->db->table('members');
$members->select('*');

if ($member_id != NULL)
$members->where('id', $member_id);

$members->orderBy('id');
$result = $members->get();

if ($member_id != NULL)
return $result->getRowArray();
else
return $result->getResultArray();
}

public function createMember()
{
$hashed_password = password_hash($_POST['password'], PASSWORD_DEFAULT);

$data = array(
'username' => $_POST['username'],
'email' => $_POST['email'],
'password' => $hashed_password,
'firstname' => $_POST['firstname'],
'lastname' => $_POST['lastname'],
'street' => $_POST['street'],
'zip' => $_POST['zip'],
'city' => $_POST['city'],
);

$members = $this->db->table('members');
$members->insert($data);
}

public function updateMember()
{
$data = array(
// TODO: should we be able to edit username?
// 'username' => $_POST['username'],
'email' => $_POST['email'],
'firstname' => $_POST['firstname'],
'lastname' => $_POST['lastname'],
'street' => $_POST['street'],
'zip' => $_POST['zip'],
'city' => $_POST['city'],
);
if ((isset($_POST['password'])) && ($_POST['password'] !== '')) {
$hashed_password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$data['password'] = $hashed_password;
}
$members = $this->db->table('members');
$members->where('id', $_POST['id']);
$members->update($data);
}

public function login()
{
$members = $this->db->table('members');
$members->select('password');
$members->where('username', $_POST['username']);
$result = $members->get();

return $result->getRowArray();
}

public function deleteMember($member_id)
{
$members = $this->db->table('members');
$members->where('id', $member_id);
$members->delete();
}


}
49 changes: 49 additions & 0 deletions Projekte.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<div class="container-fluid">
<header class="bg-light header container-fluid">Aufgabenplaner: Projekte</header>
<div class="row">
<div class="col-2">
<?php include(APPPATH . "/Views/templates/navigation.php"); ?>
</div>

<div class="col-8">
<form class="mb-3">
<div class="form-group">
<h4 class="">Projekt auswählen:</h4>
<select aria-label="Projekt auswählen" class="form-select" id="choose-project">
<!--Dropdown menü-->
<option selected>- bitte auswählen -</option>
</select>
<div class="mt-3">
<button class="btn btn-primary" type="submit">
Auswählen
</button>
<button class="btn btn-primary" type="submit">
Bearbeiten
</button>
<button class="btn btn-danger" type="submit">
Löschen
</button>
</div>
</div>
</form>
<form action="<?php echo base_url('Projekte/create'); ?>" method="POST">
<h4 class="">Projekt bearbeiten/erstellen</h4>
<div class="form-group">
<label class="form-label mb-2" for="project-name">Projektname:</label>
<input type="text" name="Projektname" aria-label="Projektname" class="form-control" id="project-name" placeholder="Projekt">
</div>
<div class="form-group">
<label class="form-label mb-2" for="project-description">Projektbeschreibung:</label>
<input type="text" rows="4" name="Projektbeschreibung" aria-label="Projektbeschreibung" class="form-control" id="project-description" placeholder="Projektbeschreibung">
</div>
<div class="mt-3">
<input type="submit" class="btn btn-primary" type="submit" value="Speichern">

<button class="btn btn-info text-white" type="submit">
Reset
</button>
</div>
</form>
</div>
</div>
</div>
18 changes: 18 additions & 0 deletions ProjekteModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
class ProjekteModel extends CI_Model {
public function createProject($id, $description) {
$data = array(
'name' => $id,
'description' => $description
);
$this->db->insert('projects', $data);
}
public function updateProject($id, $description) {
$data = array(
'name' => $id,
'description' => $description
);
$this->db->where('name', $id);
$this->db->update('projects', $data);
}
}
Loading