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); }
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'); }
public function formAction() { $this->_view->_title = 'User : Add'; $this->_view->slbGroup = $this->_model->itemInSelectBox($this->_arrParam); if (isset($this->_arrParam['id'])) { $this->_view->_title = 'User : Edit'; $this->_arrParam['form'] = $this->_model->infoItem($this->_arrParam); if (empty($this->_arrParam['form'])) { URL::redirect('admin', 'user', 'index'); } } if (@$this->_arrParam['form']['token'] > 0) { $task = 'add'; $requirePass = true; $queryUserName = "******" . TBL_USER . "` WHERE `username` = '{$this->_arrParam['form']['username']}'"; $queryEmail = "SELECT `email` FROM `" . TBL_USER . "` WHERE `email` = '{$this->_arrParam['form']['email']}'"; if (isset($this->_arrParam['form']['id'])) { $task = 'edit'; $requirePass = false; $queryUserName .= " AND `id` <> '" . $this->_arrParam['form']['id'] . "'"; $queryEmail .= " AND `id` <> '" . $this->_arrParam['form']['id'] . "'"; } $validate = new Validate($this->_arrParam['form']); $validate->addRule('username', 'string-notExistRecord', array('database' => $this->_model, 'query' => $queryUserName, 'min' => 3, 'max' => 25))->addRule('email', 'email-notExistRecord', array('database' => $this->_model, 'query' => $queryEmail))->addRule('password', 'password', array('action' => $task), $requirePass)->addRule('ordering', 'int', array('min' => 1, 'max' => 100))->addRule('status', 'status', array('deny' => array('default')))->addRule('group_id', 'status', array('deny' => array('default'))); $validate->run(); $this->_arrParam['form'] = $validate->getResult(); if ($validate->isValid() == false) { $this->_view->errors = $validate->showErrors(); } else { $task = isset($this->_arrParam['form']['id']) ? 'edit' : 'add'; // Insert to Database $id = $this->_model->saveItem($this->_arrParam, array('task' => $task)); $type = $this->_arrParam['type']; if ($type == 'save-close') { URL::redirect('admin', 'user', 'index'); } if ($type == 'save-new') { URL::redirect('admin', 'user', 'form'); } if ($type == 'save') { URL::redirect('admin', 'user', 'form', array('id' => $id)); } } } $this->_view->arrParam = $this->_arrParam; $this->_view->render('user/form', true); }
public function formAction() { $this->_view->_title = 'Book : Add'; $this->_view->slbCategory = $this->_model->itemInSelectBox($this->_arrParam); if (!empty($_FILES)) { $this->_arrParam['form']['picture'] = $_FILES['picture']; } if (isset($this->_arrParam['id'])) { $this->_view->_title = 'Book : Edit'; $this->_arrParam['form'] = $this->_model->infoItem($this->_arrParam); if (empty($this->_arrParam['form'])) { URL::redirect('admin', 'book', 'index'); } } if (@$this->_arrParam['form']['token'] > 0) { $task = 'add'; if (isset($this->_arrParam['form']['id'])) { $task = 'edit'; } $validate = new Validate($this->_arrParam['form']); $validate->addRule('name', 'string', array('min' => 1, 'max' => 255))->addRule('picture', 'file', array('min' => 100, 'max' => 1000000, 'extension' => array('jpg', 'png')), false)->addRule('ordering', 'int', array('min' => 1, 'max' => 100))->addRule('status', 'status', array('deny' => array('default')))->addRule('special', 'status', array('deny' => array('default')))->addRule('category_id', 'status', array('deny' => array('default')))->addRule('sale_off', 'int', array('min' => 0, 'max' => 100))->addRule('price', 'int', array('min' => 1000, 'max' => 1000000)); $validate->run(); $this->_arrParam['form'] = $validate->getResult(); if ($validate->isValid() == false) { $this->_view->errors = $validate->showErrors(); } else { $task = isset($this->_arrParam['form']['id']) ? 'edit' : 'add'; // Insert to Database $id = $this->_model->saveItem($this->_arrParam, array('task' => $task)); $type = $this->_arrParam['type']; if ($type == 'save-close') { URL::redirect('admin', 'book', 'index'); } if ($type == 'save-new') { URL::redirect('admin', 'book', 'form'); } if ($type == 'save') { URL::redirect('admin', 'book', 'form', array('id' => $id)); } } } $this->_view->arrParam = $this->_arrParam; $this->_view->render('book/form', true); }
public function formAction() { $this->_view->_title = 'User Category : Add'; if (!empty($_FILES)) { $this->_arrParam['form']['picture'] = $_FILES['picture']; } if (isset($this->_arrParam['id'])) { $this->_view->_title = 'User Category : Edit'; $this->_arrParam['form'] = $this->_model->infoItem($this->_arrParam); if (empty($this->_arrParam['form'])) { URL::redirect('admin', 'category', 'index'); } } if (@$this->_arrParam['form']['token'] > 0) { /*echo '<pre>'; print_r($this->_arrParam); echo '</pre>'; die("Function die is called");*/ $validate = new Validate($this->_arrParam['form']); $validate->addRule('name', 'string', array('min' => 3, 'max' => 255))->addRule('ordering', 'int', array('min' => 1, 'max' => 100))->addRule('status', 'status', array('deny' => array('default')))->addRule('picture', 'file', array('min' => 100, 'max' => 1000000, 'extension' => array('jpg', 'png')), false); $validate->run(); $this->_arrParam['form'] = $validate->getResult(); if ($validate->isValid() == false) { $this->_view->errors = $validate->showErrors(); } else { echo $task = isset($this->_arrParam['form']['id']) ? 'edit' : 'add'; // Insert to Database $id = $this->_model->saveItem($this->_arrParam, array('task' => $task)); $type = $this->_arrParam['type']; if ($type == 'save-close') { URL::redirect('admin', 'category', 'index'); } if ($type == 'save-new') { URL::redirect('admin', 'category', 'form'); } if ($type == 'save') { URL::redirect('admin', 'category', 'form', array('id' => $id)); } } } $this->_view->arrParam = $this->_arrParam; $this->_view->render('category/form', true); }
public function login() { if (Session::get('loggedIn') == true) { $this->redirect('group', 'index'); } if (isset($_POST['submit'])) { $source = array('username' => $_POST['username']); $validate = new Validate($source); $query = "SELECT `id` FROM `user` WHERE `nickname` = '{$_POST['username']}' AND `position` = '{$_POST['password']}'"; $validate->addRule('username', 'existRecord', array('database' => $this->db, 'query' => $query)); $validate->run(); $error = $validate->getError(); if ($validate->isValid() == true) { Session::set('loggedIn', true); $this->redirect('group', 'index'); } else { $this->view->errors = $validate->showErrors(); } } $this->view->render('user/login'); }
public function indexAction() { $this->_view->_title = 'Login'; $userInfo = Session::get('user'); if (@$this->_arrParam['loginForm']['token'] > 0) { $validate = new Validate($this->_arrParam['loginForm']); $username = @$this->_arrParam['loginForm']['username']; $password = md5(@$this->_arrParam['loginForm']['password']); $query = "SELECT `id` FROM `user` WHERE `nickname` = '{$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(), 'admin_control' => $infoUser['admin_control']); Session::set('user', $arraySession); URL::redirect(URL::createLink('default', 'index', 'index')); } else { $this->_view->errors = $validate->showErrors(false); } } $this->_view->render('login/index', true); }
public function formAction() { $this->_view->_title = 'Category Manager : Add'; if (isset($this->_arrParam['id'])) { $this->_view->_title = 'Category Manager : Edit'; $this->_arrParam['form'] = $this->_model->infoItem($this->_arrParam); if (empty($this->_arrParam['form'])) { URL::redirect(URL::createLink('admin', 'category', 'index')); } } if (@$this->_arrParam['form']['token'] > 0) { $validate = new Validate($this->_arrParam['form']); $validate->addRule('name', 'string', array('min' => 3, 'max' => 255))->addRule('ordering', 'int', array('min' => 1, 'max' => 100))->addRule('status', 'status', array('deny' => array('default'))); $validate->run(); $this->_arrParam['form'] = $validate->getResult(); if ($validate->isValid() == false) { $this->_view->errors = $validate->showErrors(); } else { echo $task = isset($this->_arrParam['form']['id']) ? 'edit' : 'add'; // Insert to Database $id = $this->_model->saveItem($this->_arrParam, array('task' => $task)); $type = $this->_arrParam['type']; if ($type == 'save-close') { URL::redirect(URL::createLink('admin', 'category', 'index')); } if ($type == 'save-new') { URL::redirect(URL::createLink('admin', 'category', 'form')); } if ($type == 'save') { URL::redirect(URL::createLink('admin', 'category', 'form', array('id' => $id))); } } } $this->_view->arrParam = $this->_arrParam; $this->_view->render('category/form', true); }
<?php require_once "class/Validate.class.php"; $flagType = 'error'; $error = ''; $source = array('name' => $_POST['name'], 'email' => $_POST['email'], 'message' => $_POST['message'], 'file' => $_FILES['attach']); $validate = new Validate($source); $validate->addRule('name', 'string', array('min' => 2, 'max' => 50))->addRule('email', 'email')->addRule('message', 'string', array('min' => 5, 'max' => 500))->addRule('file', 'file', array('extension' => array('png', 'jpg'), 'min' => 50, 'max' => 9000000), false); $validate->run(); if ($validate->isValid() == false) { $error = $validate->getError(); } else { $flagType = 'success'; } $response = array('type' => $flagType, 'message' => $error); echo json_encode($response);
if ($flagRedirect == true) { header('location: error.php'); exit; } if (!empty($_POST)) { if ($_SESSION['token'] == $_POST['token']) { // refresh page unset($_SESSION['token']); header('location: ' . $linkForm); exit; } else { $_SESSION['token'] = $_POST['token']; } $source = array('username' => $_POST['username'], 'email' => $_POST['email'], 'password' => $_POST['password'], 'birthday' => $_POST['birthday'], 'status' => $_POST['status'], 'groupid' => $_POST['groupid'], 'ordering' => $_POST['ordering']); $validate = new Validate($source); $validate->addRule('username', 'string', 2, 50)->addRule('email', 'email')->addRule('password', 'password')->addRule('birthday', 'birthday')->addRule('groupid', 'status')->addRule('ordering', 'int', 1, 10)->addRule('status', 'status'); $validate->run(); $outValidate = $validate->getResult(); if (!$validate->isValid()) { $error = $validate->showErrors(); } else { if ($action == 'edit') { $where = array(array('id', $id)); $database->update($outValidate, $where); } else { if ($action == 'add') { $database->insert($outValidate); $outValidate = array(); } } $success = '<div class="success">Success</div>';