public function _upload_image(Validate $array, $input) { if ($array->errors()) { // Don't bother uploading return; } // Get the image from the array $image = $array[$input]; if (!Upload::valid($image) or !Upload::not_empty($image)) { // No need to do anything right now return; } if (Upload::valid($image) and Upload::type($image, $this->types)) { $filename = strtolower(Text::random('alnum', 20)) . '.jpg'; if ($file = Upload::save($image, NULL, $this->directory)) { Image::factory($file)->resize($this->width, $this->height, $this->resize)->save($this->directory . $filename); // Update the image filename $array[$input] = $filename; // Delete the temporary file unlink($file); } else { $array->error('image', 'failed'); } } else { $array->error('image', 'valid'); } }
public function validate_latlong_required_as_pair(Validate $validate, $field) { // if we are already invalid, just return if (array_key_exists($field, $validate->errors())) { return; } $other_field = $field == 'lat' ? 'long' : 'lat'; if (!empty($validate[$field]) && empty($validate[$other_field])) { $validate->error($other_field, 'required_if_other_given', array($field)); } }
public function set($data) { foreach ($data as $key => $value) { $this->_fields[$key] = $value; } if (isset($this->schema)) { $validate = new Validate(); $validate->check($this->_fields, $this->schema, $this->_identifier); if (!$validate->passed()) { $this->_errors = $validate->errors(); } } $this->clean(); }
public static function dispatch($class) { if (!class_exists($class)) { include_once 'controllers/' . str_replace('_', '/', $class) . '.php'; } $instance = new $class(); $params = array_slice(func_get_args(), 1); $return = true; if (method_exists($instance, 'init')) { $return = call_user_func_array(array($instance, 'init'), $params); } if (!(true === $return)) { if (is_string($return) || $return instanceof Url) { Url::redirect($return); } return false; } $errors = array(); if (Request::isPost()) { $validation = new Validate(); if ($rules = $instance->validation()) { $validation->add($rules); $validation->validate(); } if ($validation->valid()) { $return = $instance->post(); if (!(false === $return)) { if (is_string($return) || $return instanceof Url) { Url::redirect($return); } return true; } } $errors = $validation->errors(); } $return = $instance->get(); if (!(false === $return)) { $return['errors'] = $errors; $view = new View($class, $return); $viewContent = $view->dispatch(); return $viewContent; } return false; }
function changePassword() { $input = Input::parse(); if (Token::check($input['token'])) { $validate = new Validate(); $validate->check($input, array('password_current' => ['required' => true, 'min' => 6], 'password' => ['required' => true, 'min' => 6], 'password_repeat' => ['required' => true, 'min' => 6, 'matches' => 'password'])); if ($validate->passed()) { $user = new User(); if (Hash::make($input['password_current'], config::get('encryption/salt')) !== $user->data()->password) { echo "incorrent password"; } else { $user->update(array('password' => Hash::make($input['password'], config::get('ecryption/salt')))); Session::flash('success', 'Successfully changed password'); Redirect::to('changepassword'); } } else { Session::flash('error', $validate->errors()); Redirect::to('changepassword'); } } }
/** * Processes an uploaded image * * @return null */ public function action_upload() { // Validate the upload first $validate = new Validate($_FILES); $validate->rules('image', array('Upload::not_empty' => null, 'Upload::valid' => null, 'Upload::size' => array('4M'), 'Upload::type' => array(array('jpg', 'png', 'gif')))); if ($validate->check(true)) { // Shrink the image to the lowest max dimension $image = Image::factory($_FILES['image']['tmp_name']); $constraints = Kohana::config('image')->constraints; $image->resize($constraints['max_width'], $constraints['max_height']); $image->save(APPPATH . 'photos/' . $_FILES['image']['name']); $photo = new Model_Vendo_Photo(); $photo->file = APPPATH . 'photos/' . $_FILES['image']['name']; $photo->save(); unlink(APPPATH . 'photos/' . $_FILES['image']['name']); $this->request->redirect('admin/photo'); } else { Session::instance()->set('errors', $validate->errors('validate')); $this->request->redirect('admin/photo'); } }
function signup() { $input = Input::parse(); if (Token::check($input['token'])) { $validate = new Validate(); $validate->check($input, array('username' => ['required' => true, 'min' => 5, 'max' => 20, 'unique' => 'users'], 'name' => ['required' => true, 'max' => 50], 'password' => ['required' => true, 'min' => 6])); if ($validate->passed()) { $user = new User(); $salt = config::get("encription/hash"); try { $user->create(array('username' => $input['username'], 'password' => Hash::make($input['password']), 'name' => $input['name'], 'joined' => date('Y-m-d H:i:s'), 'group_id' => 1)); } catch (Exception $e) { die($e->getMessage()); } Session::flash('login', 'You registered successfully! Please login!'); Redirect::to('login'); } else { Session::flash('error', $validate->errors()); Redirect::to('signup'); } } else { echo "Invalid token"; } }
public function action_recover_request() { $view = View::factory('login/recover'); if ('POST' == $_SERVER['REQUEST_METHOD']) { $post = new Validate($_POST); $post->rules('email', array('not_empty' => array(), 'email' => array())); if ($post->check()) { $user = ORM::factory('user')->where('email', '=', $post['email'])->find(); if ('True' == $user->email_verified) { $user->generate_key(); $user->save(); /* //send an email $q = new Pheanstalk_Model('codewars-email'); $q->put('password:'******'login/recover_email_html'); $text_email = View::factory('login/recover_email_text'); $link = url::site('login/recover/?' . 'key=' . $user->activation_key . '&id=' . $user->id); View::bind_global('link', $link); $email = new Model_Email(); $messages = $email->message(array($user->email => $user->fullname()), '[Code-Wars] Password Recovery', $html_email, $text_email); if (false === $messages) { $view->set('message', 'Looks like email has not been configured serverside'); } else { $view = View::factory('login/recover_sent'); } } else { $view->set('message', 'Your email address was not verified we can not send you a password recovery email'); } } else { $view->set('message', $post->errors('login_errors')); } } $this->request->response = $view; }
echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>'; echo 'Please verify you\'re not a robot'; echo '</div>'; break; default: echo '<div class="alert alert-danger alert-dismissible" role="alert">'; echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>'; echo $errors; echo '</div>'; break; } } unset($validate); } if (isset($otp_validate)) { foreach ($otp_validate->errors() as $errors) { echo '<div class="alert alert-warning alert-dismissible" role="alert">'; echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>'; echo $errors; echo '</div>'; } unset($otp_validate); } if (Session::exists('OTP Sending') && Session::get('OTP Sending') != 'Incorrect, Enter Again' && Session::get('OTP Sending') != '') { echo '<div class="alert alert-success alert-dismissible" role="alert">'; echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>'; echo Session::get('OTP Sending'); echo '</div>'; } if (Session::exists('OTP Sending') && Session::get('OTP Sending') == 'Incorrect, Enter Again') { echo '<div class="alert alert-danger alert-dismissible" role="alert">';
/** * Tests Validate::check() * * @test * @covers Validate::check * @covers Validate::callbacks * @covers Validate::callback * @covers Validate::rule * @covers Validate::rules * @covers Validate::errors * @covers Validate::error * @dataProvider provider_check * @param string $url The url to test * @param boolean $expected Is it valid? */ public function test_check($array, $rules, $callbacks, $expected, $expected_errors) { $validate = new Validate($array); foreach ($rules as $field => $rule) { $validate->rule($field, $rule[0], array($rule[1])); } foreach ($callbacks as $field => $callback) $validate->callback($field, $callback); $status = $validate->check(); $errors = $validate->errors(TRUE); $this->assertSame($expected, $status); $this->assertSame($expected_errors, $errors); $validate = new Validate($array); foreach ($rules as $field => $rule) $validate->rules($field, array($rule[0] => array($rule[1]))); $this->assertSame($expected, $validate->check()); }
public static function setErrors($errors) { self::$errors = $errors; }
public function action_log($project_id = 0) { // Get project data $project_data = $this->model_gather->get_project_data($project_id); // Verify that project exists if (count($project_data) == 0) { echo "<p>Project with this ID does not exist.</p>"; } else { $project_data = array_pop($project_data); $view = View::factory('template'); $view->page_title = $project_data['project_title'] . " - Gather Log"; $view->page_content = View::factory('pages/gather_log'); // Default results display $result_params = array('date_from' => 0, 'date_to' => 0, 'num_results' => 100, 'order' => 'desc'); $form_errors = ""; if ($_POST) { // Form validation $post = new Validate($_POST); $post->rule('datef_m', 'digit')->rule('datef_d', 'digit')->rule('datef_y', 'digit')->rule('datet_m', 'digit')->rule('datet_d', 'digit')->rule('datet_y', 'digit'); $field_data = $post->as_array(); // For form re-population if ($post->check()) { // Process results display parameters if ($field_data['datef_m'] > 0 and $field_data['datef_y'] > 0 and $field_data['datef_y'] > 0) { $result_params['date_from'] = mktime(0, 0, 0, $field_data['datef_m'], $field_data['datef_d'], $field_data['datef_y']); } if ($field_data['datet_m'] > 0 and $field_data['datet_y'] > 0 and $field_data['datet_y'] > 0) { $result_params['date_to'] = mktime(0, 0, 0, $field_data['datet_m'], $field_data['datet_d'], $field_data['datet_y']); } $result_params['num_results'] = $field_data['num_results']; $result_params['order'] = strtoupper($field_data['order']); } else { $form_errors = $post->errors('results'); } } else { // Populate form w/ empty values $field_data = array('datef_m' => '', 'datef_d' => '', 'datef_y' => '', 'datet_m' => '', 'datet_d' => '', 'datet_y' => '', 'num_results' => $result_params['num_results'], 'order' => $result_params['order']); } $results = $this->model_gather->get_gather_log($project_id, $result_params); $view->page_content->field_data = $field_data; $view->page_content->results = $results; $view->page_content->errors = $form_errors; $this->request->response = $view; } }
public function validate($source, $rules = []) { $this->errors = null; $validate = new Validate(); if (!empty($rules)) { if ($validate->check($source, $rules)->passed()) { return true; } else { $this->errors = $validate->errors(); return false; } } else { if (!empty($this->validate)) { if ($validate->check($source, $this->validate)->passed()) { return true; } else { $this->errors = $validate->errors(); return false; } } else { return true; } } return false; }
public function post($post_id) { $this->model('User'); $this->model('Article'); $user = new User(); $article = new Article(); $this->loginRequired($user); // If new post is to be created if (empty($post_id) || $post_id == 'new') { if (Input::exists()) { $validate = new Validate(); // Validation for Inputs $validation = $validate->check($_POST, array('title' => array('name' => 'Post title', 'required' => true, 'min' => 5), 'description' => array('name' => 'description', 'required' => true, 'min' => 50), 'featuredimage' => array('name' => 'Featured Image', 'required' => true), 'link' => array('name' => 'Article Link', 'required' => true, 'unique' => ARTICLE_TABLE))); if (empty(Input::get('type'))) { $type = 0; } else { $type = 1; } if ($validate->passed()) { $template = Strings::get('catagory'); try { $article->create(array('TITLE' => Input::get('title'), 'SECURL' => Input::get('catagory'), 'SUBSEC' => Input::get('subsec'), 'CREATED_DATE' => date("Y-m-d H:i:s", time()), 'IMG' => Input::get('featuredimage'), 'DES' => Input::get('description'), 'LINK' => Input::get('link'), 'TYPE' => $type, 'TEMPLATE' => Input::get('template'))); // Get the created article details from LINK to redirect the user to edit it. $newarticle = new Article(Input::get('link')); Redirect::to(ADMINPATH . 'post/' . $newarticle->data()->SL_NO); } catch (Exception $e) { die($e->getMessage()); } if (isset($data)) { $submissionData = Input::values($_POST); $data = array_merge($data, $submissionData); } else { $data = Input::values($_POST); } } else { $data = $validate->errors(); } } if (isset($data)) { $submissionData = Input::values($_POST); $data = array_merge($data, $submissionData); } else { $data = Input::values($_POST); } $data['CATAGORY'] = Strings::get('catagory'); $data['SUBCATAGORY'] = Strings::get('subcatagory'); $data['TEMPLATES'] = Strings::get('templates'); $data['token'] = Token::generate(); $data['TITLE'] = "Create New Post"; $this->view('admin/post.new.html', $data); } else { /** * Edit Post section * * The edit and after creation events happen here */ $article = new Article($post_id); if (Input::exists()) { $validate = new Validate(); // Validation for Inputs $validation = $validate->check($_POST, array('title' => array('name' => 'Post title', 'required' => true, 'min' => 5), 'description' => array('name' => 'description', 'required' => true, 'min' => 50), 'featuredimage' => array('name' => 'Featured Image', 'required' => true))); // If Article URL is changed check if it already exist if ($validate->passed() && $article->data()->LINK != Input::get('link')) { $validation = $validate->check($_POST, array('link' => array('name' => 'Article Link', 'required' => true, 'unique' => ARTICLE_TABLE))); } if (empty(Input::get('type'))) { $type = 0; } else { $type = 1; } if (empty(Input::get('featured'))) { $featured = 0; } else { $featured = 1; } if (Input::get('publish') == 1) { $publish = $article->data()->STATUS ? 0 : 1; } else { $publish = $article->data()->STATUS; } if ($validation) { $template = Strings::get('catagory'); try { $article->update(array('TITLE' => Input::get('title'), 'SECURL' => Input::get('catagory'), 'SUBSEC' => Input::get('subsec'), 'CONTENT' => Input::get('content'), 'DATE' => Input::get('date'), 'IMG' => Input::get('featuredimage'), 'DES' => Input::get('description'), 'LINK' => Input::get('link'), 'TYPE' => $type, 'TEMPLATE' => Input::get('template'), 'FEATURED' => $featured, 'STATUS' => $publish), $post_id); Redirect::to(ADMINPATH . 'post/' . $post_id); } catch (Exception $e) { die($e->getMessage()); } if (isset($data)) { $submissionData = Input::values($_POST); $data = array_merge($data, $submissionData); } else { $data = Input::values($_POST); } } else { $data = $validate->errors(); } } if ($article->count()) { if (isset($data)) { $data = array_merge($data, objectToArray($article->data())); } else { $data = objectToArray($article->data()); } $data['CATAGORY'] = Strings::get('catagory'); $data['SUBCATAGORY'] = Strings::get('subcatagory'); $data['TEMPLATES'] = Strings::get('templates'); $data['CONTENT_RAW'] = $data['CONTENT']; $data['CONTENT'] = str_replace('[IMAGE]', MEDIAPATH, $data['CONTENT']); $data['CONTENT'] = $data['CONTENT']; $data['token'] = Token::generate(); $this->view('admin/post.html', $data); } } }
if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validate(); $validation = $validate->check($_POST, array('current_password' => array('required' => true, 'min' => 6), 'new_password' => array('required' => true, 'min' => 6), 'new_password_again' => array('required' => true, 'min' => 6, 'matches' => 'new_password'))); if ($validate->passed()) { if (Hash::make(Input::get('current_password'), $user->data()->salt) !== $user->data()->password) { Session::flash('error', 'Your current password is incorrect.'); Redirect::to('changepassword.php'); } else { $salt = Hash::salt(32); $user->update(array('password' => Hash::make(Input::get('new_password'), $salt), 'salt' => $salt)); Session::flash('success', 'Your password has been changed!'); Redirect::to('index.php'); } } else { foreach ($validate->errors() as $error) { echo $error, '<br>'; } } } } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>OOP Login/Register</title> <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"> <link href="css/material.css" rel="stylesheet">
if (Input::exists()) { //regeln für alle felder, analog zum erstellen eines events $validation->check($_POST, array('eventName' => array('name' => 'Event Name', 'required' => true, 'max' => 100), 'eventCast' => array('name' => 'Cast', 'max' => 255), 'eventDescription' => array('name' => 'Event Description', 'required' => true), 'eventDate' => array('name' => 'Event Date', 'required' => true, 'date' => true), 'eventTimeHour' => array('name' => 'Time of the Event ( Hours )', 'required' => true, 'minValue' => 0, 'maxValue' => 23), 'eventTimeMinute' => array('name' => 'Time of the Event ( Minutes )', 'required' => true, 'maxValue' => 59, 'minValue' => 0), 'eventDuration' => array('name' => 'Duration of the Event', 'required' => true, 'minValue' => 1), 'eventLink' => array('name' => 'Event Link', 'max' => 100), 'eventLinkDescription' => array('name' => 'Description of the EventLink', 'max' => 255), 'pricegroup' => array('name' => 'Price Group', 'required' => true))); //date-time stempel wird gebaut $rawdate = new DateTime(Input::get('eventDate') . ' ' . Input::get('eventTimeHour') . ':' . Input::get('eventTimeMinute') . ':00'); $date = $rawdate->format('Y-m-d H:i:s'); $duration = Input::get('eventDuration'); $endTime = strtotime("+{$duration} minutes", strtotime($date)); //hier wird überprüft ob ein event in einem zeitkonflikt mit einem anderen event steht $conflicts = DB::getInstance()->getInterferingEvents('event', 'date', $date, date('Y-m-d h:i:s', $endTime))->results(); if (count($conflicts)) { $validation->addError('Dieses Event steht in einem Zeitkonflikt mit einem bereits bestehendem Event'); $validation->setPassed(false); } if (!$validation->passed()) { foreach ($validation->errors() as $error) { echo $error . '<br>'; } } //wenn alles validiert werden konnte wird hier der event aktualisiert if ($validation->passed()) { //2015-11-12 15:26:53 das wollen wir $rawdate = new DateTime(Input::get('eventDate') . ' ' . Input::get('eventTimeHour') . ':' . Input::get('eventTimeMinute') . ':00'); $date = $rawdate->format('Y-m-d H:i:s'); $eventName = Input::get('eventName'); try { //neue daten werden in der db gespeichert $db->update('event', Input::get('id'), array('name' => $eventName, 'starring' => Input::get('eventCast'), 'description' => Input::get('eventDescription'), 'date' => $date, 'duration' => Input::get('eventDuration'), 'link' => Input::get('eventLink'), 'linkDescription' => Input::get('eventLinkDescription'), 'fk_genre_id' => Input::get('genre'))); $eventID = $db->get('event', array('name', '=', $eventName))->first()->id; $rowCount = $db->get('event_has_price', array('fk_event_id', '=', $_POST['delete']))->count(); //alte verknüpfungen mit pricegroups werden alle gelöscht
if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validate(); $validation = $validate->check($_POST, array('username' => array('required' => true, 'min' => 2, 'max' => 20, 'unique' => 'Users'), 'password' => array('required' => true, 'min' => 6, 'max' => 64), 'password_again' => array('required' => true, 'matches' => 'password'), 'name' => array('required' => true, 'min' => 2, 'max' => 50))); if ($validate->passed()) { $user = new User(); $salt = Hash::salt(32); try { $user->create(array('username' => Input::get('username'), 'password' => Hash::make(Input::get('password')), 'salt' => $salt, 'name' => Input::get('name'), 'joined' => date('Y-m-d H:i:s'), 'groupid' => 1)); Session::flash('home', 'You have been registered and can now log in'); Redirect::To(404); } catch (Exception $e) { die($e->getMessage()); } } else { print_r($validate->errors()); } } } ?> <form action="" method="POST"> <div class="field"> <label for="username">Username</label> <input type="text" name="username" id="username" value="" autocomplete="off"> </div> <div class="field"> <label for="password">Password</label> <input type="password" name="password" id="password" value=""> </div>