/** * 修改菜单 */ public function edit($id) { $model = D('Menu'); if (IS_POST) { if ($model->create()) { if ($model->updateMenu() !== false) { $this->success('修改成功', cookie('forward')); } else { $this->error('修改失败'); } } else { $this->error(get_errors($model->getError())); } } else { //1.根据id获取数据表中的数据 //获取所有的菜单 $this->assign('all_menu', $model->getList(array('id,name,parent_id'), array(), true)); //获取所有的权限 //取出所有的权限 $this->assign('all_permissions', D('Permission')->getList('id,name,parent_id', array(), true)); //获取当前关联的权限 $this->assign('perms', $model->getPermission($id, true)); $row = $model->find($id); $this->assign('row', $row); $this->display(); } }
/** * edit_user * * @param mixed $id the unique identifier * * @access public * @return string */ function edit_user($id) { i_am_logged(); $user = fetch_or_404('User', $id); if (is_post()) { $user->fromArray($_POST); if ($user->isValid()) { $user->save(); return redirect('/user/page/' . $user->id); } else { $errors = array(); $errors['user'] = get_errors($user); } } return render('user_edit.tpl', compact('user', 'errors')); }
public function login() { if (IS_POST) { $model = D('Member'); $flag = $model->login(); if ($flag) { $url = cookie('__forward__') ? cookie('__forward__') : U('Index/index'); $this->success('登录成功', $url); return; } else { $this->error(get_errors($model->getError())); } } else { $this->display(); } }
/** * faq_add * * @access public * @return string */ function faq_add() { $data = array(); $data['faq'] = new Faq(); if (is_post()) { $faq->fromArray($_POST); $faq->id = null; if ($faq->isValid()) { $faq->save(); return redirect('/faq/list'); } else { $data['errors'] = array(); $data['errors']['faq'] = get_errors($faq); } } return render('faq_form.tpl', $data); }
/** * page_add * * @access public * @return string */ function page_add() { $data = array(); $page = new Pages(); if (is_post()) { $page->fromArray($_POST); if ($page->isValid()) { $page->save(); return redirect('/page/list'); } else { $errors = array(); $errors['page'] = get_errors($page); print_r($errors['page']); } } $data['page'] = $page; return render('page_form.tpl', $data); }
/** * 修改文章分类 */ public function edit($id) { $model = D('ArticleCategory'); if (IS_POST) { if ($model->create()) { if ($model->save() !== false) { $this->success('修改成功', cookie('forward')); } else { $this->error('修改失败'); } } else { $this->error(get_errors($model->getError())); } } else { //1.根据id获取数据表中的数据 $row = $model->find($id); $this->assign('row', $row); $this->display(); } }
/** * 修改角色 */ public function edit($id) { $model = D('Role'); if (IS_POST) { if ($model->create()) { if ($model->saveRole() !== false) { $this->success('修改成功', cookie('forward')); } else { $this->error('修改失败'); } } else { $this->error(get_errors($model->getError())); } } else { //1.根据id获取数据表中的数据 $row = $model->find($id); $this->assign('row', $row); $this->assign('permissions', D('Permission')->getList('id,name,parent_id', array(), true)); $this->assign('perms', $model->getPermission($id, true)); $this->display(); } }
function password() { if(!isset($_SESSION['active_user'])) redirect_to(make_url("users")); $usr = instance_model('users'); $user = $usr->get_user_by_id($_SESSION['active_user']['id']); if($user == array()) throw new no_such_user_exception(); if(!isset($_POST['Submit'])) { // Display main $view = instance_view("settings_password"); $view = $view->parse_to_variable(array()); } else { $form_vals = $_POST; // Varify old password $selected_user = $usr->verify_user($user[0]['User_name'], $form_vals[0]); if($selected_user === false) new_flash('Old password is incorrect', 1); // Validate new password if(mb_strlen($form_vals[1], 'utf8') < 6) new_flash('New password too short, min 6 charicters', 1); else if(sha1($form_vals[1]) != sha1($form_vals[2])) new_flash('Passwords do not match', 1); if(count(get_errors()) == 0) { // Everything was vald, save updated password $usr->update_password( $user[0]['ID'], $form_vals[1]); redirect_to(make_url('settings', 'password')); } else { // Something was invalid, redisplay main $view = instance_view("settings_password"); $view = $view->parse_to_variable(array()); } } // Display sidebar $sb_view = instance_view("settings_sidebar"); $sb_view = $sb_view->parse_to_variable(array( 'uid' => $_SESSION['active_user']['id'], 'uname' => $_SESSION['active_user']['name'])); $this->set_template_paramiters( array('main_content' => $view, 'sidebar' => $sb_view)); }
* obligation to do so :) * * Please read the accompanying LICENSE document for the full WTFPL * licensing text. */ if (!isset($_APP)) { die("Unauthorized."); } try { $sCampaign = Campaign::CreateFromQuery("SELECT * FROM campaigns WHERE `UrlName` = :UrlName", array(":UrlName" => $router->uParameters[1]), 30, true); } catch (NotFoundException $e) { throw new RouterException("Campaign does not exist."); } if ($sCampaign->VerifyAdministratorAccess($_SESSION['user_id']) === false) { throw new RouterException("Not authorized to administrate this campaign."); } if (!empty($_POST['default_currency']) && in_array($_POST['default_currency'], array("usd", "eur", "btc"))) { $sCampaign->uDefaultCurrency = $_POST['default_currency']; } if (isset($_POST['default_amount'])) { if (preg_match("/^([0-9]*[.,][0-9]+|[0-9]+)\$/", $_POST['default_amount']) == false) { flash_error("You did not enter a valid default amount."); } else { $sCampaign->uDefaultAmount = $_POST['default_amount']; } } if (count(get_errors(false)) == 0) { $sCampaign->InsertIntoDatabase(); flash_notice("Settings successfully changed."); } redirect("/dashboard/{$sCampaign->sUrlName}");
<?php require MODELS_PATH . "user.php"; switch ($route["view"]) { case 'create': $user = new User(); $invalid_fields = $user->search($params["post"]); $errors_user = get_errors($user->validations, $params["post"]); $errors_person = get_errors($user->person->validations, $params["post"]); $invalid_password = $user->valid_password($params["post"]["password"], $params["post"]["confirm_password"]); if (!$errors_user && !$errors_person && !$invalid_fields["email"] && !$invalid_fields["username"] && !$invalid_password["confirm_password"]) { $user->set($params["post"]); save_msg_success("Se ha agregado correctamente el nuevo usuario"); redirect_to("users/new"); } else { $post = $params["post"]; $route["view"] = "new"; save_msg_warnings("Por favor, corrige los siguientes campos: <br/><br/>"); } break; }
function test_get_errors() { new_flash('Something went wrong', 1); $this->assertEquals(get_errors(), $_SESSION['flash']); }
function get_error_string() { $CI =& get_instance(); $errors = get_errors(); if (!empty($errors)) { $error_string = ''; foreach ($errors as $error) { $error_string .= '<p>' . $error . (substr($error, -1) == '.' ? '' : '.') . '</p>'; } return $error_string; } }
/** * 修改商品 */ public function edit($id) { $model = D('Goods'); if (IS_POST) { if ($model->create()) { if ($model->save() !== false) { $this->success('修改成功', cookie('forward')); } else { $this->error('修改失败'); } } else { $this->error(get_errors($model->getError())); } } else { //1.根据id获取数据表中的数据 $row = $model->relation(array('GoodsIntro', 'GoodsGallery'))->find($id); $this->assign('row', $row); $this->assign('categorys', D('GoodsCategory')->getList()); $this->assign('brands', D('Brand')->getAll()); $this->assign('suppliers', D('Supplier')->getAll()); $this->assign('articles', D('Article')->getArticles($id)); $this->display(); } }
include './functions.php'; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>TaskPaper.web</title> <link rel="stylesheet" type="text/css" href="./style.css"> <script type="text/javascript" src="./jquery.js"></script> <script type="text/javascript" src="./javascript.php"></script> </head> <body> <div id="wrapper"> <?php echo get_errors(); ?> <div id="menu"> <input type="button" id="edit_back" value="Edit"> <select id="project_select"> <option value=''>Select Project</option> <?php $projects = get_projects_list(); foreach ($projects as $project) { print "\t\t<option value=\"{$project}\">{$project}</option>\n"; } ?> </select> <!-- <div class="due_menu">Item due: <a href="#" onclick="due(1,0,'Today'); return false">today</a>, <a href="#" onclick="due(2,0,'Tomorrow'); return false">tomorrow</a>, <a href="#" onclick="due(7,1,'This Week'); return false">this week</a>.</div> --> </div> <div id="todo_list">
/** * 修改管理员 */ public function edit($id) { $model = D('Admin'); if (IS_POST) { if ($model->create()) { if ($model->saveAdmin() !== false) { $this->success('修改成功', cookie('forward')); } else { $this->error('修改失败'); } } else { $this->error(get_errors($model->getError())); } } else { //1.根据id获取数据表中的数据 $this->before_edit_view(); //获取所有的额外权限 //获取当前用户关联的角色 $row = $model->find($id); $this->assign('row', $row); $this->assign('perms', $model->getPermission($id, true)); $this->assign('roles', $model->getRole($id, true)); $this->display(); } }
<?php define('DEBUG', false); define('SERVER_NAME', 'Shivas'); define('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']); define('DB_HOST', 'localhost'); define('DB_NAME', 'shivas'); define('DB_USER', 'root'); define('DB_PASSWD', ''); define('DB_INSERT_QUERY', 'INSERT INTO accounts(name, password, salt, nickname, question, answer) VALUES(:name, :password, :salt, :nickname, :question, :answer);'); require_once "common.lib.php"; $success = false; $fields = get_fields(array('name', 'password', 'nickname', 'question', 'answer'), $_POST); $validators = array('name' => Validators::with($required)->plus($length_between, 4, 15)->build(), 'password' => Validators::with($required)->plus($min_length, 4)->build(), 'nickname' => Validators::with($required)->plus($min_length, 4)->build(), 'question' => Validators::with($required)->plus($min_length, 4)->build(), 'answer' => Validators::with($required)->plus($min_length, 4)->build()); $errors = is_method('POST') ? get_errors($validators, $fields) : array(); if (is_method('POST') && ($success = count($errors) <= 0)) { $fields['salt'] = random_string(32); $fields['password'] = shivas_encrypt($fields['password'], $fields['salt']); try { $db = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASSWD); $db->prepare(DB_INSERT_QUERY)->execute($fields); } catch (Exception $e) { $success = false; $errors['global'] = array($e->getMessage()); } } include "signup.view.php";
function register() { if(ALLOW_REGISTRATION == false) die('Registration has bean disabled on this node'); if(!isset($_POST['Submit'])) { $form_vals = make_reg_vals_array('', '', '', ''); // display register form $view = instance_view('register'); $view = $view->parse_to_variable(array( 'form_vals' => $form_vals)); $this->set_template_paramiters( array('main_content' => $view, 'sidebar' => '')); } else { // reed the form $form_vals = array( 'errs' => array(), 'name' => $_POST['name'], 'email' => $_POST['email'], 'pass' => $_POST['pass'], 'pass_v' => $_POST['pass_v']); // Instance users model $usr = instance_model('users'); $test_exists = array(); // Validate user name try { validate_username($form_vals['name']); $test_exists = $usr->get_user_by_name($form_vals['name']); if($test_exists != array()) { new_flash('User name is already tacken on this node', 1); $form_vals['name'] = ''; } } catch(exception $e) { if(strlen($form_vals['name']) < 3) { new_flash('User name too short, min 3 charicters', 1); $form_vals['name'] = ''; } else if(strlen($form_vals['name']) > 30) { new_flash('User name too long, max 30 charicters', 1); $form_vals['name'] = ''; } else if(!preg_match('/^[a-zA-Z0-9_]+$/', $form_vals['name'])) { new_flash('User names must contain only alphanumeric charicters and the underscore', 1); $form_vals['name'] = ''; } } // Validate email if(!preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+' .'(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', $form_vals['email'])) { new_flash('Email address is invalid', 1); $form_vals['email'] = ""; } // Validate passwords if(mb_strlen($form_vals['pass'], 'utf8') < 6) new_flash('Password too short, min 6 charicters', 1); else if(sha1($form_vals['pass']) != sha1($form_vals['pass_v'])) new_flash('Passwords do not match', 1); if(count(get_errors()) == 0) { // Everything was valid, save, login and redirect $usr->new_user($form_vals['name'], $form_vals['email'], $form_vals['pass']); $new_id = $usr->get_user_by_name($form_vals['name']); log_in_user($new_id[0]['User_name'], $new_id[0]['ID']); } // else re-display the register form and show errors else { $view = instance_view("register"); $view = $view->parse_to_variable(array( 'form_vals' => $form_vals)); $this->set_template_paramiters( array('main_content' => $view, 'sidebar' => '')); } } }
// Testing password if (empty($password)) { $result['password'] = '******'; } else { if (strlen($password) < 4 || strlen($password) > 20) { $result['password'] = '******'; } } return $result; } $errors = array(); $success = array(); // Check Post method isn't empty if (!empty($_POST)) { // Get errors $errors = get_errors($_POST); // Success if (empty($errors)) { $pseudo = trim($_POST['pseudo']); $password = $_POST['password']; $hashed_password = hash("sha256", $password) . SALT; // Select user with pseudo and password according to the user query $query = $pdo->prepare("SELECT * FROM 4l_admin WHERE pseudo = :pseudo AND password = :hashed_password"); /*** bind the parameters ***/ $query->bindParam(':pseudo', $pseudo); $query->bindParam(':hashed_password', $hashed_password); /*** execute the prepared statement ***/ $query->execute(); $infos = $query->fetchAll(); if (!empty($infos)) { $id_admin = $infos[0]->id;
public function edit($id) { $model = D('Brand'); //1.判断是否有提交 if (IS_POST) { //1.1检查数据是否合法 if ($model->create()) { if ($model->save()) { $this->success('修改成功', cookie('forward')); } else { $this->error(get_errors($model->getError())); } } else { $this->error('数据不合法'); } } else { //2.如果没有提交,直接展示数据 $row = $model->find($id); $this->assign('row', $row); $this->display(); } }
function add_error($error) { $CI =& get_instance(); $CI->_data['errors'] = get_errors(); $CI->_data['errors'] .= '<p>' . $error . '</p>'; $CI->session->set_flashdata('validation::errors', $CI->_data['errors']); }
function edit() { if(!(isset($_SESSION['active_user']) && $_SESSION['active_user']['type'] == 'admin')) redirect_to('/'); $this->load_outer_template('admin'); $usr = instance_model('users'); if(!isset($_POST['Submit'])) { $user = $usr->get_user_by_id($_SESSION['active_user']['id']); if($user == array()) throw new exception("User does not exist"); $form_vals = make_reg_vals_array('', $user[0]['Ppal_email'], '', ''); // display user edit form $view = instance_view('users/edit'); $view = $view->parse_to_variable(array( 'form_vals' => $form_vals)); $this->set_template_paramiters(array( 'content' => $view )); } else { // reed the form $form_vals = array( 'errs' => array(), 'ppal_email' => $_POST['ppal_email'], 'oldpass' => $_POST['oldpass'], 'pass' => $_POST['pass'], 'pass_v' => $_POST['pass_v']); // Instance users model $test_exists = array(); // Validate email try { validate_email($form_vals['ppal_email']); $test_exists = $usr->get_user_by_email($form_vals['ppal_email']); if($test_exists != array() && $test_exists[0]['ID'] != $_SESSION['active_user']['id']) { new_flash('Email address is already in use', 1); $form_vals['ppal_email'] = ''; } } catch(exception $e) { new_flash('Email address is invalid', 1); } // Validate passwords if($form_vals['oldpass'] != '') { try { $selected_user = $usr->verify_user($_SESSION['active_user']['name'], $form_vals['oldpass']); if($selected_user == false) throw new exception(); if(mb_strlen($form_vals['pass'], 'utf8') < 6) new_flash('Password too short, min 6 charicters', 1); else if(sha1($form_vals['pass']) != sha1($form_vals['pass_v'])) new_flash('Passwords do not match', 1); } catch(redirecting_to $e) { throw $e; } catch(exception $e) { new_flash('Username or password is incorrect', 1); } } if(count(get_errors()) == 0) { // Everything was valid, save, login and redirect $usr->update_user_email($_SESSION['active_user']['id'], $form_vals['ppal_email']); if($form_vals['oldpass']) { $usr->update_password($_SESSION['active_user']['id'], $form_vals['pass']); } new_flash("Settings updated", 1); } // else re-display the register form and show errors //else //{ $view = instance_view("users/edit"); $view = $view->parse_to_variable(array( 'form_vals' => $form_vals)); $this->set_template_paramiters(array( 'content' => $view )); //} } }