Example #1
0
 public function logoutAction()
 {
     $this->app->user->logout();
     $resp = new Response();
     $resp->redirect($this->app->router->path('home'));
     return $resp;
 }
Example #2
0
 public function createAction()
 {
     $resp = new Response();
     $request = $this->app->request;
     $post_id = $request->getPostParam('post_id');
     $content = $request->getPostParam('content');
     if ($post_id && $content) {
         $comment = new Comment(array('post_id' => $post_id, 'content' => $content, 'user_id' => $this->app->user->getId()));
         $comment->save();
     }
     $resp->redirectBack();
     return $resp;
 }
Example #3
0
function logout($module, $interface, $date, $start_time, $offset, $count)
{
    $response = \Core\Response::getInstance()->response();
    $session = \Core\Session::getInstance($response);
    $session->delete();
    include ST_ROOT . '/Views/login.tpl.php';
}
 public function comment($section, $newsId)
 {
     $comment = Input::get('comment');
     $user = User::get();
     Comment::Insert(array('newsId' => $newsId, 'userId' => $user->id, 'comment' => $comment));
     Response::redirect('/' . $section . '/' . $newsId);
 }
Example #5
0
 /**
  * 当request时调用
  * @param unknown $request
  * @param unknown $response
  */
 public function onRequest($request, $response)
 {
     // 		var_dump($request, $response);
     $_GET = $_POST = $_COOKIE = array();
     $resp = \Core\Response::getInstance($response);
     $resp->setResponse($response);
     if (isset($request->get)) {
         $_GET = $request->get;
     }
     if (isset($request->post)) {
         $_POST = $request->post;
     }
     if (isset($request->cookie)) {
         $_COOKIE = $request->cookie;
     }
     try {
         ob_start();
         include APPLICATION_PATH . '/Web/index.php';
         $result = ob_get_contents();
         ob_end_clean();
         $response->header("Content-Type", "text/html;charset=utf-8");
         $result = empty($result) ? 'No message' : $result;
         $response->end($result);
         unset($result);
     } catch (Exception $e) {
         var_dump($e);
     }
 }
Example #6
0
 public function Lockscreen()
 {
     global $user;
     if (isset($_POST['email']) && isset($_POST['passwd'])) {
         $result = array("status" => 0, "message" => "验证失败");
         $passwd = htmlspecialchars($_POST['passwd']);
         $result['passwd'] = $passwd;
         $user = User::getInstance();
         $user = $user->GetUserByEmail($user->email);
         $result['obj'] = $user;
         if ($user->verifyPassword($passwd)) {
             Util::setToken();
             $result['status'] = 1;
             $result['message'] = "验证成功, 将跳转到 >> 仪表盘";
         } else {
             $result['message'] = "我跟你讲, 你密码错的在试2遍就给你锁了.";
         }
         echo json_encode($result);
         exit;
     } else {
         if (!\Helper\Listener::checkLogin()) {
             \Core\Response::redirect('/Auth/login');
             exit;
         }
         include Template::load('/panel/lockscreen');
     }
     exit;
 }
Example #7
0
/**
 * 检查是否登录
 */
function check_auth()
{
    // 如果配置中管理员用户名密码为空则说明不用验证
    if (Config\Config::$adminName == '' && Config\Config::$adminPassword == '') {
        return true;
    }
    // 进入验证流程
    $response = \Core\Response::getInstance()->response();
    $session = \Core\Session::getInstance($response);
    $session->start();
    if (!isset($_SESSION['admin'])) {
        if (!isset($_POST['admin_name']) || !isset($_POST['admin_password'])) {
            include ST_ROOT . '/Views/login.tpl.php';
            return _exit();
        } else {
            $admin_name = $_POST['admin_name'];
            $admin_password = $_POST['admin_password'];
            if ($admin_name != Config\Config::$adminName || $admin_password != Config\Config::$adminPassword) {
                $msg = "用户名或者密码不正确";
                include ST_ROOT . '/Views/login.tpl.php';
                return _exit();
            }
            $_SESSION['admin'] = $admin_name;
            $_GET['fn'] = 'main';
        }
    }
    $session->save();
    return true;
}
Example #8
0
 public function createAction()
 {
     $request = $this->app->request;
     $resp = new Response();
     $errors = array();
     $title = $request->getPostParam('title');
     $content = $request->getPostParam('content');
     if (!$title) {
         $errors['title'] = 'Введите заголовок';
     }
     if (!$content) {
         $errors['content'] = 'Введите текст';
     }
     if (!$errors) {
         $post = new Post(array('user_id' => $this->app->user->getId(), 'title' => $title, 'content' => $content));
         if ($id = $post->save()) {
             $resp->redirect($this->app->router->path('post.show', array($id)));
             return $resp;
         } else {
             $errors[] = 'Не удалось добавить пост';
         }
     }
     $resp->setTplVars(array('values' => array('title' => $title, 'content' => $content)));
     $resp->setTplVars(array('errors' => $errors));
     $resp->setTemplate('new_post.html');
     return $resp;
 }
Example #9
0
 /**
  * Common method to get a project
  *
  * @access protected
  * @param  integer      $project_id    Default project id
  * @return array
  */
 protected function getProject($project_id = 0)
 {
     $project_id = $this->request->getIntegerParam('project_id', $project_id);
     $project = $this->project->getById($project_id);
     if (empty($project)) {
         $this->session->flashError(t('Project not found.'));
         $this->response->redirect($this->helper->url->to('project', 'index'));
     }
     return $project;
 }
Example #10
0
 /**
  * Common method to get a project
  *
  * @access protected
  * @param  integer      $project_id    Default project id
  * @return array
  */
 protected function getProject($project_id = 0)
 {
     $project_id = $this->request->getIntegerParam('project_id', $project_id);
     $project = $this->project->getById($project_id);
     if (!$project) {
         $this->session->flashError(t('Project not found.'));
         $this->response->redirect('?controller=project');
     }
     return $project;
 }
Example #11
0
 /**
  * Show text and redirect to another page
  * @param string $text Content
  * @param string $link Target page
  * @param int $timeout Time before redirect
  */
 public static function show($text, $link = null, $timeout = 3)
 {
     Template::setView('Misc/Redirect');
     Template::putContext('text', $text);
     Template::putContext('timeout', $timeout);
     Template::putContext('link', $link === null ? null : Response::generateURL($link));
     Filter::preRender();
     Template::render();
     Filter::afterRender();
     exit;
 }
 public function subscribe()
 {
     $user = Input::get('user');
     $password = Input::get('password');
     $name = Input::get('name');
     $email = Input::get('email');
     $address = Input::get('address');
     $gender = Input::get('gender');
     $result = User::query()->where('user', '=', $user)->first();
     if (!is_null($result)) {
         return Response::redirect('/login?error=subscribe');
     }
     User::insert(array('user' => $user, 'password' => md5($password), 'name' => $name, 'email' => $email, 'address' => $address, 'gender' => $gender));
     return Response::redirect('/login');
 }
Example #13
0
 /**
  * Display the template show task (common between different actions)
  *
  * @access protected
  * @param  array  $task               Task data
  * @param  array  $comment_form       Comment form data
  * @param  array  $description_form   Description form data
  * @param  array  $comment_edit_form  Comment edit form data
  */
 protected function showTask(array $task, array $comment_form = array(), array $description_form = array(), array $comment_edit_form = array())
 {
     if (empty($comment_form)) {
         $comment_form = array('values' => array('task_id' => $task['id'], 'user_id' => $this->acl->getUserId()), 'errors' => array());
     }
     if (empty($description_form)) {
         $description_form = array('values' => array('id' => $task['id']), 'errors' => array());
     }
     if (empty($comment_edit_form)) {
         $comment_edit_form = array('values' => array('id' => 0), 'errors' => array());
     } else {
         $hide_comment_form = true;
     }
     $this->response->html($this->template->layout('task_show', array('hide_comment_form' => isset($hide_comment_form), 'comment_edit_form' => $comment_edit_form, 'comment_form' => $comment_form, 'description_form' => $description_form, 'comments' => $this->comment->getAll($task['id']), 'task' => $task, 'columns_list' => $this->board->getColumnsList($task['project_id']), 'colors_list' => $this->task->getColors(), 'menu' => 'tasks', 'title' => $task['title'])));
 }
Example #14
0
 /**
  * Show text and redirect to another page
  * @param string $text Content
  * @param string $link Target page
  * @param int $timeout Time before redirect
  */
 public static function show($text, $link = null, $timeout = 3)
 {
     Template::setView('Misc/Redirect');
     if (is_array($text)) {
         array_unshift($text, $text[0]);
         // Set fallback string
         Template::putContext('text', call_user_func_array(array('I18N', 'parse'), $text));
     } else {
         Template::putContext('text', I18N::parse($text, $text));
     }
     Template::putContext('timeout', $timeout);
     Template::putContext('link', $link === null ? null : Response::generateURL($link));
     Filter::preRender();
     Template::render();
     Filter::afterRender();
     exit;
 }
Example #15
0
 public function __construct()
 {
     global $user;
     $user = User::getInstance();
     if (!$user->uid) {
         Response::redirect('/Auth/login');
     }
     if (LOCKSCREEN) {
         // check LOACKSCREEN define
         if (!empty(@$_COOKIE['token'])) {
             $token = Util::getToken();
             if ($token > 3600 && stristr(\Core\Request::getRequestPath(), 'lockscreen') == false) {
                 Response::redirect('/Auth/lockscreen');
             }
         } else {
             Response::redirect('/Auth/lockscreen');
         }
     }
     $user = $user->GetUserByEmail($user->email);
 }
Example #16
0
 public function initSalt()
 {
     $lockFile = ROOT_PATH . 'install.lock';
     $configFile = DATA_PATH . 'Config.php';
     // sql
     //Migrations
     //判断是否已经安装.
     if (!file_exists($configFile)) {
         copy(DATA_PATH . 'Config.simple.php', $configFile);
     }
     if (!file_exists($lockFile)) {
         Key::SetConfig("ENCRYPT_KEY", Key::CreateKey());
         Key::SetConfig("COOKIE_KEY", Key::CreateKey());
         file_put_contents($lockFile, "");
         echo "安装成功..即将跳转";
         Response::redirect("/");
     } else {
         throw new Error("程序已经安装,重置KEY将导致账户无法登陆,已禁止操作。<br/>若要强制重置,请删除程序目录下的install.lock", 555);
     }
 }
 public function delete($newsId)
 {
     $news = News::findById($newsId);
     $news->delete();
     Response::redirect('/admin/news');
 }
Example #18
0
 /**
  * Method automatically invoked after the current Action, when it not return a
  * null or boolean value. This Method is supposed to be overriden for using it.
  *
  * Note that the Action's returned value is passed to this Method as parameter.
  */
 protected function after($data)
 {
     if (is_string($data)) {
         // The data is a String; send the Response Headers and output it.
         Response::sendHeaders();
         echo $data;
     } else {
         if (is_array($data)) {
             // The data is an Array; prepare and send a JSON response.
             header('Content-Type: application/json', true);
             echo json_encode($data);
         } else {
             if (!$data instanceof View) {
                 // The data is not a View instance; no further processing required.
                 return;
             }
         }
     }
     //
     // Execute the default Template-based rendering of the given View instance.
     if (!$data instanceof Template && $this->layout !== false) {
         // The View instance is NOT a Template, but we have a Layout specified.
         Template::make($this->layout, array(), $this->template)->withContent($data)->display();
     } else {
         // The given View instance is a Template, or no Layout is specified.
         $data->display();
     }
 }
Example #19
0
 public function index()
 {
     Response::redirect('admin/home');
 }
Example #20
0
 /**
  * Show text and redirect to another page
  * @param string $text Content
  * @param string $link Target page
  * @param int $timeout Time before redirect
  */
 public static function show($text, $link = null, $timeout = 3)
 {
     $link = Response::generateURL($link);
     include Template::load('Misc/Redirect');
     exit;
 }
Example #21
0
 public function index()
 {
     Response::redirect("/Admin/user");
 }
Example #22
0
 public function help()
 {
     Response::redirect("http://www.ishadowsocks.org/");
 }
Example #23
0
 /**
  * 自定义错误处理机制
  * @param int 错误代码
  * @param string 错误信息
  * @param string 错误文件
  * @param int 错误行号
  * @return void
  */
 public static function appError($errno, $errstr, $errfile, $errline)
 {
     // 错误记录
     Log::error($error[$errno], $errstr, $errfile, $errline);
     // 服务器错误
     Response::_500();
 }