Beispiel #1
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $id = $request->route('id');
     if (\App\Model\TokensAccount::where('guid', \Auth::user()->guid)->where('token', $id)->count() == 0) {
         return abort(404);
     }
     return $next($request);
 }
Beispiel #2
0
 /**
  * Count all tokens
  */
 public function countTokens()
 {
     $number = 0;
     $tokensAccount = TokensAccountManager::where('guid', \Auth::user()->guid)->get();
     foreach ($tokensAccount as $tokenAccount) {
         $number += $tokenAccount->quantity;
     }
     return $number;
 }
Beispiel #3
0
 /**
  * Confirm code and give reward
  * POST
  *
  * @param Request $request
  * @param string $key
  * @return Response
  */
 public function confirmCode(Request $request, $key)
 {
     $user = UserManager::find(Auth::user()->guid);
     $code = CodeManager::find($key);
     $code->use -= 1;
     $code->accounts .= $user->guid . '|';
     $code->save();
     switch ($code->action) {
         case 1:
             //Give points
             $user->points += $code->param;
             $user->save();
             break;
         case 2:
             //Give tokens
             $token = \App\Model\TokensAccount::where('guid', $user->guid)->where('token', $code->param)->first();
             if (!$token) {
                 $token = new \App\Model\TokensAccount();
                 $token->guid = $user->guid;
                 $token->token = $code->param;
                 $token->quantity = 1;
             } else {
                 $token->quantity += 1;
             }
             $token->save();
             break;
         case 3:
             //Give item
             $this->validate($request, ['player' => 'required|numeric|exists:personnages,guid']);
             $this->GiveObject($request->player, $code->param);
             break;
         case 4:
             //Give itemsets
             $this->validate($request, ['player' => 'required|numeric|exists:personnages,guid']);
             $itemset = \App\Model\Itemset::find($code->param);
             $exp = explode(',', $itemset->items);
             foreach ($exp as $id) {
                 $this->_giveObject($request->player, $id);
             }
             break;
     }
     if ($code->use == 0) {
         $code->delete();
     }
     return redirect()->route('gift.code');
 }
Beispiel #4
0
 /**
  * Use token
  * POST
  *
  * @param Request $request
  * @param int $id
  * @param string $name
  * @return Response
  */
 public function useToken(Request $request, $id, $name)
 {
     $token = TokensManager::find($id);
     $this->validate($request, ['player' => 'required|numeric|exists:personnages,guid']);
     $tokensAccount = TokensAccountManager::where('guid', Auth::user()->guid)->where('token', $id)->first();
     $tokensAccount->quantity -= 1;
     $tokensAccount->save();
     $this->_giveObject($request->player, $this->_generateRandomObject($token->items));
     if ($tokensAccount->quantity == 0) {
         $tokensAccount->delete();
     }
     return redirect()->route('gift.tokens');
 }