Example #1
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $this->data['items'] = Event::where('enabled', 1)->first();
     $cek = Flag::where('eventid', $this->data['items']->id)->where('from', Auth::id())->where('to', Auth::id())->first();
     if ($cek != null) {
         $this->data['items'] = null;
         // dd($cek);
     }
     return view('pages.dept.dashboard', $this->data);
 }
Example #2
0
 public function store(SubmitFlagRequest $request)
 {
     $startd = DB::table('Games')->select('start')->first();
     $endd = DB::table('Games')->select('stop')->first();
     if ($startd->start > Carbon::now()) {
         return view("pages.countdown");
     } elseif ($endd->stop < Carbon::now()) {
         return view('pages.closed');
     }
     $request = $request->all();
     $flags = Flag::where('flag', $request['flag'])->first();
     if (!empty($flags)) {
         $previously = Submitted_flag::select('user_id')->where('text', $request['flag'])->where('user_id', Auth::user()->id)->get();
         $previously = $previously->toArray();
         var_dump($previously);
         if (empty($previously)) {
             $flags = $flags->toArray();
             $submission['created_at'] = Carbon::now()->toDateTimeString();
             $submission['updated_at'] = Carbon::now()->toDateTimeString();
             $submission['user_id'] = Auth::user()->id;
             $submission['challenge_id'] = $flags['challenge_id'];
             //to do yo
             $submission['text'] = $request['flag'];
             Submitted_flag::create($submission);
             return redirect('flags/submit')->with('message', 'Correct!');
         }
         $message = 'You have previously submitted this flag!';
         return redirect('flags/submit')->with('message', $message);
     }
     $filename = "../storage/failed.csv";
     $content = Auth::user()->name . "," . $request['flag'] . "\n\r";
     $bytesWritten = File::append($filename, $content);
     if ($bytesWritten === false) {
         die("Couldn't write to the file.");
     }
     return redirect('flags/submit')->with('message', 'Incorrect, sorry try again!');
 }
 public function store(SubmitFlagRequest $request)
 {
     $request = $request->all();
     $flags = Flag::where('flag', $request['flag'])->first();
     if (!empty($flags)) {
         $previously = Submitted_flag::select('user_id')->where('text', $request['flag'])->where('user_id', Auth::user()->id)->get();
         $previously = $previously->toArray();
         var_dump($previously);
         if (empty($previously)) {
             $flags = $flags->toArray();
             $submission['created_at'] = Carbon::now()->toDateTimeString();
             $submission['updated_at'] = Carbon::now()->toDateTimeString();
             $submission['user_id'] = Auth::user()->id;
             $submission['challenge_id'] = $flags['challenge_id'];
             //to do yo
             $submission['text'] = $request['flag'];
             Submitted_flag::create($submission);
             return redirect('flags/submit')->with('message', 'Correct!');
         }
         $message = 'You have previously submitted this flag!';
         return redirect('flags/submit')->with('message', $message);
     }
     return redirect('flags/submit')->with('message', 'Incorrect, sorry try again!');
 }
Example #4
0
 public function yes($id, $userid)
 {
     if (Request::isMethod('get')) {
         //cek event aktif, anaknya bukan, udah pernah ngisi belum, kadept bukan
         if (Auth::user()->positionid != 1) {
             $user = User::find($userid);
             // dd($user->deptid);
             if ($user->deptid != Auth::user()->deptid) {
                 return redirect('/');
             }
             $data = Event::where('enabled', 1)->find($id);
             if (!$data) {
                 return redirect('/');
             }
             if (!$data->enabled) {
                 return redirect('/');
             }
             $cek = Flag::where('eventid', $id)->where('from', '!=', $userid)->where('to', $userid)->first();
             if ($cek != null) {
                 return redirect('/');
             }
             $this->data['event'] = $data;
             $this->data['questions'] = Pivot::where('eventid', $id)->get();
             return view('pages.submit.yes', $this->data);
         } else {
             return redirect('/');
         }
     } else {
         $input = Input::get('score');
         $data = Event::where('enabled', 1)->find($id);
         if (!$data) {
             return redirect('/');
         }
         if (!$data->enabled) {
             return redirect('/');
         }
         // dd($input);
         //set ke mark
         foreach ($input as $key => $value) {
             $mark = new Mark();
             $mark->userid = $userid;
             $mark->questionid = $key;
             $mark->string = $value;
             $mark->save();
         }
         //set ke score
         $score = Score::where('eventid', $id)->where('userid', $userid)->first();
         if ($score) {
             foreach ($input as $key => $value) {
                 $question = Question::find($key);
                 if ($question->type == 1) {
                     $pivot = Pivot::where('eventid', $id)->where('questionid', $key)->first();
                     $score->score += $value * $pivot->score / 100;
                     $score->save();
                 }
             }
         } else {
             $score = new Score();
             $score->eventid = $id;
             $score->userid = $userid;
             $score->score = 0;
             foreach ($input as $key => $value) {
                 $question = Question::find($key);
                 // dd($input);
                 if ($question->type == 1) {
                     $pivot = Pivot::where('eventid', $id)->where('questionid', $key)->first();
                     $score->score += $value * $pivot->score / 100;
                     $score->save();
                 }
             }
         }
         //set ke flag
         $flag = new Flag();
         $flag->from = Auth::id();
         $flag->to = $userid;
         $flag->eventid = $id;
         $flag->save();
         return redirect('submit/' . $id);
     }
 }