当前位置: 首页>>代码示例>>PHP>>正文


PHP Validation::factory方法代码示例

本文整理汇总了PHP中Validation::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::factory方法的具体用法?PHP Validation::factory怎么用?PHP Validation::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Validation的用法示例。


在下文中一共展示了Validation::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: custom_validate

 /**
  * Custom validation for this model - complements the default validate()
  *
  * @param   array  array to validate
  * @param   Auth   instance of Auth class; used for testing purposes
  * @return bool TRUE if validation succeeds, FALSE otherwise
  */
 public static function custom_validate(array &$post, Auth $auth = null)
 {
     // Initalize validation
     $post = Validation::factory($post)->pre_filter('trim', TRUE);
     if ($auth === null) {
         $auth = new Auth();
     }
     $post->add_rules('username', 'required', 'length[3,100]', 'alpha_numeric');
     $post->add_rules('name', 'required', 'length[3,100]');
     $post->add_rules('email', 'required', 'email', 'length[4,64]');
     // If user id is not specified, check if the username already exists
     if (empty($post->user_id)) {
         $post->add_callbacks('username', array('User_Model', 'unique_value_exists'));
         $post->add_callbacks('email', array('User_Model', 'unique_value_exists'));
     }
     // Only check for the password if the user id has been specified
     if (empty($post->user_id)) {
         $post->add_rules('password', 'required', 'length[5,50]', 'alpha_numeric');
     }
     // If Password field is not blank
     if (!empty($post->password) or empty($post->password) and !empty($post->password_again)) {
         $post->add_rules('password', 'required', 'length[5,50]', 'alpha_numeric', 'matches[password_again]');
     }
     $post->add_rules('role', 'required', 'length[3,30]', 'alpha_numeric');
     $post->add_rules('notify', 'between[0,1]');
     if (!$auth->logged_in('superadmin')) {
         $post->add_callbacks('role', array('User_Model', 'prevent_superadmin_modification'));
     }
     // Additional validation checks
     Event::run('ushahidi_action.user_submit_admin', $post);
     // Return
     return $post->validate();
 }
开发者ID:neumicro,项目名称:Ushahidi_Web_Dev,代码行数:40,代码来源:user.php

示例2: action_login

 public function action_login()
 {
     if (Auth::check()) {
         Response::redirect('/');
         // user already logged in
     }
     $val = Validation::factory('users');
     $val->add_field('username', 'Your username', 'required|min_length[3]|max_length[20]');
     $val->add_field('password', 'Your password', 'required|min_length[3]|max_length[20]');
     if ($val->run()) {
         $auth = Auth::instance();
         if ($auth->login($val->validated('username'), $val->validated('password'))) {
             Session::set_flash('notice', 'FLASH: logged in');
             Response::redirect('users');
         } else {
             $data['username'] = $val->validated('username');
             $data['errors'] = 'Wrong username/password. Try again';
         }
     } else {
         if ($_POST) {
             $data['username'] = $val->validated('username');
             $data['errors'] = 'Wrong username/password combo. Try again';
         } else {
             $data['errors'] = false;
         }
     }
     $this->template->title = 'Login';
     $this->template->logged_in = false;
     $this->template->errors = @$data['errors'];
     $this->template->content = View::factory('users/login', $data);
 }
开发者ID:bryanheo,项目名称:FuelPHP-Auth-AJAX,代码行数:31,代码来源:users.php

示例3: upload_csv

 /** 
  * Upload function for a JNCC style designations spreadsheet.
  */
 public function upload_csv()
 {
     try {
         // We will be using a POST array to send data, and presumably a FILES array for the
         // media.
         // Upload size
         $ups = Kohana::config('indicia.maxUploadSize');
         $_FILES = Validation::factory($_FILES)->add_rules('csv_upload', 'upload::valid', 'upload::required', 'upload::type[csv]', "upload::size[{$ups}]");
         if (count($_FILES) === 0) {
             echo "No file was uploaded.";
         } elseif ($_FILES->validate()) {
             if (array_key_exists('name_is_guid', $_POST) && $_POST['name_is_guid'] == 'true') {
                 $finalName = strtolower($_FILES['csv_upload']['name']);
             } else {
                 $finalName = time() . strtolower($_FILES['csv_upload']['name']);
             }
             $fTmp = upload::save('csv_upload', $finalName);
             url::redirect('taxon_designation/import_progress?file=' . urlencode(basename($fTmp)));
         } else {
             kohana::log('error', 'Validation errors uploading file ' . $_FILES['csv_upload']['name']);
             kohana::log('error', print_r($_FILES->errors('form_error_messages'), true));
             throw new ValidationError('Validation error', 2004, $_FILES->errors('form_error_messages'));
         }
     } catch (Exception $e) {
         $this->handle_error($e);
     }
 }
开发者ID:BirenRathod,项目名称:indicia-code,代码行数:30,代码来源:taxon_designation.php

示例4: action_forgot_password

 /**
  * Отправка письма на восстановление пароля
  * @return
  */
 public function action_forgot_password()
 {
     $this->template->title = $this->site_name . 'Восстановление пароля';
     $this->template->bc['#'] = 'Восстановление пароля';
     if ($_POST) {
         $validation = Validation::factory($_POST)->rule('username_email', 'not_empty');
         if ($validation->check()) {
             $have_user = DB::select('email', 'id', 'username')->from('users')->where('username', '=', $validation['username_email'])->or_where('email', '=', $validation['username_email'])->execute()->current();
             if ($have_user) {
                 //echo $have_user;
                 $key = md5($validation['username_email']);
                 DB::insert('recover_passwords', array('key', 'user_id'))->values(array($key, $have_user['id']))->execute();
                 $email_view = View::factory('email/recover_password')->set('username', $have_user['username'])->set('key', $key)->render();
                 Email::send($have_user['email'], array('no-reply@as-avtoservice.ru', 'Ассоциация автосервисов'), 'Восстановление пароля', $email_view, true);
                 $view = View::factory('frontend/auth/forgot_send_email_complete');
                 $this->template->content = $view;
                 return;
             } else {
                 $this->errors['username_email'] = 'Такой пользователь не найден';
             }
         } else {
             $this->errors = $validation->errors('registration');
         }
     }
     $this->view = View::factory('frontend/auth/forgot')->set('values', $this->values)->set('errors', $this->errors);
     $this->template->content = $this->view;
 }
开发者ID:Alexander711,项目名称:naav1,代码行数:31,代码来源:auth.php

示例5: _validation

 /**
  * Validation image file
  *
  * @return $this
  * @throws Exception
  */
 private function _validation()
 {
     if (!Upload::valid(Arr::get($_FILES, $this->_config['fn']))) {
         throw new Exception('Error field input name');
     }
     return Validation::factory($_FILES)->rule($this->_config['fn'], 'Upload::valid')->rule($this->_config['fn'], 'Upload::type', array(':value', array('jpg', 'jpeg', 'png', 'gif')))->rule($this->_config['fn'], 'Upload::size', array(':value', '10M'))->rule($this->_config['fn'], 'Upload::image');
 }
开发者ID:eok8177,项目名称:shopCMS,代码行数:13,代码来源:Fileuploaders.php

示例6: action_view

 function action_view()
 {
     $open_coupon = Arr::get($_GET, 'print_coupon', FALSE);
     $service = ORM::factory('service', $this->request->param('id', NULL));
     if (!$service->loaded() || !$service->active) {
         Message::set(Message::ERROR, 'Такой сервис не найден');
         $this->request->redirect('/');
     }
     $this->validation = Validation::factory($_POST)->rule('antibot', 'not_empty');
     if ($_POST) {
         $review = ORM::factory('review');
         try {
             $review->values($_POST, array('text', 'email'));
             $review->date = Date::formatted_time();
             $review->service_id = $service->id;
             $review->active = 0;
             //$review->user_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
             $review->save($this->validation);
             Message::set(Message::SUCCESS, Kohana::message('success_msg', 'review_created'));
             $this->request->redirect('services/' . $service->id);
         } catch (ORM_Validation_Exception $e) {
             $this->errors = $e->errors('models');
             $this->values = $_POST;
         }
     }
     $this->view = View::factory('frontend/services/view_service')->set('service', $service)->set('open_coupon', $open_coupon)->set('coupon_frame', HTML::iframe('services/get_coupon/' . $service->id, 'coupon_frame'))->set('values', $this->values)->set('errors', $this->errors);
     $this->template->bc['/'] = 'Главная';
     $this->template->bc['#'] = $service->name;
     $this->template->title = 'Автосервис ' . $service->name . ' ' . $service->about;
     $this->template->meta_description = strip_tags($service->about);
     $this->add_js('http://api-maps.yandex.ru/1.1/index.xml?key=' . $this->settings['YMaps_key'] . '&onerror=map_alert');
     $this->add_js('assets/js/maps_detail.js');
     $this->add_js('assets/share42/share42.js');
     $this->template->content = $this->view;
 }
开发者ID:Alexander711,项目名称:naav1,代码行数:35,代码来源:services.php

示例7: action_hashpass

 public function action_hashpass()
 {
     $this->template->positionleft = false;
     //Создание обьекта авторизации
     $auth = Auth::instance();
     $data = array();
     if ($auth->logged_in()) {
         if ($_POST) {
             $post = Validation::factory($_POST);
             $post->rule('password_old', 'not_empty')->rule('password_old', 'Model_Myuser::not_password')->rule('password_new', 'not_empty')->rule('password_confirm', 'not_empty')->rule('password_confirm', 'matches', array(':validation', 'password_new', ':field'));
             if ($post->check()) {
                 $model = ORM::factory('myuser')->where("id", "=", $auth->get_user()->id)->find();
                 $model->password = $auth->hash_password($post['password_new']);
                 $model->save();
                 $this->redirect('main');
             } else {
                 $data = $post->errors("chanepass");
             }
         }
         $view = View::factory('chanepass');
         $view->data = $data;
         // $this->template->content = View::factory($view);
         $this->template->content = $view;
     } else {
         $this->redirect('auth');
     }
 }
开发者ID:N-Vitas,项目名称:sdsystem,代码行数:27,代码来源:Auth.php

示例8: action_archivos

 public function action_archivos()
 {
     $errors = array();
     $id = $_GET['contra'];
     $proceso = ORM::factory('gestiones', $id);
     if ($_POST) {
         $id_archivo = 0;
         $archivo_texto = '';
         $post = Validation::factory($_FILES)->rule('archivo', 'Upload::not_empty')->rule('archivo', 'Upload::type', array(':value', array('jpg', 'png', 'gif', 'pdf', 'doc', 'docx', 'ppt', 'xls', 'xlsx')))->rule('archivo', 'Upload::size', array(':value', '3M'));
         // ->rules ( 'archivo', array (array ('Upload::valid' ), array ('Upload::type', array (':value', array ('pdf', 'doc', 'docx', 'ppt', 'xls', 'xlsx' ) ) ), array ('Upload::size', array (':value', '5M' ) ) ) );
         //si pasa la validacion guardamamos
         if ($post->check()) {
             //guardamos el archivo
             $filename = upload::save($_FILES['archivo1']);
             $archivo1 = ORM::factory('archivos1');
             //intanciamos el modelo
             $archivo1->archivo = basename($filename);
             $archivo1->extension = $_FILES['archivo']['type'];
             $archivo1->size = $_FILES['archivo']['size'];
             $archivo1->fecha = date('Y-m-d');
             $archivo1->proceso_id = $_POST['proceso_id'];
             // $archivo->id = $nuevo->id;
             $archivo->save();
             $_POST = array();
             //enviamos email
             // $this->template->content=View::factory('digitales');
         } else {
             $errors['Datos'] = 'No se pudo guardar, vuelva a intentarlo';
         }
     } else {
         $errors['Archivos'] = 'Ocurrio un error al subir el archivo';
     }
     $archivos = ORM::factory('archivos')->where('proceso_id', '=', $id)->find_all();
     $this->template->content = View::factory('Archivos')->bind('errors', $errors)->bind('proceso', $proceso)->bind('archivos', $archivos);
 }
开发者ID:sysdevbol,项目名称:entidad,代码行数:35,代码来源:archivos1.php

示例9: action_ajax_add_feedback

 public function action_ajax_add_feedback()
 {
     if ($_POST) {
         $errors = array('name' => 'false', 'text' => 'false', 'email' => 'false', 'check' => 'false', 'phone' => 'false');
         if (Validation::factory($_POST)->rule('email', 'email')->rule('email', 'not_empty')->check()) {
             $errors['email'] = 'true';
         }
         if (Validation::factory($_POST)->rule('phone', 'not_empty')->check()) {
             $errors['phone'] = 'true';
         }
         if (Validation::factory($_POST)->rule('name', 'not_empty')->check()) {
             $errors['name'] = 'true';
         }
         if (Validation::factory($_POST)->rule('text', 'not_empty')->check()) {
             $errors['text'] = 'true';
         }
         $check = arr::get($_POST, 'check');
         if (!$check) {
             $errors['check'] = 'true';
         }
         if ($errors['name'] == 'true' && $errors['email'] == 'true' && $errors['phone'] == 'true' && $errors['text'] == 'true' && $errors['check'] == 'true') {
             $feedback = ORM::factory('Feedback');
             $feedback->name = arr::get($_POST, 'name');
             $feedback->phone = arr::get($_POST, 'phone');
             $feedback->email = arr::get($_POST, 'email');
             $feedback->text = arr::get($_POST, 'text');
             $feedback->save();
             Email::send('info@trip-shop.by', array('info@trip-shop.by', 'Trip-Shop'), 'Новый отзыв', 'Имя - ' . arr::get($_POST, 'name') . '<br/>' . 'Email - ' . arr::get($_POST, 'email') . '<br/>' . 'Телефон - ' . arr::get($_POST, 'phone') . '<br/>' . arr::get($_POST, 'text'), true);
         }
         echo json_encode($errors);
     } else {
         $this->forward_404();
     }
 }
开发者ID:ariol,项目名称:adminshop,代码行数:34,代码来源:Ajax.php

示例10: login

 public function login()
 {
     // if user is logged in, redirect refering page
     $validation = Validation::factory($_POST)->pre_filter('trim', TRUE)->add_rules('username', 'required')->add_rules('password', 'required');
     $return_path = $this->session->get('return_path') ? $this->session->get('return_path') : '/';
     $login = View::factory('pages/login');
     $login->login_failed = false;
     if ($_POST) {
         if (!$validation->validate()) {
             $login->login_failed = true;
             $form = $validation->as_array();
             $errors = $validation->errors('custom_error');
         } else {
             $username = $validation->username;
             $password = $validation->password;
             if ($this->auth->login($username, $password, true)) {
                 // Login successful, redirect
                 Session::instance()->set_flash('flash', SubfolioLanguage::get_text('login_complete'));
                 url::redirect($return_path);
                 exit;
             } else {
                 $login->login_failed = true;
                 Session::instance()->set_flash('error', SubfolioLanguage::get_text('login_failed'));
             }
         }
     } else {
         $login->login_failed = false;
     }
     $this->template->content = $login;
 }
开发者ID:romyilano,项目名称:subfolio,代码行数:30,代码来源:filebrowser.php

示例11: action_share

 /**
  * REST endpoint for sharing droplets via email
  */
 public function action_share()
 {
     $this->template = '';
     $this->auto_render = FALSE;
     if ($this->request->method() != "POST") {
         throw HTTP_Exception::factory(405)->allowed('POST');
     }
     // Extract the input data to be used for sending the email
     $post = Arr::extract($_POST, array('recipient', 'drop_title', 'drop_url', 'security_code'));
     $csrf_token = $this->request->headers('x-csrf-token');
     // Setup validation
     $validation = Validation::factory($post)->rule('recipient', 'not_empty')->rule('recipient', 'email')->rule('security_code', 'Captcha::valid')->rule('drop_title', 'not_empty')->rule('drop_url', 'url');
     // Validate
     if (!CSRF::valid($csrf_token) or !$validation->check()) {
         Kohana::$log->add(Log::DEBUG, "CSRF token or form validation failure");
         throw HTTP_Exception::factory(400);
     } else {
         list($recipient, $subject) = array($post['recipient'], $post['drop_title']);
         // Modify the mail body to include the email address of the
         // use sharing content
         $mail_body = __(":user has shared a drop with you via SwiftRiver\n\n:url", array(':user' => $this->user['owner']['username'], ':url' => $post['drop_url']));
         // Send the email
         Swiftriver_Mail::send($recipient, $subject, $mail_body);
     }
 }
开发者ID:aliyubash23,项目名称:SwiftRiver,代码行数:28,代码来源:Base.php

示例12: _login

 private function _login()
 {
     $array = $this->request->post('login');
     $array = Validation::factory($array)->label('username', 'Username')->label('password', 'Password')->label('email', 'Email')->rules('username', array(array('not_empty')))->rules('password', array(array('not_empty')));
     $fieldname = Valid::email(Arr::get($array, 'username')) ? Auth::EMAIL : Auth::USERNAME;
     // Get the remember login option
     $remember = isset($array['remember']);
     Observer::notify('admin_login_validation', $array);
     if ($array->check()) {
         Observer::notify('admin_login_before', $array);
         if (Auth::instance()->login($array['username'], $array['password'], $remember)) {
             Observer::notify('admin_login_success', $array['username']);
             Session::instance()->delete('install_data');
             Kohana::$log->add(Log::INFO, ':user login')->write();
             if ($next_url = Flash::get('redirect')) {
                 $this->go($next_url);
             }
             // $this->go to defaut controller and action
             $this->go_backend();
         } else {
             Observer::notify('admin_login_failed', $array);
             Messages::errors(__('Login failed. Please check your login data and try again.'));
             $array->error($fieldname, 'incorrect');
             Kohana::$log->add(Log::ALERT, 'Try to login with :field: :value. Incorrect data', array(':field' => $fieldname, ':value' => $array['username']))->write();
         }
     } else {
         Messages::errors($array->errors('validation'));
     }
     $this->go(Route::get('user')->uri(array('action' => 'login')));
 }
开发者ID:ZerGabriel,项目名称:cms-1,代码行数:30,代码来源:login.php

示例13: extra_rules

 public function extra_rules()
 {
     $received = UTF8::get_value($this->_form, "min") + UTF8::get_value($this->_form, "max");
     $sent = UTF8::get_value($this->_form, "captcha");
     $captcha = array("sent" => (string) $sent, "received" => (string) $received);
     return Validation::factory($this->_form)->rule("display_name", "not_empty")->rule("display_name", "regex", array(":value", "/^[a-z_.]++\$/iD"))->rule("user_email", "not_empty")->rule("user_email", "Valid::email")->rule("user_email", "Valid::email_domain")->rule("phone", "not_empty")->rule("phone", "Valid::phone", array(":value", array(9, 10, 11)))->rule("reason", "not_empty")->rule("message", "not_empty")->rule("message", "min_length", array(":value", 4))->rule("message", "max_length", array(":value", 150))->rule("captcha", "not_empty")->rule("captcha", "Valid::matches", array($captcha, "sent", "received"))->rule("overflow", "is_empty")->rule("csrf", "not_empty")->rule("csrf", "Security::check");
 }
开发者ID:benshez,项目名称:DreamWeddingCeremonies,代码行数:7,代码来源:Contact.php

示例14: addPortfolio

 public function addPortfolio($no)
 {
     $tempFileName = 'file' . rand(10000000, 99999999);
     $validationFiles = Validation::factory($_FILES)->rules('portfolioSmall', array(array('Upload::not_empty'), array('Upload::image')))->rules('portfolioBig', array(array('Upload::not_empty'), array('Upload::image')));
     $validationText = Validation::factory($_POST)->rule('name', 'not_empty');
     if ($validationFiles->check() and $validationText->check()) {
         Upload::save($validationFiles['portfolioSmall'], $tempFileName . '.png', Upload::$default_directory);
         Upload::save($validationFiles['portfolioBig'], $tempFileName . '.jpg', Upload::$default_directory);
         $tempFileNamePath = Upload::$default_directory . $tempFileName;
         $filePath = Kohana::$config->load('portfolio')->get('filePath');
         if (copy($tempFileNamePath . '.png', $filePath . $tempFileName . '.png') and copy($tempFileNamePath . '.jpg', $filePath . $tempFileName . '.jpg')) {
             unlink($tempFileNamePath . '.png');
             unlink($tempFileNamePath . '.jpg');
             $this->path = $tempFileName;
             $this->name = HTML::chars($_POST['name']);
             $this->type = HTML::chars($_POST['type']);
             if (!$no) {
                 $this->no = (int) $this->maxNoPortfolio() + 1;
             } else {
                 $this->no = $no;
             }
             $this->create();
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
开发者ID:alex-bro,项目名称:olgabro.repo,代码行数:30,代码来源:Portfolio.php

示例15: action_register

 public function action_register()
 {
     if (\Auth::check()) {
         \Session::set_flash('error', 'FLASH: Can\'t register while logged in, log out first.');
         \Output::redirect('myauth');
     }
     // The same fields as the example above
     $val = \Validation::factory('myauth2');
     $val->add_field('username', 'Your username', 'required|min_length[3]|max_length[20]');
     //        $val->add_field('username', 'Your username', 'required|min_length[3]|max_length[20]|unique[simpleauth.username]');
     $val->add_field('password', 'Your password', 'required|min_length[3]|max_length[20]');
     $val->add_field('email', 'Email', 'required|valid_email');
     // run validation on just post
     if ($val->run()) {
         if (\Auth::instance()->create_user($val->validated('username'), $val->validated('password'), $val->validated('email'), '100')) {
             \Session::set_flash('notice', 'FLASH: User created.');
             \Output::redirect('myauth');
         } else {
             throw new Exception('Smth went wrong while registering');
         }
     } else {
         // validation failed
         if ($_POST) {
             $data['username'] = $val->validated('username');
             $data['login_error'] = 'All fields are required.';
         } else {
             $data['login_error'] = false;
         }
     }
     $this->template->title = 'Myauth &raquo Register';
     $this->template->login_error = @$data['login_error'];
     $this->template->content = \View::factory('register');
 }
开发者ID:huglester,项目名称:fuel-uploadify,代码行数:33,代码来源:myauth.php


注:本文中的Validation::factory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。