public function test_entry($data) { if ($this->invite_only == 1) { $hasher = \Core\Hasher::create()->check($data['password'], $this->password); } else { if ($this->invite_only == 2) { $v = \Trouble\Voucher::container()->get_valid($data['voucher'], 'join', $this)->spend(); } } return $this; }
public function generate_vouchers() { $t = $this->_template; if ($_args['number'] > 280) { $_args['number'] = 280; } else { if ($_args['number'] < 1) { $_args['number'] = 0; } } try { $this->_auth->check_admin('game', $this->_game->id); $vouchers = array(); for ($i = 0; $i < $this->_args['number']; $i++) { array_push($vouchers, \Trouble\Voucher::container()->make_new($this->_args['type'], $this->_game)); } $t->vouchers = $vouchers; $t->types = array('join' => 'Game Join Code', 'credit1' => '1 Credit', 'credit2' => '2 Credits', 'credit5' => '5 Credits', 'credit10' => '10 Credits', 'credit20' => '20 Credits'); echo $t->render('vouchers_print.php'); } catch (\Core\AuthError $e) { throw new \Core\HTTPError(403, 'generate-vouchers'); } }
public function redeem_credit() { import('trouble.voucher'); try { $this->_game_action(function ($agent_id) { $game = \Trouble\Game::container()->get_by_id($_POST['game_id'])->load_players(); $p = $game->all_players->filter($agent_id, 'agent')->{0}; $v = \Trouble\Voucher::container()->get_valid($_POST['voucher'], False, $game)->spend(); $p->credits = $p->credits + $v->credit_value(); $p->save(); }, 'Voucher redeemed.'); } catch (\Trouble\VoucherError $e) { echo $this->_return_message('Fail', 'Invalid voucher.'); } }