From 0ce0c40b8bb3cd91ec84c1c4886610ad45b089e9 Mon Sep 17 00:00:00 2001 From: Rob <117313375+RobtopHBY@users.noreply.github.com> Date: Wed, 18 Jan 2023 17:09:59 +0100 Subject: [PATCH] =?UTF-8?q?Web-Entwicklung=20=C3=9Cbung=207?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A1: Validation komplett (für Username ,Passwort und AGB Checkbox) Hauptäschlich in login view und Validation gearbeitet, A2: Projektemodel erstellt, Create/Update Funktionen erstellt (funktioniert noch nicht), Im Projekte View die Action hinzugefügt, dass Eingabe bei Projektname/Projektbeschreibung im Controller(Projekte) ankommen. --- BaseController.php | 53 ++++++++++++++++++ Login.php | 37 +++++++++++++ Mitglieder.php | 131 ++++++++++++++++++++++++++++++++++++++++++++ MitgliederModel.php | 84 ++++++++++++++++++++++++++++ Projekte.php | 49 +++++++++++++++++ ProjekteModel.php | 18 ++++++ Routes.php | 68 +++++++++++++++++++++++ Validation.php | 50 +++++++++++++++++ login.php | 37 +++++++++++++ 9 files changed, 527 insertions(+) create mode 100644 BaseController.php create mode 100644 Login.php create mode 100644 Mitglieder.php create mode 100644 MitgliederModel.php create mode 100644 Projekte.php create mode 100644 ProjekteModel.php create mode 100644 Routes.php create mode 100644 Validation.php create mode 100644 login.php diff --git a/BaseController.php b/BaseController.php new file mode 100644 index 0000000..99f0bdc --- /dev/null +++ b/BaseController.php @@ -0,0 +1,53 @@ +session = \Config\Services::session(); + $this->validation = \Config\Services::validation(); + } +} diff --git a/Login.php b/Login.php new file mode 100644 index 0000000..29a23ab --- /dev/null +++ b/Login.php @@ -0,0 +1,37 @@ +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'); + } +} diff --git a/Mitglieder.php b/Mitglieder.php new file mode 100644 index 0000000..1af6787 --- /dev/null +++ b/Mitglieder.php @@ -0,0 +1,131 @@ +
+
Aufgabenplaner: Mitglieder
+ + + +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + +
UsernameE-MailIm Projekt:
+
+ + + +
+
+ + + +
+ + "> +
+
+ + "> +
+
+ + "> +
+ get("username") == $data['item']['username'])): ?> +
+ + +
+ +
+ + "> +
+
+ + "> +
+
+ + "> +
+
+ + "> +
+
+ + "> +
+ + + + + + + +
+
+
+
\ No newline at end of file diff --git a/MitgliederModel.php b/MitgliederModel.php new file mode 100644 index 0000000..1423494 --- /dev/null +++ b/MitgliederModel.php @@ -0,0 +1,84 @@ +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(); + } + + +} diff --git a/Projekte.php b/Projekte.php new file mode 100644 index 0000000..1f58359 --- /dev/null +++ b/Projekte.php @@ -0,0 +1,49 @@ +
+
Aufgabenplaner: Projekte
+
+
+ +
+ +
+
+
+

Projekt auswählen:

+ +
+ + + +
+
+
+
+

Projekt bearbeiten/erstellen

+
+ + +
+
+ + +
+
+ + + +
+
+
+
+
\ No newline at end of file diff --git a/ProjekteModel.php b/ProjekteModel.php new file mode 100644 index 0000000..0e62138 --- /dev/null +++ b/ProjekteModel.php @@ -0,0 +1,18 @@ + $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); + } +} \ No newline at end of file diff --git a/Routes.php b/Routes.php new file mode 100644 index 0000000..7bbcc1a --- /dev/null +++ b/Routes.php @@ -0,0 +1,68 @@ +setDefaultNamespace('App\Controllers'); +$routes->setDefaultController('Login'); +$routes->setDefaultMethod('index'); +$routes->setTranslateURIDashes(false); +$routes->set404Override(); +// The Auto Routing (Legacy) is very dangerous. It is easy to create vulnerable apps +// where controller filters or CSRF protection are bypassed. +// If you don't want to define all routes, please use the Auto Routing (Improved). +// Set `$autoRoutesImproved` to true in `app/Config/Feature.php` and set the following to true. +// $routes->setAutoRoute(false); + +/* + * -------------------------------------------------------------------- + * Route Definitions + * -------------------------------------------------------------------- + */ + +// We get a performance increase by specifying the default +// route since we don't have to scan directories. +$routes->get('/', 'Login::index'); +$routes->get('/Login', 'Login::index'); +$routes->post('/Login', 'Login::index'); +$routes->get('/Aufgaben', 'Aufgaben::index'); +$routes->get('/Mitglieder', 'Mitglieder::index'); +$routes->get('/Mitglieder/edit/(:num)', 'Mitglieder::edit/$1'); +$routes->post('/Mitglieder/update', 'Mitglieder::update'); +$routes->post('/Mitglieder/create', 'Mitglieder::createMember'); +$routes->get('/Projekte/create', 'Projekte::create'); +$routes->post('/Projekte/create', 'Projekte::create'); +$routes->get('/Mitglieder/delete/(:num)', 'Mitglieder::deleteMember/$1'); // FIXME: dirty! don't GET! +$routes->get('/Reiter', 'Reiter::index'); +$routes->get('/Todos', 'Todos::index'); +$routes->get('/Projekte', 'Projekte::index'); + +/* + * -------------------------------------------------------------------- + * Additional Routing + * -------------------------------------------------------------------- + * + * There will often be times that you need additional routing and you + * need it to be able to override any defaults in this file. Environment + * based routes is one such time. require() additional route files here + * to make that happen. + * + * You will have access to the $routes object within that file without + * needing to reload it. + */ +if (is_file(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php')) { + require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php'; +} diff --git a/Validation.php b/Validation.php new file mode 100644 index 0000000..29d71ba --- /dev/null +++ b/Validation.php @@ -0,0 +1,50 @@ + + */ + public $templates = [ + 'list' => 'CodeIgniter\Validation\Views\list', + 'single' => 'CodeIgniter\Validation\Views\single', + ]; + + // -------------------------------------------------------------------- + // Rules + // -------------------------------------------------------------------- + public $login = [ + 'username' => 'required', + 'password' => 'required', + 'AGB' => 'required' + ]; + +} diff --git a/login.php b/login.php new file mode 100644 index 0000000..e91b734 --- /dev/null +++ b/login.php @@ -0,0 +1,37 @@ +
+
+
+ 'form')) ?> + Login +
+
+ + +
+ +
+
+
+ + +
+ +
+
+ +
+
+ + +
+ +
+
+ +

Noch nicht registriert? Registrierung

+
+
+
\ No newline at end of file