public function execute()
 {
     global $gvPath, $gvPhoneCodeLength;
     if ($this->redirect) {
         return $this->redirect;
     }
     $this->message = '';
     $phone = gfPostVar('phone');
     if (!$phone) {
         $this->message = 'Il campo è obbligatorio.';
         return true;
     }
     // Check only digits have been typed
     if (!preg_match('/^[0-9]{5,}$/', $phone)) {
         $this->message = 'Il valore inserito non è valido.';
         return true;
     }
     // Remove international prefix if present
     $phone = preg_replace('/^(00|\\+)?39/', '', $phone);
     $phone = '39' . $phone;
     // Check no ticket is reserved with this phone number
     $ticket = Ticket::fromDatabaseBySourceId($phone);
     if ($ticket) {
         $this->message = 'Hai già prenotato un ticket con questo numero.';
         return true;
     }
     // Check phone number is not banned
     if (Ban::isBanned($phone)) {
         $this->message = 'Questo numero di telefono è stato bloccato.';
         return true;
     }
     $hashRandom = (string) mt_rand(0, 100000);
     $hashRandom .= (string) mt_rand(0, 100000);
     $hashRandom = strtoupper(sha1($hashRandom));
     $positionRandom = mt_rand(0, 40 - $gvPhoneCodeLength);
     $phone_code = substr($hashRandom, $positionRandom, $gvPhoneCodeLength);
     $_SESSION['phone_code'] = $phone_code;
     $_SESSION['phone'] = $phone;
     // Send SMS
     $sender = new SmsSender($phone);
     if (!$sender->sendVerificationCode($phone_code)) {
         $this->message = 'Errore nell\'invio del messaggio. Verificare che il numero di telefono sia corretto.';
         return true;
     }
     $_SESSION['step'] = 2;
     $redirect = new RedirectOutput("{$gvPath}/web/checkPhone");
     return $redirect;
 }
 public function viewPost($id)
 {
     $post = Post::getOne($id);
     $banned = Ban::isBanned($post->user_fp, self::userFp());
     return View::make('board.thread_view', ['op_post' => $post, 'banned' => $banned, 'replies' => Post::replies($post, self::getBL())]);
 }
Exemple #3
0
 public static function createPost($user_fp, $input, $timestamp = false)
 {
     $timestamp = $timestamp ? $timestamp : date('Y-m-d H:i:s');
     if ($input['parent_id'] != 0) {
         $parent_post = Post::findOrFail($input['parent_id']);
         if ($parent_post->parent_id != 0) {
             App::abort(500, "Illegal post_id");
         }
         if (Ban::isBanned($parent_post->user_fp, $user_fp)) {
             App::abort(500, "You are banned");
         }
         if ($parent_post->group_name != "" && Group::where('group_name', $parent_post->group_name)->first()->is_private == 1) {
             if (!Gsub::membership($user_fp, $parent_post->group_name)) {
                 App::abort(500, 'Only members of group can leave comments.');
             }
         }
     } else {
         if ($input['group_name']) {
             $group = Group::where('group_name', $input['group_name'])->firstOrFail();
             if ($group->is_private == 1) {
                 if (!Gsub::membership($user_fp, $input['group_name'])) {
                     App::abort(500, 'Membership required to post.');
                 }
             }
         }
     }
     $message = rtrim($input['message']);
     $plaintext = BaseController::isSigned($message);
     $post = new Post();
     $post->parent_id = $input['parent_id'] ? $input['parent_id'] : 0;
     $post->user_fp = $user_fp;
     $post->timestamp = $timestamp;
     if ($input['source_link']) {
         $post->source_link = $input['source_link'];
     }
     if ($input['title']) {
         $post->title = $input['title'];
     }
     if ($plaintext) {
         $post->clear_message = self::convertEmoji($plaintext);
         $post->message = $message;
     } else {
         $post->clear_message = "";
         $post->message = self::convertEmoji($message);
     }
     if (!isset($parent_post)) {
         if ($input['chan']) {
             $post->chan = $input['chan'];
         }
         if ($input['group_name']) {
             $post->group_name = $input['group_name'];
         }
     }
     $post->save();
     if (isset($parent_post)) {
         $parent_post->replies += 1;
         $parent_post->save();
     }
     return $post;
 }