setContext() public static method

public static setContext ( $context = [] )
Ejemplo n.º 1
0
 public function index()
 {
     $data['user'] = User::getCurrent();
     $data['nodes'] = NodeModel::getNodeArray();
     Template::setContext($data);
     Template::setView('admin/node');
 }
Ejemplo n.º 2
0
 public function index()
 {
     $data['user'] = User::getCurrent();
     $data['cronList'] = CronModel::getCronArray();
     Template::setContext($data);
     Template::setView('admin/cron');
 }
Ejemplo n.º 3
0
 public function afterRoute(&$className, &$method)
 {
     $user = User::getCurrent();
     $reflection = new ReflectionMethod($className, $method);
     $docComment = $reflection->getDocComment();
     // $this->isJson = $this->isJSON($docComment);
     if (strpos($docComment, '@Authorization') !== false && !$user) {
         $this->black = true;
     }
     $reflection = new ReflectionObject(new $className());
     $docCommentC = $reflection->getDocComment();
     if (strpos($docCommentC, '@Authorization') !== false && !$user) {
         $this->black = true;
     }
     if (strpos($docComment, '@Admin') !== false || strpos($docCommentC, '@Admin') !== false) {
         if ($user && !$user->isAdmin()) {
             $this->data['message'] = '你不是管理员,无法访问此页面';
             $this->black = true;
         }
     }
     if ($this->black) {
         if ($this->isJson) {
             Template::setContext($this->data);
             Filter::preRender();
         } else {
             Message::show($this->data['message'], 'auth/login', 3);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  *    Invite list
  *    2015.11.11 start
  */
 public function invite()
 {
     $data['user'] = MUser::getUserByUserId(MUser::getCurrent()->uid);
     $data['inviteList'] = Invite::getInvitesByUid($data['user']->uid, "0");
     Template::setContext($data);
     Template::setView("panel/invite");
 }
Ejemplo n.º 5
0
 /**
  * 详细参数 页面
  */
 public function system()
 {
     $data['user'] = User::getCurrent();
     $data['options'] = Option::getOptions();
     Template::setContext($data);
     Template::setView("admin/system");
 }
Ejemplo n.º 6
0
 public function index()
 {
     $data['selectMail'] = Option::get('MAIL_AVAILABLE');
     $data['user'] = User::getCurrent();
     Template::setContext($data);
     Template::setView('admin/mailer');
 }
Ejemplo n.º 7
0
 public function index()
 {
     $data['user'] = User::getCurrent();
     $data['lists'] = MessageModel::getPushMessage(-1);
     Template::setContext($data);
     Template::setView('admin/message');
 }
Ejemplo n.º 8
0
 public function Index()
 {
     $data['user'] = User::getCurrent();
     $data['nodes'] = MNode::getNodeArray(0);
     $data['nodeVip'] = MNode::getNodeArray(1);
     Template::setContext($data);
     Template::setView("panel/node");
 }
Ejemplo n.º 9
0
 public function inviteOldList()
 {
     $data['user'] = User::getCurrent();
     $data['inviteList'] = InviteModel::getInviteArray(1);
     $data['planList'] = json_decode(Option::get('custom_plan_name'), true);
     array_splice($data['planList'], -1, 1);
     Template::setContext($data);
     Template::setView('admin/invite');
 }
Ejemplo n.º 10
0
 public function index()
 {
     $data['user'] = User::getCurrent();
     $data['flow_num10'] = Stats::dataUsage(0);
     $data['flow_num30'] = Stats::dataUsage(1);
     $data['flow_num100'] = Stats::dataUsage(2);
     $data['flow_max'] = Stats::dataUsage(3);
     $data['userCount'] = Stats::countUser();
     $data['money'] = Stats::countMoney();
     Template::setContext($data);
     Template::setView('admin/index');
 }
Ejemplo n.º 11
0
 /**
  * @JSON
  * @Authorization
  */
 public function getList()
 {
     $port = $_GET['port'];
     $email = $_GET['email'];
     $where = ' WHERE 1=1 ';
     if ($port) {
         $where .= " AND port={$port} ";
     }
     if ($email) {
         $where .= " AND email like '%{$email}%' ";
     }
     $pageData = new PageData('member', " {$where} ORDER BY uid", ['uid', 'port', 'email', 'nickname', 'plan', 'flow_up', 'flow_down', 'transfer', 'expireTime']);
     $pageData->execute();
     Template::setContext($pageData->getContext());
 }
Ejemplo n.º 12
0
 private function findController($requestPath)
 {
     $route = array();
     $parameter = array();
     $context = null;
     $key = strtolower($requestPath);
     if ($this->StaticRoute[$key]) {
         $route = $this->StaticRoute[$key];
     } else {
         foreach ($this->DynamicRoute as $router) {
             if (!preg_match($router['regexp'], $requestPath, $matches)) {
                 continue;
             }
             // Remove the request string
             array_shift($matches);
             $route = $router['callback'];
             $parameter = $matches;
             break;
         }
     }
     if (!$route) {
         if ($this->FallbackRouter) {
             $route = $this->FallbackRouter;
         } else {
             throw new Error(I18N::parse('Error.Messages.PageNotExists', 'The request URL is not exists'), 404);
         }
     }
     list($className, $method) = $route;
     Filter::afterRoute($className, $method);
     $controller = new $className();
     if ($parameter) {
         $context = call_user_func_array(array($controller, $method), $parameter);
     } else {
         $context = $controller->{$method}();
     }
     if ($context) {
         Template::setContext($context);
     }
     Filter::preRender();
     Template::render();
     Filter::afterRender();
 }
Ejemplo n.º 13
0
 /**
  * Login
  *
  * @JSON
  */
 public function login()
 {
     /**
      * 1. 判断用户是否已经登录,
      *      若已经登录,则直接跳转到控制面板(仪表盘)中.
      * 2. 加载登录页面模板,进入登录页面.
      */
     $user = User::getCurrent();
     if ($user->uid) {
         header("Location:/member");
     } else {
         if (isset($_REQUEST['email']) && isset($_REQUEST['passwd'])) {
             $result = array('error' => 1, 'message' => '账户不存在啊喂!');
             $email = htmlspecialchars(trim($_REQUEST['email']));
             $passwd = htmlspecialchars(trim($_REQUEST['passwd']));
             $remember_me = htmlspecialchars(trim($_REQUEST['remember_me']));
             $user = User::getUserByEmail($email);
             if ($user) {
                 if ($user->verifyPassword($passwd)) {
                     $result['error'] = 0;
                     $result['message'] = '登录成功,即将跳转到 >仪表盘';
                     $remember_me == 'week' ? $ext = 3600 * 24 * 7 : ($ext = 3600);
                     $expire = time() + $ext;
                     $token = md5($user->uid . ":" . $user->email . ":" . $user->passwd . ":" . $expire . ":" . COOKIE_KEY);
                     setcookie("uid", base64_encode(Encrypt::encode($user->uid, ENCRYPT_KEY)), $expire, "/");
                     setcookie("expire", base64_encode(Encrypt::encode($expire, ENCRYPT_KEY)), $expire, "/");
                     setcookie("token", base64_encode(Encrypt::encode($token, ENCRYPT_KEY)), $expire, "/");
                     $_SESSION['currentUser'] = $user;
                     Logger::getInstance()->info('user [' . $user->email . '] Login success');
                 } else {
                     $result['message'] = "账户名或密码错误, 请检查后再试!";
                     Logger::getInstance()->info('user [' . $user->email . '] Login failed! wrong password');
                 }
             }
             return $result;
         } else {
             $data['globalMessage'] = MessageModel::getGlobalMessage();
             Template::setContext($data);
             Template::setView('panel/login');
         }
     }
 }