Пример #1
0
 public function createAccountAction()
 {
     // checks if a post is committed
     if ($this->request->isPost()) {
         // check for CSRF security
         if ($this->security->checkToken() == false) {
             $this->flash->error("invalid CSRF token ");
             $this->response->redirect('account/index');
         }
         // saves input from form in a variable
         $email = $this->request->getPost('email');
         $username = $this->request->getPost('username');
         $voornaam = $this->request->getPost('voornaam');
         $tussenvoegsel = $this->request->getPost('tussenvoegsel');
         $achternaam = $this->request->getPost('achternaam');
         $telefoonnummer = $this->request->getPost('telefoonnummer');
         $password = $this->request->getPost('password');
         $confirm_password = $this->request->getPost('confirm_password');
         // checks if both password fields are equal
         if ($password != $confirm_password) {
             $this->flash->warning('de ingevulde wachtwoorden zijn niet gelijk');
             $this->response->redirect('account/register');
         }
         // initiate model
         $gebruiker = new Gebruiker();
         // assign post input to a field form the table
         $gebruiker->rol = "user";
         $gebruiker->email = $email;
         $gebruiker->username = $username;
         $gebruiker->tussenvoegsel = $tussenvoegsel;
         $gebruiker->voornaam = $voornaam;
         $gebruiker->achternaam = $achternaam;
         $gebruiker->telefoonnummer = $telefoonnummer;
         $gebruiker->password = $password;
         // save the inputs in the table
         $result = $gebruiker->save();
         // checks if any invalid values are past
         if (!$result) {
             $output = [];
             foreach ($gebruiker->getMessages() as $message) {
                 $output[] = $message;
             }
             $output = implode("<br><br>", $output);
             // displays incorrect input
             $this->flash->error($output);
             $this->response->redirect('account/register');
             return;
         }
         $this->registerSession($gebruiker);
         $this->response->redirect('afspraak/index');
     }
 }