Пример #1
0
 /**
  * Validate project modification
  *
  * @access public
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validateModification(array $values)
 {
     if (!empty($values['identifier'])) {
         $values['identifier'] = strtoupper($values['identifier']);
     }
     $rules = array(new Validators\Required('id', t('This value is required')));
     $v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
     return array($v->execute(), $v->getErrors());
 }
Пример #2
0
 /**
  * Validate modification
  *
  * @access public
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validateModification(array $values)
 {
     $rules = array(new Validators\Required('id', t('Field required')));
     $v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
     $result = $v->execute();
     $errors = $v->getErrors();
     if ($result && $this->tagModel->exists($values['project_id'], $values['name'], $values['id'])) {
         $result = false;
         $errors = array('name' => array(t('The name must be unique')));
     }
     return array($result, $errors);
 }
Пример #3
0
 /**
  * Validate password modification
  *
  * @access public
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validatePasswordModification(array $values)
 {
     $rules = array(new Validators\Required('id', t('The user id is required')), new Validators\Required('current_password', t('The current password is required')));
     $v = new Validator($values, array_merge($rules, $this->commonPasswordValidationRules()));
     if ($v->execute()) {
         if ($this->authenticationManager->passwordAuthentication($this->userSession->getUsername(), $values['current_password'], false)) {
             return array(true, array());
         } else {
             return array(false, array('current_password' => array(t('Wrong password'))));
         }
     }
     return array(false, $v->getErrors());
 }
Пример #4
0
 public function validateLogin(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('username', t('The username is required')), new Validators\MaxLength('username', t('The maximum length is %d characters', 50), 50), new Validators\Required('password', t('The password is required'))));
     $result = $v->execute();
     $errors = $v->getErrors();
     if ($result) {
         $user = $this->getByUsername($values['username']);
         if ($user !== false && \password_verify($values['password'], $user['password'])) {
             $this->updateSession($user);
         } else {
             $result = false;
             $errors['login'] = t('Bad username or password');
         }
     }
     return array($result, $errors);
 }
Пример #5
0
 /**
  * Function that takes in a SimpleValidator object, grabs all the errors(if any), 
  * then throws the string of errors as a message.
  * 
  * @param \SimpleValidator\Validator $vdr
  * @return boolean
  * @throws \Exception
  */
 public function grabErrors($vdr)
 {
     //If errors were found, collect them into a string.
     if (!$vdr->execute()) {
         $str = "";
         //storing errors found.
         $array2D = $vdr->getErrors();
         //Grabbing errors from Validator object
         //Going through all arrays to find errors found
         foreach ($array2D as $array1D => $row) {
             foreach ($row as $error) {
                 $str .= $error . "<br />";
             }
         }
         //Throwing the message for the user to see.
         throw new \Exception($str);
     } else {
         return true;
     }
 }
Пример #6
0
function validate_login(array $values)
{
    $v = new Validator($values, array(new Validators\Required('username', t('The user name is required')), new Validators\MaxLength('username', t('The maximum length is 50 characters'), 50), new Validators\Required('password', t('The password is required'))));
    $result = $v->execute();
    $errors = $v->getErrors();
    if ($result) {
        $credentials = getCredentials();
        if ($credentials && $credentials['username'] === $values['username'] && password_verify($values['password'], $credentials['password'])) {
            $_SESSION['loggedin'] = true;
            $_SESSION['config'] = Config\get_all();
            // Setup the remember me feature
            if (!empty($values['remember_me'])) {
                $cookie = RememberMe\create(DatabaseModel\select(), $values['username'], Config\get_ip_address(), Config\get_user_agent());
                RememberMe\write_cookie($cookie['token'], $cookie['sequence'], $cookie['expiration']);
            }
        } else {
            $result = false;
            $errors['login'] = t('Bad username or password');
        }
    }
    return array($result, $errors);
}
 public function testInvalidValidation()
 {
     $rules = array('test1' => array('rule1(:test2,3,:test3)' => function ($input, $test2, $value, $test3) {
         if ($input == "test data 1" && $value == 3 && $test2 == "test data 1" && $test3 == "test data 1") {
             return true;
         }
         return false;
     }));
     $naming = array('test2' => 'Test 2');
     $validation = \SimpleValidator\Validator::validate($this->test_data, $rules, $naming);
     $this->assertFalse($validation->isSuccess());
     $validation->customErrors(array('rule1' => "Foo :params(0) bar :params(1) baz :params(2)"));
     $errors = $validation->getErrors();
     $this->assertEquals("Foo Test 2 bar 3 baz test3", $errors[0]);
 }
Пример #8
0
 /**
  * Validate user login form
  *
  * @access public
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validateForm(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('username', t('The username is required')), new Validators\MaxLength('username', t('The maximum length is %d characters', 50), 50), new Validators\Required('password', t('The password is required'))));
     $result = $v->execute();
     $errors = $v->getErrors();
     if ($result) {
         if ($this->authenticate($values['username'], $values['password'])) {
             // Setup the remember me feature
             if (!empty($values['remember_me'])) {
                 $credentials = $this->backend('rememberMe')->create($this->userSession->getId(), Request::getIpAddress(), Request::getUserAgent());
                 $this->backend('rememberMe')->writeCookie($credentials['token'], $credentials['sequence'], $credentials['expiration']);
             }
         } else {
             $result = false;
             $errors['login'] = t('Bad username or password');
         }
     }
     return array($result, $errors);
 }
Пример #9
0
 public function validate($data)
 {
     $obj = $this;
     $rules = array(':book_type' => array('required', 'integer', 'type_exists' => function ($input) use($obj) {
         return $obj->checkExist('type_id', ':type_id', 'types', $input);
     }), ':book_city' => array('required', 'integer', 'city_exists' => function ($input) use($obj) {
         return $obj->checkExist('city_id', ':city_id', 'cities', $input);
     }), ':book_size' => array('required', 'integer', 'size_exists' => function ($input) use($obj) {
         return $obj->checkExist('size_id', ':size_id', 'sizes', $input);
     }), ':book_address' => array('required'), ':book_coordinate_lat' => array('required'));
     $names = [':book_address' => 'Adresas'];
     $validate = \SimpleValidator\Validator::validate($data, $rules, $names);
     if ($validate->isSuccess() == true) {
         $response = ['success' => 'true'];
         return $response;
     } else {
         $validate->customErrors(['required' => '\':attribute\' Laukas yra privalomas', ':book_coordinate_lat.required' => 'Prašome patikslinti vietą', 'integer' => 'Reikšmė turi būti skaičius', 'type_exists' => 'Blogai pasirinktas tipas', 'city_exists' => 'Blogai pasirinktas miestas', 'size_exists' => 'Blogai pasirinktas dydis']);
         $response = ['success' => 'false', 'errors' => $validate->getErrors()];
         return $response;
     }
 }
Пример #10
0
 /**
  * Validate creation
  *
  * @access public
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validateCreation(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('user_id', t('Field required')), new Validators\Required('date', t('Field required')), new Validators\Numeric('all_day', t('This value must be numeric'))));
     return array($v->execute(), $v->getErrors());
 }
Пример #11
0
 /**
  * Validate settings modification
  *
  * @access public
  * @param  array    $values           Form values
  * @return array    $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validateModification(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('language', t('The language is required')), new Validators\Required('timezone', t('The timezone is required'))));
     return array($v->execute(), $v->getErrors());
 }
Пример #12
0
 /**
  * Validate user creation
  *
  * @access public
  * @param  array   $values
  * @return boolean
  */
 public function validateCreation(array $values)
 {
     $v = new Validator($values, array(new Validators\MaxLength('username', t('The maximum length is %d characters', 50), 50), new Validators\Unique('username', t('The username must be unique'), $this->db->getConnection(), User::TABLE, 'id'), new Validators\MinLength('password', t('The minimum length is %d characters', 6), 6), new Validators\Email('email', t('Email address invalid')), new Validators\Integer('is_admin', t('This value must be an integer')), new Validators\Integer('is_project_admin', t('This value must be an integer')), new Validators\Integer('is_ldap_user', t('This value must be an integer'))));
     return $v->execute();
 }
Пример #13
0
 /**
  * Validate password modification
  *
  * @access public
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validatePasswordModification(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('id', t('The user id is required')), new Validators\Required('current_password', t('The current password is required')), new Validators\Required('password', t('The password is required')), new Validators\MinLength('password', t('The minimum length is %d characters', 6), 6), new Validators\Required('confirmation', t('The confirmation is required')), new Validators\Equals('password', 'confirmation', t('Passwords don\'t match'))));
     if ($v->execute()) {
         // Check password
         if ($this->authentication->authenticate($_SESSION['user']['username'], $values['current_password'])) {
             return array(true, array());
         } else {
             return array(false, array('current_password' => array(t('Wrong password'))));
         }
     }
     return array(false, $v->getErrors());
 }
Пример #14
0
 /**
  * Validate allow everybody
  *
  * @access public
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validateProjectModification(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('id', t('The project id is required')), new Validators\Integer('id', t('This value must be an integer')), new Validators\Integer('is_everybody_allowed', t('This value must be an integer'))));
     return array($v->execute(), $v->getErrors());
 }
Пример #15
0
 /**
  * Validate creation
  *
  * @access public
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validateCreation(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('user_id', t('Field required')), new Validators\Required('start', t('Field required')), new Validators\Required('end', t('Field required'))));
     return array($v->execute(), $v->getErrors());
 }
Пример #16
0
 /**
  * Validate credentials syntax
  *
  * @access public
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validateFormCredentials(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('username', t('The username is required')), new Validators\MaxLength('username', t('The maximum length is %d characters', 50), 50), new Validators\Required('password', t('The password is required'))));
     return array($v->execute(), $v->getErrors());
 }
Пример #17
0
 /**
  * Validate comment modification
  *
  * @access public
  * @param  array   $values           Required parameters to save an action
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validateModification(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('id', t('This value is required')), new Validators\Integer('id', t('This value must be an integer')), new Validators\Required('comment', t('Comment is required'))));
     return array($v->execute(), $v->getErrors());
 }
Пример #18
0
function validate(array $values)
{
    $v = new Validator($values, array(new Validators\Required('name', t('The database name is required')), new Validators\AlphaNumeric('name', t('The name must have only alpha-numeric characters')), new Validators\Required('username', t('The user name is required')), new Validators\MaxLength('username', t('The maximum length is 50 characters'), 50), new Validators\Required('password', t('The password is required')), new Validators\MinLength('password', t('The minimum length is 6 characters'), 6), new Validators\Required('confirmation', t('The confirmation is required')), new Validators\Equals('password', 'confirmation', t('Passwords don\'t match'))));
    return array($v->execute(), $v->getErrors());
}
Пример #19
0
<?php

/**
 * @author Gaaaab
 */
use App\Http\Model\Contact;
use Tamtamchik\SimpleFlash\Flash;
$app->get('/contact', function () use($app) {
    $app->render('site/contacts/contact.php');
})->name('contact.index');
$app->post('/contact', function () use($app) {
    // Mail
    $mail = new \Mailgun\Mailgun(MAILGUN_KEY);
    // Validation
    $rules = ['name' => ['required', 'alpha', 'min_length(3)', 'max_length(60)'], 'email' => ['email', 'required'], 'content' => ['required']];
    $input = ['name' => $app->request->post('name'), 'email' => $app->request->post('email'), 'content' => $app->request->post('content')];
    $validation_result = \SimpleValidator\Validator::validate($_POST, $rules);
    if ($validation_result->isSuccess()) {
        $contact = new Contact();
        $contact->name = $app->request->post('name');
        $contact->email = $app->request->post('email');
        $contact->content = $app->request->post('content');
        // Saving it to database? not necessary but WTH not =3
        $contact->save();
        $mail->sendMessage(MAILGUN_DOMAIN, array('from' => MAIL_FROM, 'to' => MAIL_TO, 'subject' => 'SHARE SOMETHING SUPPORT: CONTACT RESPONSE', 'text' => 'Contact request from: ' . $app->request->post('name') . '\\n' . 'Email: ' . $app->request->post('email') . '\\n' . 'Content: ' . ' ' . $app->request->post('content')));
        $app->redirectTo('site.index');
    } else {
        require_once __DIR__ . '/../errors.php';
    }
})->name('contact.post');
Пример #20
0
 /**
  * Validate assignee change
  *
  * @access public
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validateAssigneeModification(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('id', t('The id is required')), new Validators\Integer('id', t('This value must be an integer')), new Validators\Required('project_id', t('The project is required')), new Validators\Integer('project_id', t('This value must be an integer')), new Validators\Required('owner_id', t('This value is required')), new Validators\Integer('owner_id', t('This value must be an integer'))));
     return array($v->execute(), $v->getErrors());
 }
Пример #21
0
 /**
  * Validate modification
  *
  * @access public
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validateModification(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('id', t('Field required')), new Validators\Required('opposite_id', t('Field required')), new Validators\Required('label', t('Field required')), new Validators\Unique('label', t('This label must be unique'), $this->db->getConnection(), self::TABLE)));
     return array($v->execute(), $v->getErrors());
 }
Пример #22
0
function validate_modification(array $values)
{
    $rules = array(new Validators\Required('username', t('The user name is required')), new Validators\MaxLength('username', t('The maximum length is 50 characters'), 50), new Validators\Required('autoflush', t('Value required')), new Validators\Required('autoflush_unread', t('Value required')), new Validators\Required('items_per_page', t('Value required')), new Validators\Integer('items_per_page', t('Must be an integer')), new Validators\Required('theme', t('Value required')), new Validators\Integer('frontend_updatecheck_interval', t('Must be an integer')), new Validators\Integer('debug_mode', t('Must be an integer')), new Validators\Integer('nocontent', t('Must be an integer')), new Validators\Integer('favicons', t('Must be an integer')), new Validators\Integer('original_marks_read', t('Must be an integer')));
    if (ENABLE_AUTO_UPDATE) {
        $rules[] = new Validators\Required('auto_update_url', t('Value required'));
    }
    if (!empty($values['password'])) {
        $rules[] = new Validators\Required('password', t('The password is required'));
        $rules[] = new Validators\MinLength('password', t('The minimum length is 6 characters'), 6);
        $rules[] = new Validators\Required('confirmation', t('The confirmation is required'));
        $rules[] = new Validators\Equals('password', 'confirmation', t('Passwords don\'t match'));
    }
    $v = new Validator($values, $rules);
    return array($v->execute(), $v->getErrors());
}
Пример #23
0
 /**
  * Validate action creation
  *
  * @access public
  * @param  array   $values           Required parameters to save an action
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validateCreation(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('project_id', t('The project id is required')), new Validators\Integer('project_id', t('This value must be an integer')), new Validators\Required('event_name', t('This value is required')), new Validators\Required('action_name', t('This value is required')), new Validators\Required('params', t('This value is required'))));
     return array($v->execute(), $v->getErrors());
 }
 /**
  * Validate fields
  *
  * @access protected
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 protected function validateFields(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('captcha', t('This value is required')), new Validators\Required('username', t('The username is required')), new Validators\MaxLength('username', t('The maximum length is %d characters', 50), 50)));
     return array($v->execute(), $v->getErrors());
 }
Пример #25
0
 /**
  * Validate
  *
  * @access public
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validate(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('currency', t('Field required')), new Validators\Required('rate', t('Field required'))));
     return array($v->execute(), $v->getErrors());
 }
Пример #26
0
 /**
  * Validate filter modification
  *
  * @access public
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validateModification(array $values)
 {
     $rules = array(new Validators\Required('id', t('Field required')), new Validators\Integer('id', t('This value must be an integer')));
     $v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
     return array($v->execute(), $v->getErrors());
 }
Пример #27
0
 /**
  * Validate time tracking modification (form)
  *
  * @access public
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validateTimeModification(array $values)
 {
     $rules = array(new Validators\Required('id', t('The id is required')));
     $v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
     return array($v->execute(), $v->getErrors());
 }
Пример #28
0
 /**
  * Validate creation/modification
  *
  * @access public
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validate(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('task_id', t('The task id is required')), new Validators\Integer('task_id', t('The task id must be an integer')), new Validators\Required('title', t('The title is required')), new Validators\MaxLength('title', t('The maximum length is %d characters', 100), 100), new Validators\Integer('user_id', t('The user id must be an integer')), new Validators\Integer('status', t('The status must be an integer')), new Validators\Numeric('time_estimated', t('The time must be a numeric value')), new Validators\Numeric('time_spent', t('The time must be a numeric value'))));
     return array($v->execute(), $v->getErrors());
 }
Пример #29
0
 /**
  * Validate column creation
  *
  * @access public
  * @param  array   $values           Required parameters to save an action
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validateCreation(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('project_id', t('The project id is required')), new Validators\Integer('project_id', t('This value must be an integer')), new Validators\Required('title', t('The title is required')), new Validators\MaxLength('title', t('The maximum length is %d characters', 50), 50)));
     return array($v->execute(), $v->getErrors());
 }
Пример #30
0
function validate_modification(array $values)
{
    $v = new Validator($values, array(new Validators\Required('id', t('The feed id is required')), new Validators\Required('title', t('The title is required')), new Validators\Required('site_url', t('The site url is required')), new Validators\Required('feed_url', t('The feed url is required'))));
    $result = $v->execute();
    $errors = $v->getErrors();
    return array($result, $errors);
}