/**
  * Get validation result (list of parameter keys with boolean values)
  *
  * @param object $candidate  Object to test
  * @return array
  *
  * @access public
  */
 public function get_validation($candidate)
 {
     $v = new Validate();
     $options = $this->get_valid_options();
     $ret = $v->multiple($candidate, $options);
     return $ret;
 }
Esempio n. 2
0
    function changeEmail()
    {
        $validator = new Validate();
        $validated = $validator->validateNewEmail();
        $user = \Auth::user();
        $email = $user->email;
        if ($validated->fails()) {
            return \View::make('accounts.email')->withErrors($validated)->withEmail($email);
        }
        if (\Auth::check()) {
            $id = \Auth::user()->user_id;
            \DB::beginTransaction();
            try {
                $statement = \User::find($id);
                $statement->email = \Input::get('email');
                $statement->save();
            } catch (ValidationException $e) {
                DB::rollback();
                throw $e;
            }
            \DB::commit();
            return \Redirect::to('admin/account/edit/email')->with('message', '<p class="alert alert-dismissible alert-success alert-link">Email address updated.	
				</p>')->withEmail($email);
        }
        return \Redirect::to('admin/account/edit/email')->with('message', '<p class="alert alert-dismissible alert-success alert-link">Email address updated.
				</p>')->withEmail($email);
    }
Esempio n. 3
0
 /**
  * 修改专题分类
  */
 public function detailAction($art_ban_id)
 {
     //判断是否是ajax
     if ($this->request->isAjax()) {
         $validate = new \Validate();
         $data['top_cat_id'] = $validate->getPost('top_cat_id', ['int']);
         //专题id
         $data['top_cat_name'] = $validate->getPost('top_cat_name', ['length' => ['max' => 30, 'min' => 0]], ['slashes' => true, 'html' => true]);
         //专题分类名称
         //验证参数
         if ($validate->getMessage()) {
             $this->end(400);
         }
         //修改专题
         $result = (new \TopicCategory())->updTopicCategory($this->session->get('id'), $data);
         $this->end($result);
     }
     //数据id
     $art_ban_id = (int) $art_ban_id;
     //专题分类详情
     $basic = (new \Topic())->getDetail($art_ban_id);
     //加载js
     $this->assets->addJs('backend/mt-js/topiccat.js');
     $this->view->setVars(['basic' => $basic]);
 }
Esempio n. 4
0
 /**
  * 编辑邮件模板
  */
 public function email_tpl_editOp()
 {
     $model_templates = Model('mail_templates');
     if (chksubmit()) {
         $obj_validate = new Validate();
         $obj_validate->validateparam = array(array("input" => $_POST["code"], "require" => "true", "message" => L('mailtemplates_edit_no_null')), array("input" => $_POST["title"], "require" => "true", "message" => L('mailtemplates_edit_title_null')), array("input" => $_POST["content"], "require" => "true", "message" => L('mailtemplates_edit_content_null')));
         $error = $obj_validate->validate();
         if ($error != '') {
             showMessage($error);
         } else {
             $update_array = array();
             $update_array['code'] = $_POST["code"];
             $update_array['title'] = $_POST["title"];
             $update_array['content'] = $_POST["content"];
             $result = $model_templates->editTpl($update_array, array('code' => $_POST['code']));
             if ($result === true) {
                 $this->log(L('nc_edit,email_tpl'), 1);
                 showMessage(L('mailtemplates_edit_succ'), 'index.php?act=message&op=email_tpl');
             } else {
                 $this->log(L('nc_edit,email_tpl'), 0);
                 showMessage(L('mailtemplates_edit_fail'));
             }
         }
     }
     if (empty($_GET['code'])) {
         showMessage(L('mailtemplates_edit_code_null'));
     }
     $templates_array = $model_templates->getTplInfo(array('code' => $_GET['code']));
     Tpl::output('templates_array', $templates_array);
     Tpl::output('top_link', $this->sublink($this->links, 'email_tpl'));
     Tpl::showpage('message.email_tpl.edit');
 }
Esempio n. 5
0
 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');
     }
 }
Esempio n. 6
0
    /**
     * 保存平台咨询
     */
    public function save_mallconsultOp() {
        if (!chksubmit()) {
            showDialog(L('wrong_argument'), 'reload');
        }

        //验证表单信息
        $obj_validate = new Validate();
        $obj_validate->validateparam = array(
            array("input"=>$_POST["type_id"],"require"=>"true","validator"=>"Number","message"=>"请选择咨询类型"),
            array("input"=>$_POST["consult_content"],"require"=>"true","message"=>"请填写咨询内容")
        );
        $error = $obj_validate->validate();
        if ($error != ''){
            showDialog($error);
        }

        $insert = array();
        $insert['mct_id'] = $_POST['type_id'];
        $insert['member_id'] = $_SESSION['member_id'];
        $insert['member_name'] = $_SESSION['member_name'];
        $insert['mc_content'] = $_POST['consult_content'];

        $result = Model('mall_consult')->addMallConsult($insert);
        if ($result) {
            showDialog(L('nc_common_op_succ'), 'reload', 'succ');
        } else {
            showDialog(L('nc_common_op_fail'), 'reload');
        }
    }
Esempio n. 7
0
 /**
  * Verifica que la persona exista.
  *
  * Se utiliza para otorgar las constancias.
  *
  * @param Validate $array
  * @param <type> $campo
  */
 public function existe(Validate $array, $campo)
 {
     if (ORM::factory("persona")->where("cedula", "=", $array[$campo])->count_all() == 0) {
         $array->error($campo, "no_existe");
     }
     return $array;
 }
Esempio n. 8
0
 /**
  * 新增属性
  */
 public function newAction()
 {
     //检查是否是ajax请求
     if ($this->request->isAjax()) {
         $validate = new \Validate();
         $data['att_img'] = $validate->getPost('att_img', \Validate::base64());
         //属性图
         $data['att_name'] = $validate->getPost('att_name', \Validate::regex('/^[a-z0-9\\x{4e00}-\\x{9fa5}]{2,30}$/iu'));
         //属性名称
         $data['att_sort'] = $validate->getPost('att_sort', \Validate::int());
         //排序
         //验证数据
         if ($validate->getMessage()) {
             $this->end(400);
         }
         //生成学校logo,缩略图
         $data['att_img'] = \Func::touchImg($data['att_img'], 'att_img');
         //将生成的图片地址存入img,用户失败时删除
         $img = [UPLOAD_PATH . $data['att_img'], UPLOAD_PATH . $data['att_img']];
         //监测图片是否全部生成成功
         if (!$data['att_img']) {
             \FileUtil::getInstance()->unlink($img);
         }
         //新增高校
         $result = (new \Attribute())->addAttribute($this->session->get('id'), $data);
         if ($result != 200) {
             \FileUtil::getInstance()->unlink($img);
         }
         $this->end($result);
     }
     //加载所需js
     $this->assets->addJs('backend/mt-js/attribute-new.js');
 }
Esempio n. 9
0
 /**
  * 合作机构基本信息
  */
 public function basicAction($uni_id)
 {
     //判断是否是ajax
     if ($this->request->isAjax()) {
         $validate = new \Validate();
         $data['union_logo'] = $validate->getPost('union_logo');
         //机构logo
         $data['union_name'] = $validate->getPost('union_name', \Validate::regex('/^[a-z0-9\\x{4e00}-\\x{9fa5}]{2,30}$/iu'));
         //机构名称
         //验证参数
         if ($validate->getMessage()) {
             $this->end(400);
         }
         //生成机构logo,缩略图
         if ($data['union_logo']) {
             $data['union_logo'] = \Func::touchImg($data['union_logo'], 'union_logo');
             //监测图片是否生成成功
             if (!$data['union_logo']) {
                 \FileUtil::getInstance()->unlink(UPLOAD_PATH . $data['union_logo']);
                 $this->end(400);
             }
         }
         $this->end((new \Union())->updUnionBasic($this->session->get('id'), $uni_id, $data));
     }
     //机构id
     $uni_id = (int) $uni_id;
     //获取基本数据
     $basic = (new \Union())->getUnionBasic($uni_id);
     //加载js
     $this->assets->addJs('backend/mt-js/union.js');
     $this->view->setVars(['uni_id' => $uni_id, 'basic' => $basic]);
 }
Esempio n. 10
0
 public function testOutOfExistsFieldNotFound()
 {
     $testdata = ["name" => "Foo Bar", "mobile" => "0912345678", "address" => "Hong Kong", "phone" => "12345678"];
     $chk = new Validate($testdata);
     $chk->outOf(["address", "phone", "mobile", "business"], 4);
     $this->assertFalse($chk->validate());
 }
Esempio n. 11
0
 public function newCategory()
 {
     $validate = new Validate();
     $validated = $validate->Validate_Category();
     $nameToSlug = $this->nameToSlug($validated);
     if (\Auth::check()) {
         if ($validated->passes() && $nameToSlug === true) {
             $slug = \Input::get('name');
             $slug = preg_replace('#[ -]+#', '-', $slug);
             $slug = strtolower($slug);
             \DB::beginTransaction();
             try {
                 $item = new \MenuCategory();
                 $item->menu_category_name = \Input::get('name');
                 $item->menu_category_slug = $slug;
                 $item->save();
             } catch (ValidationException $e) {
                 DB::rollback();
                 throw $e;
             }
             \DB::commit();
             return \Redirect::to('admin/category/edit/' . $slug)->with('message', '<div class="alert alert-dismissible alert-success alert-link"><button type="button" class="close" data-dismiss="alert">×</button>Saved!</p></div>');
         }
         if ($nameToSlug === false) {
             return \View::make('categories.new')->withErrors($validated)->withInput(array('name'))->with('message', '<p class="alert alert-dismissible alert-danger alert-link">That category already exists!');
         }
         return \View::make('categories.new')->withErrors($validated)->withInput(array('name'));
     }
     return \Redirect::to('admin');
 }
Esempio n. 12
0
 /**
  * 管理员编辑
  */
 public function admin_editOp()
 {
     /**
      * 保存
      */
     if (isset($_POST) && !empty($_POST)) {
         //表单验证
         $obj_validate = new Validate();
         $obj_validate->validateparam = array(array("input" => trim($_POST['admin_password']), "require" => "true", "message" => Language::get('nc_admin_admin_password_is_not_null')), array("input" => trim($_POST['admin_confirm_password']), "require" => "true", "message" => Language::get('nc_admin_password_confirm_is_not_null')));
         $error = $obj_validate->validate();
         if ($error != '') {
             $this->showTip(Language::get('error') . $error, '', 'error');
         }
         $condition = array();
         $condition['admin_id'] = intval($_POST['admin_id']);
         $params = array();
         $params['admin_password'] = md5(trim($_POST['admin_password']));
         $model = Model();
         $result = $model->table('admin')->where($condition)->update($params);
         if ($result) {
             $this->showTip(Language::get('nc_admin_edit_account_succ'));
         } else {
             $this->showTip(Language::get('nc_admin_edit_account_fail'));
         }
     }
     $admin_id = intval($_GET['admin_id']);
     $model = Model();
     $admininfo = $model->table('admin')->where(array('admin_id' => $admin_id))->find();
     if (empty($admininfo)) {
         $this->showTip(Language::get('nc_admin_add_account_succ'));
     }
     Tpl::output('admininfo', $admininfo);
     Tpl::showpage('admin.edit');
 }
Esempio n. 13
0
 /**
  * 新闻Banner列表
  */
 public function listAction()
 {
     if ($this->request->isAjax()) {
         $validate = new \Validate();
         $id = (int) $validate->getPost('id');
         if (!$id) {
             $this->end(400);
         }
         $this->end((new \SingleReward())->UpdateHandle($id));
     }
     //当前页码
     $page_id = (int) $this->request->getQuery('page');
     $page_id = $page_id < 1 ? 1 : $page_id;
     //每页显示条数
     $limit = 20;
     //显示状态
     $status = $this->request->getQuery('status');
     //关键字
     $keyword = preg_replace('/[^\\da-z\\x{4e00}-\\x{9fa5}]/iu', '', mb_substr($this->request->getQuery('keyword'), 0, 10, 'utf-8'));
     //关键字长度小于10,并且只能是字符数字中文
     //所有显示状态
     $statuses = \Setting::getStatus();
     $statuses = ['' => '所有状态'] + $statuses;
     //列表查询
     $list = (new \SingleReward())->getList($page_id, $limit, $status, $keyword);
     $page_html = $this->pageHtml($list['page']);
     //加载js
     $this->assets->addJs('backend/mt-js/single-reward.js');
     $this->view->setVars(['status' => $status, 'keyword' => $keyword, 'statuses' => $statuses, 'list' => $list['list'], 'page_html' => $page_html]);
 }
Esempio n. 14
0
 /**
  * Username callback to check if username is valid
  */
 public function check_username(Validate $array, $field)
 {
     $exists = (bool) DB::select(array('COUNT("*")', 'total_count'))->from('users')->where('username', '=', $array[$field])->execute()->get('total_count');
     if (!$exists) {
         $array->error($field, 'not_found', array($array[$field]));
     }
 }
Esempio n. 15
0
 /**
  * 修改小初高动态
  */
 public function detailAction($sch_dny_id)
 {
     //判断是否ajax
     if ($this->request->isAjax()) {
         $validate = new \Validate();
         $data['sch_id'] = $validate->getPost('sch_id', ['int']);
         //学校id
         $data['sch_dny_id'] = $validate->getPost('sch_dny_id', ['int']);
         //动态id
         $data['sch_dny_title'] = $validate->getPost('sch_dny_title', \Validate::length(60, 1), ['slashes' => true, 'html' => true]);
         //动态标题
         $data['sch_dny_content'] = $validate->getPost('sch_dny_content', \Validate::nil(), ['slashes' => true]);
         //动态内容
         //验证参数
         if ($validate->getMessage()) {
             $this->end(400);
         }
         $this->end((new \Dynamic())->updDynamic($this->session->get('id'), $data));
     }
     //动态id
     $sch_dny_id = (int) $sch_dny_id;
     //小初高学校动态数据
     $dynamic = (new \Dynamic())->getDynamicDetail($sch_dny_id);
     //获取学校类型
     $sch_dny_type = (new \Dynamic())->getDnyType($sch_dny_id);
     if ($sch_dny_type['sch_type'] == 1) {
         $this->view->setLayout("kindergarten");
     } else {
         $this->view->setLayout("school");
     }
     $this->view->setVars(['sch_dny_id' => $sch_dny_id, 'dynamic' => $dynamic, 'sch_id' => $dynamic['sch_id'], 'sch_dny_type' => $sch_dny_type]);
 }
Esempio n. 16
0
 public function loginAction()
 {
     $userInfo = Session::get('user');
     if ($userInfo['login'] == true && $userInfo['time'] + TIME_LOGIN >= time()) {
         URL::redirect('admin', 'index', 'index');
     }
     $this->_templateObj->setFolderTemplate('admin/main/');
     $this->_templateObj->setFileTemplate('login.php');
     $this->_templateObj->setFileConfig('template.ini');
     $this->_templateObj->load();
     $this->_view->_title = 'Login';
     if (@$this->_arrParam['form']['token'] > 0) {
         $validate = new Validate($this->_arrParam['form']);
         $username = @$this->_arrParam['form']['username'];
         $password = md5(@$this->_arrParam['form']['passwd']);
         $query = "SELECT `id` FROM `user` WHERE `username` = '{$username}' AND `password` = '{$password}'";
         $validate->addRule('username', 'existRecord', array('database' => $this->_model, 'query' => $query));
         $validate->run();
         if ($validate->isValid() == true) {
             $infoUser = $this->_model->infoItem($this->_arrParam);
             $arraySession = array('login' => true, 'info' => $infoUser, 'time' => time(), 'group_acp' => $infoUser['group_acp']);
             Session::set('user', $arraySession);
             URL::redirect('admin', 'index', 'index');
         } else {
             $this->_view->errors = $validate->showErrors();
         }
     }
     $this->_view->render('index/login', true);
 }
Esempio n. 17
0
 public function loginAction()
 {
     $userInfo = Session::get('user');
     if ($userInfo['login'] == true && $userInfo['time'] + TIME_LOGIN >= time()) {
         URL::redirect('default', 'user', 'index');
     }
     $this->_view->_title = 'Login';
     if (@$this->_arrParam['form']['token'] > 0) {
         $validate = new Validate($this->_arrParam['form']);
         $email = $this->_arrParam['form']['email'];
         $password = md5($this->_arrParam['form']['password']);
         $query = "SELECT `id` FROM `user` WHERE `email` = '{$email}' AND `password` = '{$password}'";
         $validate->addRule('email', 'existRecord', array('database' => $this->_model, 'query' => $query));
         $validate->run();
         if ($validate->isValid() == true) {
             $infoUser = $this->_model->infoItem($this->_arrParam);
             $arraySession = array('login' => true, 'info' => $infoUser, 'time' => time(), 'group_acp' => $infoUser['group_acp']);
             Session::set('user', $arraySession);
             URL::redirect('default', 'user', 'index');
         } else {
             $this->_view->errors = $validate->showErrorsPublic();
         }
     }
     $this->_view->render('index/login');
 }
Esempio n. 18
0
function verify_main_config($data)
{
    if (empty($data['server_name']) or empty($data['admin_firstname']) or empty($data['admin_lastname']) or empty($data['admin_email']) or empty($data['admin_pass']) or empty($data['admin_pass2'])) {
        global $errormessage;
        $errormessage = 'Some fields are missing. Please fill all required fields.';
        global $editdata;
        $editdata = $data;
        return false;
    }
    if ($data['admin_pass'] != $data['admin_pass2']) {
        global $errormessage;
        $errormessage = 'The passwords you entered to not match.';
        global $editdata;
        $editdata = $data;
        return false;
    }
    require_once MAD_PATH . '/modules/validation/validate.class.php';
    $validate = new Validate();
    if ($validate->isEmail($data['admin_email']) != true) {
        global $errormessage;
        $errormessage = 'Please enter a valid e-mail address.';
        global $editdata;
        $editdata = $data;
        return false;
    }
    return true;
}
Esempio n. 19
0
 /**
  * 上传参数设置
  *
  */
 public function paramOp()
 {
     if (chksubmit()) {
         $obj_validate = new Validate();
         $obj_validate->validateparam = array(array("input" => $_POST["image_max_filesize"], "require" => "true", "validator" => "Number", "message" => L('upload_image_filesize_is_number')), array("input" => trim($_POST["image_allow_ext"]), "require" => "true", "message" => L('image_allow_ext_not_null')));
         $error = $obj_validate->validate();
         if ($error != '') {
             showMessage($error);
         } else {
             $model_setting = Model('setting');
             $result = $model_setting->updateSetting(array('image_dir_type' => intval($_POST['image_dir_type']), 'image_max_filesize' => intval($_POST['image_max_filesize']), 'image_allow_ext' => $_POST['image_allow_ext']));
             if ($result) {
                 $this->log(L('nc_edit,upload_param'), 1);
                 showMessage(L('nc_common_save_succ'));
             } else {
                 $this->log(L('nc_edit,upload_param'), 0);
                 showMessage(L('nc_common_save_fail'));
             }
         }
     }
     //获取默认图片设置属性
     $model_setting = Model('setting');
     $list_setting = $model_setting->getListSetting();
     Tpl::output('list_setting', $list_setting);
     //输出子菜单
     Tpl::output('top_link', $this->sublink($this->links, 'param'));
     Tpl::showpage('upload.param');
 }
Esempio n. 20
0
 public function unbindOp()
 {
     //修改密码
     $model_member = Model('member');
     $update_arr = array();
     if ($_POST['is_editpw'] == 'yes') {
         /**
          * 填写密码信息验证
          */
         $obj_validate = new Validate();
         $obj_validate->validateparam = array(array("input" => $_POST["new_password"], "require" => "true", "validator" => "Length", "min" => 6, "max" => 20, "message" => Language::get('member_qqconnect_password_null')), array("input" => $_POST["confirm_password"], "require" => "true", "validator" => "Compare", "operator" => "==", "to" => $_POST["new_password"], "message" => Language::get('member_qqconnect_input_two_password_again')));
         $error = $obj_validate->validate();
         if ($error != '') {
             showMessage($error, '', 'html', 'error');
         }
         $update_arr['member_passwd'] = md5(trim($_POST['new_password']));
     }
     $update_arr['member_qqopenid'] = '';
     $update_arr['member_qqinfo'] = '';
     $edit_state = $model_member->updateMember($update_arr, $_SESSION['member_id']);
     if (!$edit_state) {
         showMessage(Language::get('member_qqconnect_password_modify_fail'), 'html', 'error');
     }
     session_unset();
     session_destroy();
     showMessage(Language::get('member_qqconnect_unbind_success'), 'index.php?act=login&ref_url=' . urlencode('index.php?act=member_qqconnect&op=qqbind'));
 }
Esempio n. 21
0
 /**
  * 编辑
  */
 public function store_class_editOp()
 {
     $lang = Language::getLangContent();
     $model_class = Model('store_class');
     if (chksubmit()) {
         //验证
         $obj_validate = new Validate();
         $obj_validate->validateparam = array(array("input" => $_POST["sc_name"], "require" => "true", "message" => $lang['store_class_name_no_null']));
         $error = $obj_validate->validate();
         if ($error != '') {
             showMessage($error);
         } else {
             $update_array = array();
             $update_array['sc_name'] = $_POST['sc_name'];
             $update_array['sc_bail'] = intval($_POST['sc_bail']);
             $update_array['sc_sort'] = intval($_POST['sc_sort']);
             $result = $model_class->editStoreClass($update_array, array('sc_id' => intval($_POST['sc_id'])));
             if ($result) {
                 $this->log(L('nc_edit,store_class') . '[' . $_POST['sc_name'] . ']', 1);
                 showMessage($lang['nc_common_save_succ'], 'index.php?act=store_class&op=store_class');
             } else {
                 showMessage($lang['nc_common_save_fail']);
             }
         }
     }
     $class_array = $model_class->getStoreClassInfo(array('sc_id' => intval($_GET['sc_id'])));
     if (empty($class_array)) {
         showMessage($lang['illegal_parameter']);
     }
     Tpl::output('class_array', $class_array);
     Tpl::showpage('store_class.edit');
 }
Esempio n. 22
0
 /**
  * Does the reverse of unique_key_exists() by triggering error if username exists
  * Validation Rule
  *
  * @param    Validate  $array   validate object
  * @param    string    $field   field name
  * @param    array     $errors  current validation errors
  * @return   array
  */
 public function rolename_available(Validate $array, $field)
 {
     //die($field);
     if ($this->unique_key_exists($field, $array[$field])) {
         $array->error($field, 'rolename_available', array($array[$field]));
     }
 }
Esempio n. 23
0
    function changePassword()
    {
        $validator = new Validate();
        $validated = $validator->validateNewPassword();
        if ($validated->fails()) {
            return \View::make('accounts.password')->withErrors($validated);
        }
        if (\Auth::check()) {
            $hashed = \Hash::make(\Input::get('password'));
            $id = \Auth::user()->user_id;
            \DB::beginTransaction();
            try {
                $statement = \User::find($id);
                $statement->password = $hashed;
                $statement->save();
            } catch (ValidationException $e) {
                DB::rollback();
                throw $e;
            }
            \DB::commit();
            \Auth::logout();
            return \Redirect::to('admin/logout')->with('message', '<div class="alert alert-dismissible alert-success alert-link">
				<button type="button" class="close" data-dismiss="alert">×</button>
				Password changed. Please log in.
				</div>');
        }
        return \Redirect::to('admin')->with('message', '<div class="alert alert-dismissible alert-success alert-link">
		<button type="button" class="close" data-dismiss="alert">×</button>
		Password changed. Please log in.
		</div>');
    }
Esempio n. 24
0
 /**
  * Validation callback to check that this user has a unique email
  * 
  * @param Validate $array the validate object to use
  * @param string   $field the field name to check
  * 
  * @return null
  */
 public function check_unique_email(Validate $array, $field)
 {
     $user = new Model_Vendo_User($array[$field]);
     // Only error if this is a new or different object
     if ($user->id and $user->id != $this->id) {
         $array->error($field, 'not_unique');
     }
 }
Esempio n. 25
0
 /**
  * 验证数据
  * @param $source
  * @param $rules
  * @return $this
  */
 public static function validate($source, $rules)
 {
     $Validate = new Validate($source);
     $Validate->addRules($rules);
     $error = $Validate->run();
     $source = $Validate->source;
     return ['error' => $error, 'source' => $source];
 }
Esempio n. 26
0
File: user.php Progetto: jonlb/JxCMS
 /**
  * Validate callback wrapper for checking password match
  * @param Validate $array
  * @param string   $field
  * @return void
  */
 public static function _check_password_matches(Validate $array, $field)
 {
     $auth = Auth::instance();
     if ($array['password'] !== $array[$field]) {
         // Re-use the error messge from the 'matches' rule in Validate
         $array->error($field, 'matches', array('param1' => 'password'));
     }
 }
Esempio n. 27
0
 /**
  * Check username for profanity.
  *
  * @param   Validate  Validate object
  * @param   string    field name
  * @return  void
  */
 public function censor(Validate $array, $field)
 {
     $censor = Censor::factory($array[$field]);
     if ($censor->is_offensive()) {
         $array->error($field, 'censor', array($array[$field]));
         return FALSE;
     }
 }
Esempio n. 28
0
 public function has_category(Validate $array, $field)
 {
     $photo = (bool) DB::select(array('COUNT("*")', 'records_found'))->from('photos')->where('user_id', '=', Auth::instance()->get_user()->id)->where('category_id', '=', $array[$field])->execute($this->_db)->get('records_found');
     if ($photo) {
         $array->error($field, 'category', array($array[$field]));
         return FALSE;
     }
 }
Esempio n. 29
0
 public function validator($data, $rules, $redirect_error = '')
 {
     $Validate = new Validate();
     $validation = $Validate->run($_REQUEST, $rules);
     if (is_array($validation)) {
         return Redirect::action($redirect_error)->with('validation', $validation);
     }
 }
Esempio n. 30
0
 function index()
 {
     if (!empty($_POST)) {
         $check = new Check();
         if (!empty($_FILES["img"]["name"])) {
             $target_dir = "uploads/";
             $target_file = $target_dir . basename($_FILES["img"]["name"]);
             $filename = $check->checkInput($_FILES['img']['name']);
             $filesize = filesize($target_file);
             move_uploaded_file($_FILES["img"]["tmp_name"], $target_file);
         } else {
             $filename = '';
             $filesize = '';
         }
         //Получаем данные методом пост
         $name = $check->checkInput($_POST['name']);
         $surname = $check->checkInput($_POST['surname']);
         $email = $check->checkInput($_POST['email']);
         $login = $check->checkInput($_POST['login']);
         $pass = $check->checkInput($_POST['pass']);
         $confirmpass = $check->checkInput($_POST['confirmpass']);
         $age = $check->checkInput($_POST['age']);
         //Создаем массив для валидации данных
         $validateArr = array('name' => $name, 'surname' => $surname, 'email' => $email, 'login' => $login, 'password' => $pass, 'confirmpass' => $confirmpass, 'age' => $age, 'filename' => $filename, 'filesize' => $filesize);
         $pdo = new Db();
         //класс с конфигурацией базы данных
         $db = $pdo->get();
         $validate = new Validate($db);
         $errors = $validate->getErrors($validateArr);
         //Выявляем ошибки через валидатор
         if (empty($errors)) {
             try {
                 //Сохраняем пользователя посредством паттерна Data Mapper
                 $user = new User();
                 $user->name = $name;
                 $user->surname = $surname;
                 $user->email = $email;
                 $user->login = $login;
                 $user->password = md5($pass);
                 $user->age = $age;
                 $user->filename = $filename;
                 $mapper = new Mapper($db);
                 $mapper->save($user);
                 $this->user = $mapper->select($user);
                 $this->out('profile.php');
             } catch (Exception $e) {
                 echo "Ошибка загрузки данных <br>" . $e->getMessage();
             }
         } else {
             foreach ($errors as $error) {
                 $this->error = $error . "<br>";
             }
             $this->out('register.php');
         }
     } else {
         $this->out('register.php');
     }
 }