Exemple #1
0
 public static function do_login_action()
 {
     self::method('post');
     try {
         $checker = new lazy_checker(p());
         $checker->check('name', array('change_to' => 'string', 'cannot_be' => array('', '用户名不能为空')));
         $checker->check('pass', array('change_to' => 'string', 'cannot_be' => array('', '密码不能为空')));
         $admin = admin_model::get_one(array('name' => $checker->name));
         if ($admin === null) {
             $checker->failed('name', '用户不存在。');
         } else {
             if (!$admin->is_valid_pass($checker->pass)) {
                 $checker->failed('pass', '密码不正确');
             } else {
                 visitor::set_role('admin', $admin->id, p_has('remember') ? 30 * 86400 : 0, array('name' => $admin->name));
                 self::json_result(true, '', 0, url('admin-site/index'));
             }
         }
     } catch (check_failed $e) {
         self::json_result(false, $e->get_reasons());
     }
 }
<?php

// Initialize Composer autoload
require __DIR__ . "/../vendor/autoload.php";
chdir("..");
// Create user
$admin_model = new admin_model();
echo $admin_model->createAccount($_POST['user'], $_POST['password']);
$admin_model->toogleSU($_POST['user']);
 function insertFile($idObject, $isTemp, $iddiv, $year, $type, $pdf = 0, $is_nogetcontent = 0)
 {
     $date = getdate();
     if (!$type) {
         $type = -1;
     }
     $year = '2012';
     if (!$idObject) {
         $idObject = 0;
     }
     if (!$isTemp) {
         $isTemp = 0;
     }
     $model = new filedinhkem_model();
     //Lưu file đính kèm xuống thư mục tạm
     $temp_path = $model->getTempPath();
     //lấy id người đăng nhập
     $user_log = new log_model();
     $user = $user_log->getIdUserLogin();
     foreach ($user as $au) {
     }
     //lấy idmessage
     $message_model = new message_model();
     $thongtin = $message_model->getId_Thongtin();
     foreach ($thongtin as $id_thongtin) {
     }
     $id_tn = $id_thongtin['id_thongtin'] + 1;
     //lấy idfood
     $food = new admin_model();
     $max_food = $food->getMaxIdFood();
     foreach ($max_food as $food_join) {
     }
     $ID = $food_join['ID'] + 1;
     //lấy id_project
     $project = new project_model();
     $duan = $project->getMaxId();
     foreach ($duan as $file_project) {
         $id_project = $file_project['ID_PR'] + 1;
     }
     $filepath = $temp_path . DIRECTORY_SEPARATOR . $_FILES['uploadedfile']['name'];
     if (!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $filepath)) {
         return -1;
     } else {
         $file = new FileDinhKem();
         $file->_time_update = $date['year'] . '-' . $date['mon'] . '-' . $date['mday'] . ' ' . $date['hours'] . ':' . $date['minutes'] . ':' . $date['seconds'];
         $file->_nam = $date['year'];
         $file->_thang = $date['mon'];
         $dirPath = $model->getDir($file->_nam, $file->_thang);
         $file->_id_thongtin = $id_tn;
         $file->_folder = $dirPath;
         $file->_id_object = $idObject;
         $file->_ID = $ID;
         $file->_id_project = $id_project;
         $file->_user = $au['ID_U'];
         $file->_filename = $_FILES['uploadedfile']['name'];
         $file->_mime = $_FILES['uploadedfile']['type'];
         $file->_type = $type;
         $model->insertFileObject($file);
         //get attachment id
         $id = $this->getId_Dk();
         foreach ($id as $object) {
             $id_file = $object['ID_DK'];
         }
         $maso = $id_file . $file->_filename . $file->_time_update;
         //var_dump($maso);
         $maso = md5($maso);
         $model->md5_update($id_file, $maso);
         $newlocation = $dirPath . DIRECTORY_SEPARATOR . $maso;
         rename($filepath, $newlocation);
         $file->_pathFile = $newlocation;
         $file->_id_dk = $id_file;
         return $id_file;
     }
 }