コード例 #1
0
 /**
  * Run the validation checks in the input data
  *
  * @param  array  $data
  *
  * @return bool
  * @throws Exception
  * @throws ValidateException
  */
 public function runValidationChecks(array $data)
 {
     foreach ($this->validators as $validator) {
         if ($validator instanceof Validator) {
             if (!$validator->with($data)->validate()) {
                 $this->errors->merge($validator->errors());
             }
         } else {
             throw new Exception("{$validator} is not an instance of Motty\\Laravel\\Validator\\Contracts\\Validator");
         }
     }
     if ($this->errors->isEmpty()) {
         return true;
     }
     throw new ValidateException('Validation failed', $this->errors);
 }
コード例 #2
0
ファイル: OneToMany.php プロジェクト: orangehill/photon
 public function validate()
 {
     $messageBag = new MessageBag();
     if (!$this->relation_table || !\Schema::hasTable($this->relation_table)) {
         $messageBag->add($this->name, 'Invalid relation table on ' . $this->name);
     }
     return $messageBag->isEmpty() ? true : $messageBag;
 }
コード例 #3
0
 /**
  * @return \Response
  */
 public function update()
 {
     $input = Input::only('email', 'first_name', 'last_name', 'phone', 'school');
     $extra = Input::only('address', 'about');
     try {
         $this->accountForm->validate(Input::all());
     } catch (FormValidationException $e) {
         $this->errors = $e->getErrors();
     }
     foreach ($input as $key => $value) {
         if (!$this->errors->has($key)) {
             $this->user()->{$key} = e(trim($value));
         }
     }
     foreach ($extra as $key => $value) {
         if (!$this->errors->has($key)) {
             $this->user()->setMeta($key, e(trim($value)));
         }
     }
     $this->user()->save();
     return json($this->errors->isEmpty() ? trans('app.saved') : ['errors' => $this->errors]);
 }
コード例 #4
0
ファイル: Validator.php プロジェクト: imydou/dkuu
 /**
  * Determine if the data passes the validation rules.
  *
  * @return bool
  */
 public function passes()
 {
     $this->messages = new MessageBag();
     // We'll spin through each rule, validating the attributes attached to that
     // rule. Any error messages will be added to the containers with each of
     // the other error messages, returning true if we don't have messages.
     foreach ($this->rules as $attribute => $rules) {
         foreach ($rules as $rule) {
             $this->validate($attribute, $rule);
             if ($this->shouldStopValidating($attribute)) {
                 break;
             }
         }
     }
     // Here we will spin through all of the "after" hooks on this validator and
     // fire them off. This gives the callbacks a chance to perform all kinds
     // of other validation that needs to get wrapped up in this operation.
     foreach ($this->after as $after) {
         call_user_func($after);
     }
     return $this->messages->isEmpty();
 }
コード例 #5
0
ファイル: ModuleCreator.php プロジェクト: orangehill/photon
 /**
  * Checks if the input request is doable
  *
  * @param array $fields
  * @param       $moduleId
  *
  * @return true|MessageBag
  */
 private function validateNewFields(array $fields = array(), $moduleId)
 {
     $customBag = new MessageBag();
     // Main bag
     $validatorBags = array();
     // Bags of different validators
     $takenColumnNames = array();
     // Column names that already exist
     // Check if column name already exists
     $tmpField = new Field();
     $rules = array_merge($tmpField->getRules(), array('column_name' => 'unique:fields,column_name,NULL,id,module_id,' . $moduleId));
     // Go through all fields and validate them
     foreach ($fields as $field) {
         $photonField = new Field($field);
         $formField = FieldFactory::make($photonField);
         $formField->setRow($field);
         $validated = $formField->validate();
         if ($validated instanceof MessageBag) {
             $validatorBags[] = $validated;
         }
         /* @var $validator \Illuminate\Validation\Validator */
         $validator = \Validator::make($field, $rules);
         if ($validator->fails()) {
             $validatorBags[] = $validator->getMessageBag();
         }
         if (in_array($field['column_name'], $takenColumnNames)) {
             $customBag->add('new_field', 'Column name `' . $field['column_name'] . '` cannot be assigned to multiple fields');
         }
         $takenColumnNames[] = $field['column_name'];
     }
     // Merge all bags
     /* @var $bag MessageBag */
     foreach ($validatorBags as $bag) {
         $customBag->merge($bag->getMessages());
     }
     // Return the bag if there are no errors, otherwise return true
     return $customBag->isEmpty() ? true : $customBag;
 }
コード例 #6
0
ファイル: ManyToMany.php プロジェクト: orangehill/photon
 public function validate()
 {
     $messageBag = new MessageBag();
     $pivotInfo = $this->getPivotInfo();
     if (!$this->relation_table || !\Schema::hasTable($this->relation_table)) {
         $messageBag->add($this->name, 'Invalid relation table on ' . $this->name);
     }
     if (\Schema::hasTable($pivotInfo['pivot_table'])) {
         $messageBag->add($this->name, "Pivot table {$pivotInfo['pivot_table']} already exists.");
     }
     return $messageBag->isEmpty() ? true : $messageBag;
 }
コード例 #7
0
ファイル: Form.php プロジェクト: jacksun101/streams-platform
 /**
  * Return whether the form has errors or not.
  *
  * @return bool
  */
 public function hasErrors()
 {
     return !$this->errors->isEmpty();
 }
コード例 #8
0
ファイル: TestsController.php プロジェクト: Orvo/mlraamattu
 public function check($id, Request $request, TestValidator $testvalidator)
 {
     $test = Test::findOrFail($id);
     $validation = $testvalidator->WithRequest($test, $request);
     $hasPassed = $validation['num_correct'] / $validation['total'] >= 0.5;
     $hasPassedFull = $validation['num_correct'] == $validation['total'];
     $minimumToPass = ceil($validation['total'] * 0.5);
     $customErrors = new MessageBag();
     $errors = [];
     if (!Auth::check()) {
         $authenticationType = $request->input('authentication_type');
         switch ($authenticationType) {
             case 0:
                 $authvalidator = \Validator::make($request->all(), ['user-name' => 'required', 'user-email' => 'required|email|unique:users,email', 'user-password' => 'required|min:8|confirmed'], ['user-name.required' => 'Nimi on pakollinen.', 'user-email.required' => 'Sähköpostiosoite on pakollinen.', 'user-email.email' => 'Annettu sähköpostiosoite ei ole pätevä.', 'user-email.unique' => 'Tunnus samalla sähköpostiosoitteella on jo olemassa.', 'user-password.required' => 'Salasana on pakollinen.', 'user-password.min' => 'Salasanan pitää olla ainakin :min merkkiä pitkä.', 'user-password.confirmed' => 'Salasanat eivät täsmää.']);
                 break;
             case 1:
                 $authvalidator = \Validator::make($request->all(), ['user-login-email' => 'required|email', 'user-login-password' => 'required'], ['user-login-email.required' => 'Sähköpostiosoite on pakollinen.', 'user-login-email.email' => 'Annettu sähköpostiosoite ei ole pätevä.', 'user-login-password.required' => 'Salasana on pakollinen.']);
                 break;
         }
         $group = false;
         $shouldJoinGroup = false;
         if (strlen($request->input('group-code')) > 0) {
             $group = Group::where('code', $request->input('group-code'));
             if (!$group->exists()) {
                 $customErrors->add('group-code', 'Annettua ryhmää ei löytynyt. Syötä oikea ryhmäkoodi.');
             } else {
                 $shouldJoinGroup = true;
             }
         }
         if ($authvalidator->passes() && $customErrors->isEmpty()) {
             switch ($authenticationType) {
                 case 0:
                     $user = new User();
                     $user->name = $request->input('user-name');
                     $user->email = $request->input('user-email');
                     $user->password = Hash::make($request->input('user-password'));
                     $user->access_level = 'USER';
                     $user->save();
                     Mail::send('email.user_account_created', ['user' => $user], function ($m) use($user) {
                         $m->to($user->email, $user->name)->subject('Käyttäjätunnus luotu Media7 raamattuopistoon');
                     });
                     Auth::login($user);
                     if ($shouldJoinGroup) {
                         $group->first()->join();
                     }
                     break;
                 case 1:
                     $credentials = ['email' => $request->input('user-login-email'), 'password' => $request->input('user-login-password')];
                     $remember = $request->input('remember_me');
                     if (!Auth::attempt($credentials, $remember)) {
                         $customErrors->add('user-login-email', 'Kirjautuminen annetuilla tunnuksilla ei onnistunut!');
                     } else {
                         if ($shouldJoinGroup) {
                             $group->first()->join();
                         }
                         return redirect('/test/' . $test->id);
                     }
                     break;
             }
         }
         $errors = array_merge($authvalidator->errors()->all(), $customErrors->all());
     }
     if (Auth::check() && $customErrors->isEmpty()) {
         $archive = Auth::user()->archives()->where('test_id', $id)->first();
         $data = $validation;
         if (!$archive) {
             $archive = new Archive();
             $archive->user_id = Auth::user()->id;
             $archive->test_id = $test->id;
         } else {
             $old_data = json_decode($archive->data, true);
             if (@$old_data['feedback']) {
                 $data['feedback'] = $old_data['feedback'];
             }
         }
         $archive->data = json_encode($data);
         $archive->save();
     }
     return view('test.show')->with(array_merge($validation, ['test' => $test, 'feedback' => @$data['feedback'], 'hasPassed' => @$hasPassed, 'hasPassedFull' => @$hasPassedFull, 'minimumToPass' => @$minimumToPass, 'authentication_type' => @$authenticationType, 'isMaterialPage' => false, 'authFailed' => !Auth::check() && !$authvalidator->passes(), 'old' => $request->all()]))->withInput($request)->withErrors(@$errors);
 }