/**
  * @return mixed
  */
 public function handleRegister()
 {
     $rules = ['first_name' => 'required|min:3', 'last_name' => 'required|min:3', 'email' => 'unique:User:email|required|email', 'confirm-email' => 'required|email|equalTo:email', 'agree' => 'required', 'password' => 'required|min:3', 'confirm-password' => 'required|equalTo:password', 'join_list' => 'required'];
     $errors = $this->validate($rules);
     if (sizeof($errors) > 0) {
         $html = $this->blade->with('session', $this->session)->withTemplate('register')->render();
         $new_html = $this->repopulateForm($html, $errors, $this->request->getParameters());
         return $this->response->setContent($new_html);
     } else {
         $user = new User();
         $user->email = $this->request->getParameter('email');
         $user->password = password_hash($this->request->getParameter('password'), PASSWORD_DEFAULT);
         $user->save();
         $user_id = $user->id;
         $registration = new Registration();
         $registration->user_id = $user_id;
         $registration->first_name = $this->request->getParameter('first_name');
         $registration->last_name = $this->request->getParameter('last_name');
         $registration->colour = $this->request->getParameter('colour');
         $registration->comments = $this->request->getParameter('comments');
         $registration->join_list = $this->request->getParameter('join_list');
         $registration->save();
         return $this->response->setContent($this->blade->with('session', $this->session)->render("generic-page", ['content' => 'Thanks for joining our site!', 'title' => 'Thanks!']));
     }
 }
Пример #2
0
 public function aanmelden_anonmiem()
 {
     $meal = Meal::find((int) Request::input('meal_id'));
     if (!$meal) {
         return response()->json(['error' => 'meal_not_found', 'error_details' => 'Maaltijd bestaat niet'], 404);
     }
     // Create a new registration
     $registration = new Registration(['name' => e(Request::input('name')), 'handicap' => Request::input('handicap') != '' ? e(Request::input('handicap')) : null]);
     $registration->confirmed = true;
     $registration->meal_id = $meal->id;
     if ($registration->save()) {
         Log::info("Aangemeld: administratie|{$registration->id}|{$registration->name}");
         return view('meal/_registration', ['registration' => $registration]);
     } else {
         return response()->json(['error' => 'create_registration_admin_unknown_error', 'error_details' => 'Deze registratie kon niet opgeslagen worden, reden onbekend.'], 500);
     }
 }
Пример #3
0
 /**
  * Subscribe a user to a single meal
  * @return json
  */
 public function aanmeldenBolker()
 {
     // Find the meal
     $meal = Meal::find((int) Request::input('meal_id'));
     if (!$meal) {
         return response()->json(['error' => 'meal_not_found', 'error_details' => 'De maaltijd waarvoor je je probeert aan te melden bestaat niet'], 404);
     }
     // Check if the meal is still open
     if (!$meal->open_for_registrations()) {
         return response()->json(['error' => 'meal_deadline_expired', 'error_details' => 'De aanmeldingsdeadline is verstreken'], 400);
     }
     $user = OAuth::user();
     // Check if the user is blocked from registering
     if ($user->blocked) {
         return response()->json(['error' => 'user_blocked', 'error_details' => 'Je bent geblokkeerd op bolknoms. Je kunt je niet aanmelden voor maaltijden.'], 403);
     }
     // Check if the user is already registered
     if ($user->registeredFor($meal)) {
         return response()->json(['error' => 'double_registration', 'error_details' => 'Je bent al aangemeld voor deze maaltijd'], 400);
     }
     // Create registration
     $registration = new Registration(['name' => $user->name, 'handicap' => $user->handicap]);
     $registration->user_id = $user->id;
     $registration->meal_id = $meal->id;
     $registration->username = $user->username;
     $registration->email = $user->email;
     $registration->confirmed = true;
     if ($registration->save()) {
         \Log::info("Aangemeld: {$registration->id}|{$registration->name}");
         return response(null, 200);
     } else {
         \Log::error("Aanmelding mislukt, onbekend");
         return response()->json(['error' => 'unknown', 'error_details' => 'unknown_internal_server_error'], 500);
     }
 }
Пример #4
0
 /**
  * @param $id
  * @return \yii\web\Response
  * @throws NotFoundHttpException
  * @throws \yii\db\Exception
  */
 public function actionPreregister($id)
 {
     $model = $this->findModel($id);
     $user = User::find()->where("id=" . Yii::$app->user->id)->one();
     $user_id = $user->id;
     $student = Student::find()->where("user_id=" . $user_id)->one();
     $student_id = $student->id;
     $vacancy = ProjectVacancy::find()->where("project_id=" . $id)->one();
     $vacancyValue = $vacancy->vacancy;
     if ($existe = StudentProfile::find()->where(['project_id' => $id, 'degree_id' => $student->degree_id])->one()) {
         if (Registration::find()->where(['student_id' => $student_id])->one()) {
             Yii::$app->getSession()->setFlash('danger', 'Ya te has pre-registrado a un proyecto');
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             if ($vacancyValue > 0) {
                 $newRegistration = new Registration();
                 $newRegistration->project_id = $id;
                 $newRegistration->student_id = $student_id;
                 $newRegistration->student_status = "preregistered";
                 $newRegistration->save();
                 Yii::$app->db->createCommand()->update('project_vacancy', ['vacancy' => $vacancy->vacancy - 1], 'project_id=' . $id)->execute();
                 Yii::$app->getSession()->setFlash('success', 'Te has pre-registrado al proyecto');
                 return $this->redirect(['view', 'id' => $model->id]);
             } else {
                 Yii::$app->getSession()->setFlash('danger', 'No hay cupo para este proyecto. Escoge otro.');
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         }
     } else {
         Yii::$app->getSession()->setFlash('danger', 'No cuentas con el perfil solicitado');
         return $this->redirect(['view', 'id' => $model->id]);
     }
 }