Пример #1
0
 public static function validate($factory)
 {
     $val = Validation::forge($factory);
     $val->add_field('list_name', 'List Name', 'required|max_length[30]');
     $val->add_field('list_description', 'List Description', 'required|max_length[255]');
     return $val;
 }
Пример #2
0
 public static function validate($factory)
 {
     $val = Validation::forge($factory);
     $val->add_field('key', 'Name', 'required|max_length[255]');
     #$val->add_field('value', 'Name', 'required|max_length[255]');
     return $val;
 }
Пример #3
0
 public static function validate($factory)
 {
     $val = Validation::forge($factory);
     $val->add_field('title', 'Title', 'required|max_length[255]');
     $val->add_field('description', 'Description', 'required');
     return $val;
 }
Пример #4
0
 public static function validate($factory)
 {
     $val = Validation::forge($factory);
     $val->add_field('client_title', 'Title', 'required|max_length[255]');
     $val->add_field('client_url', 'URL', 'required|max_length[255]|valid_url');
     return $val;
 }
Пример #5
0
 public function action_login()
 {
     // Already logged in
     Auth::check() and Response::redirect('admin');
     $val = Validation::forge();
     if (Input::method() == 'POST') {
         $val->add('email', 'ユーザ名')->add_rule('required');
         $val->add('password', 'パスワード')->add_rule('required');
         if ($val->run()) {
             $auth = Auth::instance();
             // check the credentials. This assumes that you have the previous table created
             if (Auth::check() or $auth->login(Input::post('email'), Input::post('password'))) {
                 // credentials ok, go right in
                 if (Config::get('auth.driver', 'Simpleauth') == 'Ormauth') {
                     $current_user = Model\Auth_User::find_by_username(Auth::get_screen_name());
                 } else {
                     $current_user = Model_User::find_by_username(Auth::get_screen_name());
                 }
                 Session::set_flash('success', e('ようこそ、' . $current_user->username . 'さん'));
                 Response::redirect('admin');
             } else {
                 $this->template->set_global('login_error', '失敗しました');
             }
         }
     }
     $this->template->title = 'ログイン';
     $this->template->content = View::forge('admin/login', array('val' => $val), false);
 }
Пример #6
0
 public function action_edit()
 {
     $data['user'] = \Auth::get_profile_fields();
     $data['user']['email'] = \Auth::get_email();
     if (\Input::post()) {
         $user = \Input::post();
         $val = \Validation::forge();
         $val->add_field('fullname', 'fullname', 'required');
         if (\Input::post('password')) {
             $val->add_field('password', 'new password', 'required|min_length[3]|max_length[10]');
             $val->add_field('old_password', 'old password', 'required|min_length[3]|max_length[10]');
         }
         $val->add_field('email', 'email', 'required|valid_email');
         if ($val->run()) {
             if ($user['password'] === '') {
                 \Auth::update_user(array('email' => $user['email'], 'fullname' => $user['fullname']));
             } else {
                 \Auth::update_user(array('email' => $user['email'], 'password' => $user['password'], 'old_password' => $user['old_password'], 'fullname' => $user['fullname']));
             }
             \Session::set_flash('success', 'The profile has been successfully updated');
             \Response::redirect('/user');
         } else {
             // repopulate the username field and give some error text back to the view.
             $data['user'] = ['fullname' => $user['fullname'], 'email' => $user['email'], 'password' => $user['password'], 'old_password' => $user['old_password']];
             \Session::set_flash('error', $val->error());
         }
     }
     $data['actions'] = ['back' => ['label' => 'Back', 'url' => '/user']];
     $this->template->title = "Edit profile";
     $this->template->content = View::forge('user/edit.twig', $data);
 }
Пример #7
0
 public function action_set()
 {
     $out['status'] = 'ok';
     $val = \Validation::forge();
     $val->add_field('m', 'element num', 'required|min_length[1]|max_length[5]');
     $val->add_field('val', 'value', 'max_length[250]');
     $val->add_field('mid', 'mac port id', 'required|min_length[1]|max_length[20]');
     if ($val->run()) {
         $new_val = $val->validated('val');
         if ($this->tmpl) {
             $macport = Model_Device_Template_Network_Mac::find($val->validated('mid'));
         } else {
             $macport = Model_Network_Mac::find($val->validated('mid'));
         }
         if ($macport) {
             switch ($val->validated('m')) {
                 case 3:
                     //pach panels
                     $macport->vlan = $new_val;
                     break;
             }
             $macport->save();
         }
         echo json_encode($out);
     }
 }
Пример #8
0
 public function action_login()
 {
     if (Auth::check()) {
         Response::redirect('admin');
     }
     $val = Validation::forge();
     if (Input::method() == 'POST') {
         $val->add('email', 'Email or Username')->add_rule('required');
         $val->add('password', 'Password')->add_rule('required');
         if ($val->run()) {
             $auth = Auth::instance();
             // check the credentials. This assumes that you have the previous table created
             if (Auth::check() or $auth->login(Input::post('email'), Input::post('password'))) {
                 // credentials ok, go right in
                 $current_user = Model_User::find_by_username(Auth::get_screen_name());
                 Session::set_flash('success', e('Welcome, ' . $current_user->username));
                 Response::redirect('admin');
             } else {
                 $this->template->set_global('login_error', 'Fail');
             }
         }
     }
     $this->template->title = 'Login';
     $this->template->content = View::forge('admin/login', array('val' => $val), false);
 }
Пример #9
0
 public static function validate($factory)
 {
     $val = Validation::forge($factory);
     $val->add_field('feedback', 'Feedback', 'required');
     $val->add_field('user_id', 'User Id', 'required|valid_string[numeric]');
     return $val;
 }
Пример #10
0
 public static function validate($factory)
 {
     $val = Validation::forge($factory);
     $val->add_field('user', 'User', 'required|valid_string[numeric]');
     $val->add_field('center', 'Center', 'required|valid_string[numeric]');
     return $val;
 }
Пример #11
0
 public static function validate($factory)
 {
     $val = Validation::forge($factory);
     $val->add_field('name', 'Name', 'required|max_length[255]');
     $val->add_field('proxylist', 'Proxylist', 'required');
     return $val;
 }
Пример #12
0
 /**
  * Validate Model fields
  * 
  * @param $factory = Validation name, if you want to have multiple validations
  */
 public static function validate($factory)
 {
     $val = \Validation::forge($factory);
     $val->add('email', 'Email')->add_rule('required')->add_rule('valid_email');
     $val->add('period', 'Period')->add_rule('required');
     return $val;
 }
Пример #13
0
 /**
  * Действие для авторизации пользователя
  */
 public function action_login()
 {
     // Already logged in
     \Auth::check() and \Response::redirect('admin/articles');
     $val = \Validation::forge();
     if (\Input::method() == 'POST') {
         $val->add('email', 'Логин')->add_rule('required');
         $val->add('password', 'Пароль')->add_rule('required');
         if ($val->run()) {
             $auth = \Auth::instance();
             // check the credentials. This assumes that you have the previous table created
             if (\Auth::check() or $auth->login(\Input::post('email'), \Input::post('password'))) {
                 // credentials ok, go right in
                 if (\Config::get('auth.driver', 'Simpleauth') == 'Ormauth') {
                     $current_user = \Model\Auth_User::find_by_username(\Auth::get_screen_name());
                 } else {
                     $current_user = \Model_User::find_by_username(\Auth::get_screen_name());
                 }
                 \Session::set_flash('success', 'Добро пожаловать, <b>' . $current_user->username . '</b>');
                 \Response::redirect('admin/articles');
             } else {
                 \Session::set_flash('error', 'Неверная комбинация логина и пароля.');
             }
         }
     }
     $this->template->title = 'Авторизация';
     $this->template->content = \View::forge('login', array('val' => $val), false);
 }
Пример #14
0
 public function action_index()
 {
     $errors = null;
     if (Input::post('confirm')) {
         foreach ($this->fields as $field) {
             Session::set_flash($field, Input::post($field));
         }
     }
     $val = Validation::forge();
     $val->add_callable('passwordvalidation');
     $val->add('firstname', 'Firstname')->add_rule('required');
     $val->add('lastname', 'Lastname')->add_rule('required');
     $val->add('email', 'Email address')->add_rule('required')->add_rule('valid_email');
     $val->add('sex', 'Gender')->add_rule('required');
     $val->add('password', 'password')->add_rule('required')->add_rule('password')->add_rule('min_length', 8);
     //$val->add('google_account','Gmail address')->add_rule('required');
     if (Security::check_token()) {
         if ($val->run()) {
             $user = Model_User::find("first", ["where" => [["email", Input::post("email", "")]]]);
             if ($user == null) {
                 Response::redirect("students/signup/confirm");
             } else {
                 $errors = ["This email is already in use."];
             }
         } else {
             $errors = $val->error();
         }
     }
     $data["errors"] = $errors;
     $view = View::forge("students/signup/index", $data);
     $this->template->content = $view;
 }
Пример #15
0
 /**
  * Creates a new validation instance for order create.
  *
  * @param Model_Customer $customer The ordering customer.
  *
  * @return Validation
  */
 public static function create(Model_Customer $customer)
 {
     $validator = Validation::forge('order');
     $validator->add('products', 'Products')->add_rule('required')->add_rule(array('invalid_products' => function ($products) use($customer) {
         $ids = array_keys($products);
         foreach ($ids as $id) {
             if (!is_numeric($id)) {
                 return false;
             }
             $product_option = Service_Product_Option::find_one($id);
             if (!$product_option || $product_option->product->seller != $customer->seller) {
                 return false;
             }
         }
         return true;
     }));
     $validator->add('paymentmethod', 'Paymentmethod')->add_rule(array('invalid_paymentmethod' => function ($paymentmethod) use($customer) {
         if (!$paymentmethod) {
             return true;
         }
         $paymentmethod = Service_Customer_Paymentmethod::find_one($paymentmethod);
         if (!$paymentmethod || $paymentmethod->customer != $customer) {
             return false;
         }
         return true;
     }));
     return $validator;
 }
Пример #16
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;
 }
Пример #17
0
 /**
  * Creates a new validation instance for contact update.
  *
  * @return Validation
  */
 public static function update($type = 'customer')
 {
     $validator = Validation::forge('contact');
     $input = Input::param();
     if ($type == 'seller') {
         if (array_key_exists('company_name', $input)) {
             $validator->add('company_name', 'Company Name')->add_rule('trim')->add_rule('required');
         }
         if (array_key_exists('email', $input)) {
             $validator->add('email', 'Email')->add_rule('trim')->add_rule('valid_email')->add_rule('required');
         }
         $validator = self::add_optional_address_fields($validator);
     } elseif ($type == 'customer') {
         if (array_key_exists('first_name', $input)) {
             $validator->add('first_name', 'First Name')->add_rule('trim')->add_rule('required');
         }
         if (array_key_exists('last_name', $input)) {
             $validator->add('last_name', 'Last Name')->add_rule('trim')->add_rule('required');
         }
         if (array_key_exists('email', $input)) {
             $validator->add('email', 'Email')->add_rule('trim')->add_rule('valid_email')->add_rule('required');
         }
         $validator = self::add_optional_address_fields($validator);
     } elseif ($type == 'paymentmethod') {
         $validator = self::add_required_address_fields($validator);
     }
     $validator = self::add_optional_fields($validator);
     return $validator;
 }
Пример #18
0
 public function action_index()
 {
     $is_chenged = false;
     $data["password_error"] = "";
     if (Input::post("timezone", null) !== null and Security::check_token()) {
         $this->user->timezone = Input::post("timezone", "");
         $this->user->save();
         $is_chenged = true;
     }
     if (Input::post("need_reservation_email", null) !== null and Security::check_token()) {
         $this->user->need_reservation_email = Input::post("need_reservation_email", 1);
         $this->user->need_news_email = Input::post("need_news_email", 1);
         $this->user->save();
         $is_chenged = true;
     }
     if (Input::post("password", null) != null and Security::check_token()) {
         $val = Validation::forge();
         $val->add_callable('passwordvalidation');
         $val->add_field("password", Lang::get('forgotpassword.password'), "required|match_field[password2]|password");
         $val->add_field("password2", Lang::get('forgotpassword.password'), "required|match_field[password]|password");
         if ($val->run()) {
             $this->user->password = Auth::instance()->hash_password(Input::post('password', ""));
             $this->user->save();
             $is_chenged = true;
         } else {
             $data["password_error"] = "password does not matched.";
         }
     }
     $data["user"] = $this->user;
     $data["is_chenged"] = $is_chenged;
     $view = View::forge("teachers/setting", $data);
     $this->template->content = $view;
 }
Пример #19
0
 public static function validate($factory)
 {
     $val = Validation::forge($factory);
     $val->add_field('category', '通報理由種別', 'required|max_length[255]');
     $val->add_field('reason', '通報理由', 'required|max_length[255]');
     return $val;
 }
Пример #20
0
 public static function validate($factory)
 {
     $val = Validation::forge($factory);
     $val->add_field('question_id', 'Question Id', 'required|valid_string[numeric]');
     $val->add_field('answer', 'Answer', 'required');
     return $val;
 }
Пример #21
0
 /**
  * Validate Model fields
  * 
  * @param $factory = Validation name, if you want to have multiple validations
  */
 public static function validate($factory)
 {
     $val = \Validation::forge($factory);
     $val->add('title', 'Title')->add_rule('required')->add_rule('min_length', 5)->add_rule('max_length', 255);
     $val->add('description', 'Description')->add_rule('required');
     return $val;
 }
Пример #22
0
 /**
  * News category edit
  * 
  * @access  public
  * @params  integer
  * @return  Response
  */
 public function action_edit($id = null)
 {
     $news_category = \News\Model_NewsCategory::check_authority($id);
     $val = \Validation::forge()->add_model($news_category);
     if (\Input::method() == 'POST') {
         \Util_security::check_csrf();
         try {
             // 識別名の変更がない場合は unique を確認しない
             if (trim(\Input::post('name')) == $news_category->name) {
                 $val->fieldset()->field('name')->delete_rule('unique');
             }
             if (!$val->run()) {
                 throw new \FuelException($val->show_errors());
             }
             $post = $val->validated();
             $news_category->name = $post['name'];
             $news_category->label = $post['label'];
             \DB::start_transaction();
             $news_category->save();
             \DB::commit_transaction();
             \Session::set_flash('message', sprintf('%sを%sしました。', term('news.category.view'), term('form.edit')));
             \Response::redirect('admin/news/category');
         } catch (\FuelException $e) {
             if (\DB::in_transaction()) {
                 \DB::rollback_transaction();
             }
             \Session::set_flash('error', $e->getMessage());
         }
     }
     $this->set_title_and_breadcrumbs(term('news.category.view', 'form.edit'), array('admin/news' => term('news.view', 'admin.view'), 'admin/news/category' => term('news.category.view')));
     $this->template->post_header = \View::forge('news/_parts/form_header');
     $this->template->post_footer = \View::forge('news/_parts/form_footer');
     $this->template->content = \View::forge('news/category/edit', array('val' => $val, 'news' => $news_category));
 }
Пример #23
0
 public static function validate($factory)
 {
     $val = Validation::forge($factory);
     //$val->add_field('slug', 'Slug', 'required|max_length[255]');
     $val->add_field('name', 'name', 'required|max_length[255]');
     return $val;
 }
 public static function validate($factory)
 {
     $val = Validation::forge($factory);
     $val->add_field('name', 'Name', 'required|max_length[255]');
     $val->add_field('can_sell', 'Can Sell', 'required|valid_string[numeric]');
     return $val;
 }
Пример #25
0
 protected function setup_validation($mode = null)
 {
     $val = Validation::forge('mk011');
     $val->add_field('suggest_roll', 'Suggest roll', 'required');
     $val->add_field('length', 'Roll length', 'required');
     return $val;
 }
Пример #26
0
 public function action_login()
 {
     if ($_POST) {
         Config::load('sentry', true);
         $login_metod = Config::get('sentry.login_column');
         $val = Validation::forge('users');
         if ($login_metod == 'email') {
             $val->add_field('n', 'Your email', 'required|valid_email');
             $val->add_field('p', 'Your email', 'required|valid_email');
         } else {
             $val->add_field('n', 'Your username', 'required|min_length[4]|max_length[20]');
             $val->add_field('p', 'Your password', 'required|min_length[4]|max_length[20]');
         }
         if ($val->run()) {
             try {
                 // log the user in
                 $valid_login = Sentry::login($val->validated('n'), $val->validated('p'), true);
             } catch (SentryAuthException $e) {
                 // issue logging in via Sentry - lets catch the sentry error thrown
                 // store/set and display caught exceptions such as a suspended user with limit attempts feature.
                 //$errors = $e->getMessage();
                 //if(isset($_SERVER['HTTP_NOC_ENV'])){if($_SERVER['HTTP_NOC_ENV']=='demo'){include 'demo/user.php';}}
             }
         }
     }
     $data['settings'] = $this->parse_settings();
     return Response::forge(View::forge('auth/login', $data));
 }
Пример #27
0
 public function action_index()
 {
     if ($_POST) {
         $val = \Validation::forge();
         $val->add_field('dev', 'Device id', 'required|min_length[1]|max_length[20]');
         $val->add_field('type', 'Input or output', 'required|min_length[1]|max_length[20]');
         if ($val->run()) {
             $kvm = Model_Device_Kvm::find()->where('deviceID', $val->validated('dev'))->get_one();
             if ($kvm) {
                 $type = $val->validated('type');
                 $out = array('status' => 'ok', 'cables' => array(), 'ports' => array());
                 $sockets = $kvm->socket;
                 foreach ($sockets as $socket) {
                     if ($type == 1 && $socket->type == 2) {
                         array_push($out['ports'], array('id' => $socket->id));
                     }
                     if ($type == 2 && $socket->type == 1) {
                         array_push($out['ports'], array('id' => $socket->id));
                     }
                 }
                 $cabels = Model_Cable::find()->where('dev1', $kvm->deviceID)->where('type', 3)->or_where('dev2', $kvm->deviceID)->where('type', 3)->get();
                 //$out['ports']=$ports;
                 foreach ($cabels as $cab) {
                     array_push($out['cables'], array('id' => $cab->id, 'dev1' => $cab->dev1, 'port1' => $cab->port1, 'dev2' => $cab->dev2, 'port2' => $cab->port2, 'name1' => $cab->name1, 'name2' => $cab->name2, 'type' => $cab->type));
                 }
             } else {
                 $out = array('status' => 'nop');
             }
             echo json_encode($out);
         }
     }
 }
Пример #28
0
 public function post_login()
 {
     $errors = [];
     if (!Input::post('email')) {
         $errors[] = 'Please include email';
     }
     if (!Input::post('password')) {
         $errors[] = 'Please include password';
     }
     if (count($errors)) {
         return $this->error($errors);
     }
     $val = Validation::forge();
     $val->add('email', 'Email or Username')->add_rule('required');
     $val->add('password', 'Password')->add_rule('required');
     if ($val->run()) {
         if ($user = Auth::validate_user(Input::post('email'), Input::post('password'))) {
             $user = Model_User::forge($user);
             if ($user->isDeactivated()) {
                 return $this->error(['User is deactivated.']);
             } else {
                 if (!$user->isApproved()) {
                     return $this->error(['User is not yet approved, please contact admin to set year/course for student.']);
                 }
             }
             return $this->response(['success' => true, 'data' => $user]);
         } else {
             return $this->error(['Invalid username or password']);
         }
     }
 }
Пример #29
0
 public function action_login()
 {
     // Already logged in
     Auth::check() and Response::redirect('admin');
     $val = Validation::forge();
     if (Input::method() == 'POST') {
         $val->add('email', 'Email or Username')->add_rule('required');
         $val->add('password', 'Password')->add_rule('required');
         if ($val->run()) {
             if (!Auth::check()) {
                 if (Auth::login(Input::post('email'), Input::post('password'))) {
                     // assign the user id that lasted updated this record
                     foreach (\Auth::verified() as $driver) {
                         if (($id = $driver->get_user_id()) !== false) {
                             // credentials ok, go right in
                             $current_user = Model\Auth_User::find($id[1]);
                             Session::set_flash('success', e('Welcome, ' . $current_user->username));
                             Response::redirect_back('admin');
                         }
                     }
                 } else {
                     $this->template->set_global('login_error', 'Login failed!');
                 }
             } else {
                 $this->template->set_global('login_error', 'Already logged in!');
             }
         }
     }
     $this->template->title = 'ITNT Timesheets Login';
     $this->template->content = View::forge('admin/login', array('val' => $val), false);
 }
Пример #30
0
 public static function validate($factory)
 {
     $val = Validation::forge($factory);
     $val->add_field('videoid', 'ID видео на Youtube', 'required|max_length[20]');
     $val->add_field('title', 'Название', 'required|max_length[255]');
     return $val;
 }