/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { //handle registration emails $name = $data['first_name'] . ' ' . $data['last_name']; //send normal registration email Mail::send('auth.emails.welcome', ['name' => $name], function ($message) use($data) { $message->to($data['email'])->from('*****@*****.**', 'BICO Registration')->subject('Welcome to the BICO Website!'); }); if ($data['instructor'] == 1) { //send instructor weclome email Mail::send('auth.emails.instructor', ['name' => $name], function ($message) use($data) { $message->to($data['email'])->from('*****@*****.**', 'BICO Registration')->subject('Welcome Instructor!'); }); } //convert array of SAR roles into string (because I'm lazy) $sar_role = implode(",", $data['sar_role']); //check for 'other' province if ($data['other'] !== "") { $province = "Other - " . $data['other']; } else { $province = $data['province']; } //create user $user = User::create(['first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'province' => $province, 'sar_role' => $sar_role, 'instructor' => $data['instructor'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]); //set up entry in progress table $progress = Progress::create(['user_id' => $user->id]); //TEMPORARY: send to survey after registraion $this->redirectTo = 'http://www.surveygizmo.com/s3/2504752/a81420acc61a'; return $user; }
/** * Check to see if team's guess was correct * @return index page */ public function answer(Request $request) { // get team and question $team = Auth::user()->team()->first(); $questionNr = count(Progress::where('team_id', $team->id)->get()); $question = Question::where('sequence', $questionNr + 1)->first(); // get the answer from the user from the input $answer = $request->input('answer'); $answer = trim($answer); // fetch the correct answers from the database $rightAnswers = $question->answers()->get(); $answersCount = count($rightAnswers); $correct = false; $errors = []; if (strpos($answer, ' ') !== false) { array_push($errors, "Je antwoord bevat één of meerdere spaties!"); } if (strpbrk($answer, '1234567890') !== false) { array_push($errors, "Je antwoord bevat één of meerdere cijfers!"); } if (strpbrk($answer, '³²&é"\'(§è!çà-)$^*¨µù£%=:+/;,.?][`´~<>|@#^{}') !== false) { array_push($errors, "Je antwoord bevat één of meerdere speciale tekens!"); } // check if the given answer was correct for ($i = 0; $i < $answersCount; $i++) { if (strcmp(strtoupper($rightAnswers[$i]->answer), strtoupper($answer)) == 0) { $correct = true; } } // create a new record in the team answers table TeamAnswer::create(['team_id' => $team->id, 'question_id' => $question->id, 'answer' => $answer, 'correct' => $correct]); // if the answer was correct, a lot of stuff has to be done here... if ($correct) { // new record in the progress table Progress::create(['team_id' => $team->id, 'question_id' => $question->id]); // finish record in the times table $qt = QuestionTime::where('question_id', $question->id)->where('team_id', $team->id)->first(); $qt->end_time = \Carbon\Carbon::now()->timestamp; $qt->delta_time = $qt->end_time - $qt->start_time; $qt->save(); Event::create(['type_id' => 1, 'time' => \Carbon\Carbon::now()->timestamp, 'team_id' => $team->id, 'question_id' => $question->id]); $newQuestion = Question::where('sequence', $question->sequence + 1)->first(); if ($newQuestion != null) { QuestionTime::create(array('team_id' => $team->id, 'question_id' => $newQuestion->id, 'tip' => false, 'start_time' => \Carbon\Carbon::now()->timestamp)); } return redirect('/'); } else { if (count($errors) > 0) { array_push($errors, "<a href='#'>Kijk hier het reglement na</a>."); } array_unshift($errors, "Fout antwoord, probeer opnieuw."); return redirect('/')->withErrors($errors); } }