Esempio n. 1
0
 public static function validate($factory)
 {
     $val = Validation::forge($factory);
     $val->add_field('title', 'Title', 'required|max_length[50]');
     $val->add_field('body', 'Body', 'required');
     return $val;
 }
Esempio n. 2
0
 /**
  * Removes a field, and all its rules and its label from Validation object
  */
 public function offsetUnset($field)
 {
     unset($this->_labels[$field], $this->_rules[$field]);
     if (isset($this[$field])) {
         parent::offsetUnset($field);
     }
 }
Esempio n. 3
0
 public function validate()
 {
     $validation = Validation::forge();
     $validation->add('searchkey', '検索キーワード')->add_rule('required');
     $this->validator = $validation;
     return $this->validator;
 }
Esempio n. 4
0
 public function forge_validation()
 {
     $val = Validation::forge();
     $val->add('name', '名前')->add_rule('trim')->add_rule('required')->add_rule('max_length', 50);
     $val->add('email', 'メールアドレス')->add_rule('trim')->add_rule('required')->add_rule('max_length', 100)->add_rule('valid_email');
     $val->add('comment', 'コメント')->add_rule('required')->add_rule('max_length', 400);
     return $val;
 }
Esempio n. 5
0
 public function validate()
 {
     $validation = Validation::forge();
     $validation->add('namefull', '氏名')->add_rule('required');
     $validation->add('email', 'メール')->add_rule('required')->add_rule('required')->add_rule('valid_email');
     $validation->add('comment', '内容')->add_rule('required');
     $this->validator = $validation;
     return $this->validator;
 }
Esempio n. 6
0
 public function validate()
 {
     $validation = Validation::forge();
     $validation->add('namefull', '氏名')->add_rule('required');
     $validation->add('email', '会員メール')->add_rule('required')->add_rule('required')->add_rule('valid_email');
     $validation->add('point', 'ポイント')->add_rule('required')->add_rule('valid_string', array('numeric'));
     $this->validator = $validation;
     return $this->validator;
 }
Esempio n. 7
0
 public function get_view()
 {
     $reqObj = Input::get();
     $val = Validation::forge('news admin');
     $val->add('category', 'category id')->add_rule('valid_string', ['numeric']);
     if ($val->run(Input::get())) {
         exit;
     }
     $categoryID = isset($reqObj['category']) ? $reqObj['category'] : -1;
     $storyManager = new StoryManager();
     $respData['News'] = $storyManager->getListStory($categoryID);
     $this->format_response('modules/news/news', $respData);
 }
Esempio n. 8
0
 public function post_status()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('status', Lang::get('label.status'), 'required|valid_category_status');
     $val->add_field('category_id', Lang::get('label.category'), 'required|valid_category');
     if ($val->run()) {
         Model_Base_Category::update($val->validated('category_id'), array('status' => $val->validated('status')));
         $this->data['success'] = true;
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }
Esempio n. 9
0
 public function action_index()
 {
     $actionList = ['all', 'smb', 'faculty', 'department'];
     $val = \Fuel\Core\Validation::forge();
     $val->add('view', 'View')->add_rule('valid_string', array('alpha'));
     $type = 'all';
     if (!isset($__getData['view'])) {
         $type = 'index';
     } else {
         $type = $__getData['view'];
     }
     $call_func = 'view_' . $type;
     $this->{$call_func}($__getData);
     if (!in_array($type, $this->ACTION_LIST)) {
         return ErrorMsg::set_404();
     }
 }
Esempio n. 10
0
 public function post_update_config()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('email', Lang::get('label.email'), 'required|valid_email|max_length[255]');
     $val->add_field('telephone', Lang::get('label.telephone'), 'trim|valid_numeric|max_length[12]');
     $val->add_field('address', Lang::get('label.address'), 'trim|max_length[255]');
     $val->add_field('fb_url', Lang::get('label.fb_url'), 'required|valid_url');
     $val->add_field('shop_name', Lang::get('label.shop_name'), 'required|max_length[255]');
     if ($val->run()) {
         $props = array('email' => $val->validated('email'), 'telephone' => $val->validated('telephone'), 'address' => $val->validated('address'), 'fb_url' => $val->validated('fb_url'), 'shop_name' => $val->validated('shop_name'));
         Model_Base_Config::update($props);
         $this->data['success'] = Lang::get($this->controller . '.' . $this->action . '.success');
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }
Esempio n. 11
0
 public function post_update_password()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('password', Lang::get('label.password'), 'required|valid_password|min_length[8]|max_length[50]');
     $val->add_field('confirm_password', Lang::get('label.confirm_password'), 'match_field[password]');
     if ($val->run()) {
         $props = array('password' => Model_Service_Util::hash_password($val->validated('password')));
         if (Model_Base_User::update($this->user_id, $props)) {
             $this->data['success'] = Lang::get($this->controller . '.' . $this->action . '.success');
         } else {
             $this->data['error'] = Lang::get($this->controller . '.' . $this->action . '.error');
         }
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }
Esempio n. 12
0
 public function post_signin()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('email', Lang::get('label.email'), 'required|valid_email|max_length[255]');
     $val->add_field('password', Lang::get('label.password'), 'required|valid_password|min_length[8]|max_length[50]');
     if ($val->run()) {
         $email = $val->validated('email');
         $password = $val->validated('password');
         if (Model_Base_User::admin_login($email, $password)) {
             $this->data['success'] = true;
         } else {
             $this->data['errors']['signin'] = Lang::get($this->controller . '.' . $this->action . '.error');
         }
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }
Esempio n. 13
0
 public function get_index()
 {
     $reqObj = Input::get();
     $val = Validation::forge();
     $val->add('id', 'section code')->add_rule('valid_string', array('numeric'))->add_rule('required');
     if (!$val->run(Input::get())) {
         // Forge 404 with query error
     }
     $name = $reqObj['id'];
     $sectionID = $val->validated('id');
     $manageObj = new StoryManager();
     $listStory = $manageObj->buildSectionPageData($sectionID, 1);
     $randomStory = array_rand($listStory, 1);
     if ($randomStory !== null) {
         $retData['Data']['Highlight'] = $listStory[$randomStory];
     }
     $sectionInfo = $manageObj->getSectionInfoBaseID($this->section_code);
     $this->side_data['Data'] = array();
     $retData['Data']['MainSection'] = $sectionInfo['MainSection'];
     $retData['Data']['SubSection'][0] = $sectionInfo['MainSection'];
     $retData['Data']['SubSection'][1] = $sectionInfo['SubSection'];
     $retData['Data']['News'] = $listStory;
     $this->template->__yield__ = View::forge('section/overview', $retData);
 }
Esempio n. 14
0
 public function post_delete_group()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('group', Lang::get('label.group'), 'required|valid_group_fb');
     if ($val->run()) {
         $id = $val->validated('group');
         if (Model_Base_GroupFb::delete($id)) {
             $this->data['success'] = true;
         }
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }
Esempio n. 15
0
 public function action_colors($id = null)
 {
     $pass = Model_Pass::find($id);
     $val = \Fuel\Core\Validation::forge();
     $val->add_field('background_color', 'Background Color', 'max_length[255]');
     $val->add_field('foreground_color', 'Foreground Color', 'max_length[255]');
     $val->add_field('label_color', 'Label Color', 'max_length[255]');
     if ($val->run()) {
         $pass->background_color = \Fuel\Core\Input::post('background_color');
         $pass->foreground_color = \Fuel\Core\Input::post('foreground_color');
         $pass->label_color = \Fuel\Core\Input::post('label_color');
         if ($pass->save()) {
             Session::set_flash('success', e('Set colors of pass #' . $id));
             Response::redirect('admin/pass/view/' . $id);
         } else {
             Session::set_flash('error', e('Could not update pass #' . $id));
         }
     } else {
         if (\Fuel\Core\Input::method() == 'POST') {
             $pass->background_color = $val->validated('background_color');
             $pass->foreground_color = $val->validated('foreground_color');
             $pass->label_color = $val->validated('label_color');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('pass', $pass, false);
     }
     $this->template->title = "Pass colors";
     $this->template->set_safe('head', '<script type="text/javascript" src="' . \Fuel\Core\Uri::base() . 'assets/modcoder_excolor/jquery.modcoder.excolor.js"></script>');
     $this->template->content = View::forge('admin/pass/colors');
 }
Esempio n. 16
0
 public function post_sort_sub_photo()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('photo', Lang::get('label.photo'), 'required');
     if ($val->run()) {
         $rank = 1;
         foreach ($val->validated('photo') as $value) {
             Model_Base_Photo::update($value, array('rank' => $rank++));
         }
         $this->data['success'] = true;
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }
Esempio n. 17
0
 public function action_forgot()
 {
     \Auth\Auth::check() and \Fuel\Core\Response::redirect("user");
     $val = \Fuel\Core\Validation::forge('forgot');
     if (\Fuel\Core\Input::method() == "POST") {
         if ($val->run()) {
             try {
                 $username = \Fuel\Core\Input::post('email');
                 $user = Model_User::find('first', array('where' => array(array('username', 'LIKE', "{$username}"), 'or' => array(array('email', 'LIKE', "{$username}")))));
                 if (!$user) {
                     throw new \Auth\SimpleUserUpdateException("Invalid username or email");
                 }
                 $old_password = \Auth\Auth::reset_password($user->username);
                 $new_password = \Fuel\Core\Str::random();
                 \Auth\Auth::update_user(array('password' => $new_password, 'old_password' => $old_password), $user->username);
                 // Create an instance
                 $email = \Email\Email::forge();
                 // Set the from address
                 $email->from('*****@*****.**', 'ITNT Time Sheets');
                 // Set the to address
                 $email->to($user->email, $user->first_name . " " . $user->last_name);
                 // Set a subject
                 $email->subject('ITNT Time Sheets Password Reset');
                 // Set multiple to addresses
                 //                            $email->bcc(array(
                 //                                '*****@*****.**' => 'Gavin Murambadoro',
                 //                            ));
                 // Set a html body message
                 $email->html_body(\View::forge('includes/email/forgot', array('user' => $user, 'password' => $new_password)));
                 if ($email->send()) {
                     $this->template->set_global('login_success', "Your password has been reset and an email was sent to {$user->email}");
                 } else {
                     $this->template->set_global('login_error', "Your password was reset but we could not send you an email. Your new password is {$new_password}. Make sure that you copy this before leaving this page.");
                 }
             } catch (\SimpleUserUpdateException $exception) {
                 $this->template->set_global('login_error', "User Error: {$exception->getMessage()}");
             } catch (\EmailValidationFailedException $exception) {
                 $this->template->set_global('login_error', "Mail Validation Error: {$exception->getMessage()}");
             } catch (\EmailSendingFailedException $exception) {
                 $this->template->set_global('login_error', "Mail Error: {$exception->getMessage()}");
             } catch (Exception $exception) {
                 $this->template->set_global('login_error', "General Error: {$exception->getMessage()}");
             }
         } else {
             $this->template->set_global('login_error', $val->error());
         }
     }
     $this->template->set_global('val', $val, false);
     $this->template->title = 'Forgot Password';
     $this->template->content = View::forge('user/forgot');
 }