public function commentPOST()
 {
     if (!Authentication::getInstance()->isAuthenticated()) {
         throw new NotAuthenticatedException();
     }
     $id = (int) $this->getParams()[0];
     $this->articleCommentModel->insertCommentArticle(Authentication::getInstance()->getUserId(), $id, Input::post('message'));
     $this->getView()->redirect('/article/show/' . $id);
 }
 public function registerPOST()
 {
     $user = ['username' => Input::post('username'), 'password' => Input::post('password'), 'firstname' => Input::post('firstname'), 'lastname' => Input::post('lastname'), 'birthday' => Input::post('birthday'), 'mail' => Input::post('mail'), 'phonenumber' => Input::post('phonenumber', true), 'twitter' => Input::post('twitter', true), 'skype' => Input::post('skype', true), 'facebookuri' => Input::post('facebookuri', true), 'website' => Input::post('website', true), 'job' => Input::post('job'), 'description' => Input::post('description'), 'privacy' => 0, 'mailnotifications' => Input::post('mailnotifications', true) == 'on' ? 1 : 0, 'accesslevel' => 0];
     // LES FLAGS C TROP SWAG
     $privacySettings = ['birthday', 'mail', 'phonenumber', 'twitter', 'skype', 'facebookuri', 'website', 'job'];
     for ($i = 0; $i < sizeof($privacySettings); ++$i) {
         if (Input::post($privacySettings[$i] . 'Private', true) == 'on') {
             $user['privacy'] |= 0b1 << $i;
         }
     }
     $errors = [];
     try {
         $this->userModel->insertUser($user);
     } catch (\PDOException $e) {
         $match = [];
         if (preg_match('/SQLSTATE\\[23000]: Integrity constraint violation: 1062 Duplicate entry \'(?P<value>.*)\' for key \'(?P<field>.*)_UNIQUE\'/', $e->getMessage(), $match)) {
             switch ($match['field']) {
                 case 'username':
                     $errors[] = 'Ce nom d\'utilisateur est déjà pris !';
                     break;
                 default:
                     $errors[] = 'Unknown database error.';
             }
         } else {
             throw $e;
         }
     }
     if (!empty($errors)) {
         $this->getView()->render('user/register', ['user' => $user, 'errors' => $errors]);
     } else {
         $this->getView()->redirect('/');
     }
 }
 public function addPOST()
 {
     if (empty($this->getParams(true))) {
         $this->getView()->redirect('/conversation');
     }
     $conversationId = (int) $this->getParams()[0];
     $userModel = $this->loadModel('User');
     foreach (explode(', ', Input::post('participations')) as $participation) {
         $userId = $userModel->getUserFullNameLike($participation)['id'];
         $this->conversationModel->addUserToConversation($conversationId, $userId);
     }
     $this->getView()->redirect('/conversation/show/' . $conversationId);
 }
Example #4
0
 public function validate($inputs)
 {
     $result = [];
     foreach ($this->getFields() as $field) {
         if (array_key_exists($field->getName(), $inputs)) {
             if ($this->getMethod() == 'POST') {
                 $result[$field->getName()] = Input::post($field->getName());
             } elseif ($this->getMethod() == 'GET') {
                 $result[$field->getName()] = Input::get($field->getName());
             }
         }
     }
     return $result;
 }