public static function run() { if (!isset($_SERVER['REDIRECT_URL'])) { throw new Exception(); } $_SERVER['REDIRECT_URL'] = substr($_SERVER['REDIRECT_URL'], strlen(config::prefix())); $path = explode('/', $_SERVER['REDIRECT_URL']); //array_shift($path); if ($path && preg_match('/^[0-9a-z]+$/i', $path[0])) { req::$controller = array_shift($path); if ($path && preg_match('/^[0-9a-z]+$/i', $path[0])) { req::$function = array_shift($path); } } unset($path); session::get_instance()->start(); if (uuid::check(req::$controller)) { $obj = state::load(req::$controller); if (!$obj instanceof ctrl) { throw new Exception(); } call_user_func(array($obj, req::$function)); } else { $obj = eval('return new ' . req::$controller . '_ctrl();'); if (!$obj instanceof ctrl) { throw new Exception(); } util::redirect($obj, req::$function, $_GET); } }
public function doSignIn() { $prompt = null; $email = null; $password = null; if ($_POST) { $email = util::request("email", "P"); $password = util::request("password", "P"); if (empty($email)) { $prompt = "邮箱不能为空"; } else { if (empty($password)) { $prompt = "密码不能为空"; } else { $isOk = true; //$this->load("user")->checkUser(); if ($isOk) { util::redirect("http://cgi.daotianhudong.com/?c=admin&a=index"); } else { $prompt = "用户名或密码错误"; } } } } $template = resource::getView('admin'); $template->assign("prompt", $prompt); $template->assign("email", $email); $template->assign("password", $password); $template->display('signin.tpl'); }
public function post() { try { $this->name->post(); $this->pass->post(); if ($this->name->value() == 'martin' && $this->pass->value() == 'test') { session_regenerate_id(); $_SESSION['id'] = 1; util::redirect(); } else { sleep(1); $this->message = '<p>Please check your username and password and try again.</p>'; util::redirect($this, 'in'); } } catch (Exception $e) { $this->message = $e->getMessage(); util::redirect($this, 'in'); } }
/** * 授权 * @return [type] [description] */ public function doAuthorize() { $client_id = util::request("client_id", "G"); $state = util::request("state", "G"); $response_type = util::request("response_type", "G"); $request = OAuth2\Request::createFromGlobals(); $response = new OAuth2\Response(); if (!$this->server->validateAuthorizeRequest($request, $response)) { $response->send(); die; } if (!empty($_POST)) { $authorized = $_POST['authorized'] == 'yes'; $this->server->handleAuthorizeRequest($request, $response, $authorized, "77777"); if ($authorized) { $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=') + 5, 40); //exit("SUCCESS! Authorization Code: $code"); $clientInfo = $this->storage->getClientDetails($client_id); $redirect_uri = urldecode($clientInfo['redirect_uri']); //$url = $redirect_uri . "&code=" . $code . "&state=" . $state; $redirect_uri = util::add_url_param($redirect_uri, "code", $code); $redirect_uri = util::add_url_param($redirect_uri, "state", $state); util::redirect($redirect_uri); } //$response->send(); } resource::getView('admin')->display("oauth_authorize.tpl"); }
protected function save() { $db = my_db::open(); $db->set($this->id, 'acc', array('acc_id' => $this->acc_id->value(), 'name' => $this->name->value(), 'total' => $this->total)); util::redirect('acc', 'load', array('id' => $this->id)); }
public function post() { $this->message = ''; $this->name->post(); $this->date->post(); $this->total = 0; foreach ($this->entry as $entry) { $entry['acc_id']->post(); $entry['amount']->post(); $this->total += (double) $entry['amount']->value(); } switch (key($_POST['action'])) { case 'set': break; case 'commit': // validate if (abs($this->total) < 0.01) { if (count($this->entry) > 1) { $ok = true; foreach ($this->entry as $entry) { if (abs($entry['amount']->value()) < 0.01) { $ok = false; } } if ($ok) { $this->db = my_db::open(); $this->db->query('begin'); $this->id = $this->db->set($this->id, 'trn', array('name' => $this->name->value(), 'dte' => $this->date->value())); $ids = array(); foreach ($this->entry as $entry) { if ($entry['id']) { $ids[] = $entry['id']; } } if ($ids) { $this->db->query('delete from ent where trn_id=? and id not in (' . join(',', $ids) . ')', $this->id); } foreach ($this->entry as &$entry) { $entry['id'] = $this->db->set($entry['id'], 'ent', array('trn_id' => $this->id, 'acc_id' => $entry['acc_id']->value(), 'amount' => $entry['amount']->value())); } unset($entry); $this->db->query('commit'); util::redirect('trn', 'load', array('id' => $this->id)); } else { $this->message = 'One or more entries has a balance of 0.00'; } } else { $this->message = 'There must be two or more entries to commit.'; } } else { $this->message = 'Your total must be 0.00'; } break; case 'cancel': util::redirect('secure'); case 'remove': $i = key($_POST['action']['remove']); $this->total -= $this->entry[$i]['amount']->value(); unset($this->entry[$i]); break; case 'add': $this->add_entry(); break; } util::redirect($this); }