Exemplo n.º 1
0
void WorldController::save(const QString &pk)
{
    if (httpRequest().method() != Tf::Post) {
        return;
    }

    QString error;
    World world = World::get(pk.toUInt());
    if (world.isNull()) {
        error = "Original data not found. It may have been updated/removed by another transaction.";
        tflash(error);
        redirect(urla("edit", pk));
        return;
    }

    QVariantMap form = httpRequest().formItems("world");
    world.setProperties(form);
    if (world.save()) {
        QString notice = "Updated successfully.";
        tflash(notice);
        redirect(urla("show", pk));
    } else {
        error = "Failed to update.";
        texport(error);
        renderEdit(form);
    }
}
Exemplo n.º 2
0
void MarketingunitController::save(const QString &pk)
{
    if (httpRequest().method() != Tf::Post) {
        return;
    }

    QString error;
    auto marketingunit = Marketingunit::get(pk.toInt());
    if (marketingunit.isNull()) {
        error = "Original data not found. It may have been updated/removed by another transaction.";
        tflash(error);
        redirect(urla("edit", pk));
        return;
    }

    auto form = httpRequest().formItems("marketingunit");
    marketingunit.setProperties(form);
    if (marketingunit.save()) {
        QString notice = "Updated successfully.";
        tflash(notice);
        redirect(urla("show", pk));
    } else {
        error = "Failed to update.";
        texport(error);
        renderEdit(form);
    }
}
Exemplo n.º 3
0
void SessionController::login()
{
    if (httpRequest().method() != Tf::Post) {
        return;
    }

    QString password_md5;
    QByteArray bb;
    QString username = httpRequest().formItemValue("username");
    QString password = httpRequest().formItemValue("password");

    bb = QCryptographicHash::hash ( password.toLocal8Bit(), QCryptographicHash::Md5 );
    password_md5.append(bb.toHex());

    Admin admin = Admin::authenticate(username, password_md5);

    if(!admin.isNull()) {
        userLogin(&admin);
        redirect(QUrl("/admin/dashboard"));
    } else {
        QString message = "Login failed";
        texport(message);
        redirect(url("session", "form"));
    }
}
Exemplo n.º 4
0
void CmsController::savemanager(const QString &pk)
{
    QString adminID = session().value("adminID").toString();
    if (httpRequest().method() != Tf::Post) {
        return;
    }

    QString error;
    auto assetsunitmanager = Assetsunitmanager::get(pk);
    if (assetsunitmanager.isNull()) {
        error = "Original data not found. It may have been updated/removed by another transaction.";
        tflash(error);
        redirect(urla("change", pk));
        return;
    }
    Cms a;
    if(!a.update_manager(adminID,pk))
    {
        return;
    }

    auto form = httpRequest().formItems("assetsunitmanager");
    assetsunitmanager.setProperties(form);
    if (assetsunitmanager.save()) {
        redirect(urla("list_manager"));
    } else {
        error = "Failed to update.";
        texport(error);
        renderEdit(form);
    }

}
void EntryController::save(const QString &pk)
{
    if (httpRequest().method() != Tf::Post) {
        return;
    }

    QString error;
    Entry entry = Entry::get(pk.toInt());
    if (entry.isNull()) {
        error = "Original data not found. It may have been updated/removed by another transaction.";
        tflash(error);
        redirect(urla("edit", pk));
        return;
    } 
    
    entry.setProperties( httpRequest().formItems("entry") );
    if (entry.save()) {
        QString notice = "Updated successfully.";
        tflash(notice);
    } else {
        error = "Failed to update.";
        tflash(error);
    }
    redirect(urla("show", pk));
}
Exemplo n.º 6
0
void CmsController::search_manager()
{
    if(httpRequest().method() != Tf::Post){
        return;
    }
    auto form = httpRequest().formItems("assetsunitmanager");
    QString managerID = form["managerID"].toString();
    redirect(urla("show_manager", managerID));
}
Exemplo n.º 7
0
void CmsController::search_operator()
{
    if(httpRequest().method() != Tf::Post){
        return;
    }
    auto form = httpRequest().formItems("operators");
    QString operatorID = form["operatorID"].toString();
    redirect(urla("show_operator", operatorID));


}
Exemplo n.º 8
0
void MarketingunitController::showform() {
    QString start = httpRequest().formItemValue("start");
    QString end = httpRequest().formItemValue("end");
    QString error;
    QList<Marketingunit> list;
    TSqlQuery query;
    int c=0;
    if(start.isEmpty()&&end.isEmpty()) {
        query.exec("SELECT * FROM CMS.marketingunit ORDER BY MUdate;");
    } else if(start.isEmpty()||end.isEmpty()) {
        error="请输入日期";
        tflash(error);
        redirect(urla("reportform"));
        return;
    } else if(start>end) {
        error="起始日期应小于截止日期";
        tflash(error);
        redirect(urla("reportform"));
        return;
    } else {
        query.exec("SELECT * FROM CMS.marketingunit WHERE MUdate BETWEEN '"+start+"' AND '"+end+"' ORDER BY MUdate;");
    }

    while(query.next()) {
        Marketingunit a;
        a.setMuid(query.value(0).toInt());
        a.setMuvalue(query.value(1).toInt());
        a.setMusname(query.value(2).toString());
        a.setMuname(query.value(3).toString());


        a.setMudate(query.value(4).toDate());
        a.setSrcUnitID(query.value(5).toInt());
        a.setDestUnitID(query.value(6).toInt());
        a.setOperatorID(query.value(7).toString());
        c=a.muvalue()+c;
        list.append(a);
    }
    if(list.isEmpty()) {
        error="所选日期内无记录";
        tflash(error);
        redirect(urla("reportform"));
        return;
    }
    texport(list);
    texport(c);
    render();
}
Exemplo n.º 9
0
/*  
    Run the web client to retrieve a URI
    This will create the MPR and Http service on demand. As such, it is not the most
    efficient way to run a web request.
    @return HTTP status code or negative MPR error code. Returns a malloc string in response.
 */
PUBLIC int maRunWebClient(cchar *method, cchar *uri, cchar *data, char **response, char **err)
{
    Mpr         *mpr;
    HttpConn    *conn;
    int         status;

    if (err) {
        *err = 0;
    }
    if (response) {
        *response = 0;
    }
    if ((mpr = mprCreate(0, NULL, 0)) == 0) {
        mprLog("error appweb", 0, "Cannot create the MPR runtime");
        return MPR_ERR_CANT_CREATE;
    }
    if (mprStart() < 0) {
        mprLog("error appweb", 0, "Cannot start the web server runtime");
        return MPR_ERR_CANT_INITIALIZE;
    }
    httpCreate(HTTP_CLIENT_SIDE);
    conn = httpRequest(method, uri, data, err);
    status = httpGetStatus(conn);
    if (response) {
        *response = httpReadString(conn);
    }
    mprDestroy();
    return status;
}
Exemplo n.º 10
0
int CMDWifi::read() {

  // if three seconds have passed since your last connection,
  // then connect again and send data:
  if (millis() - lastConnectionTime > postingInterval) {
    httpRequest(urlPars);
  }

  char buffer[50] = "";
  int recording = 0;
  int i = 0;
  // if there is a message waiting from the server
  while (client.available()) {
    char c = client.read();
    if ((recording == 0 && c == 13) || // dumps all characters until
        (recording == 1 && c == 10) || // a sequence of 13 10 13 10 (CR LF CR LF)
        (recording == 2 && c == 13) || // is detected, then records
        (recording == 3 && c == 10))   // to buffer
          recording++;
    else if (recording != 4)
      recording = 0;
    else
      buffer[i++] = c;
  }

  if (buffer[0] != '\0') { // if buffer is not empty
    buffer[i++] = '\0'; // append \0 to terminate string
    return atoi(buffer); // return buffer as an integer
  }
  else
    return -1;
}
Exemplo n.º 11
0
String GAE(String link) {
	httpRequest(link);
	delay(10000);

	String readString = ""; //Reset string

	while (client.available() > 0) {

		char s = client.read();
		//Serial.print(s);			//Complete response w/ headers. For dev mode.
		if (s== '\n') {
			char c = client.read();
			//Serial.print(c);			//Parsed response. For dev mode.
			if (c == '\r') {
				while (client.connected()) {
					char z = client.read();
					readString += z;
				}
			}
		}
	}
	client.stop();
	return(readString);

}
void loop() {
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if there's no net connection, but there was one last time
  // through the loop, then stop the client:
  if (!client.connected() && lastConnected) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }

  // if you're not connected, and ten seconds have passed since
  // your last connection, then connect again and send data:
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
    httpRequest();
  }
  // store the state of the connection for next time through
  // the loop:
  lastConnected = client.connected();
}
Exemplo n.º 13
0
void CmsController::operatorlogin()
{
    if(httpRequest().method() != Tf::Post){
        return;
    }
    auto form = httpRequest().formItems("cms");
    Cms cms;
    if(cms.operatorlogin(form)){
        a = form["numberID"].toString();
        session().insert("operatorID",a);
        redirect(url("assetsunit","index"));
    }else{
        QString error = "NumberID or Password Error";
        tflash(error);
        redirect(urla("operator_login"));
    }
}
Exemplo n.º 14
0
void CmsController::adminlogin()
{
    if(httpRequest().method() != Tf::Post){
        return;
    }
    auto form = httpRequest().formItems("cms");
    Cms cms;
    if(cms.adminlogin(form)){
        b = form["numberID"].toString();
        session().insert("adminID",b);
        redirect(urla("admin_center",b));
    }else{
        QString error = "NumberID or Password Error";
        tflash(error);
        redirect(urla("admin_login"));
    }
}
void EntryController::create()
{
    if (httpRequest().method() != Tf::Post) {
        return;
    }
    
    Entry entry = Entry::create( httpRequest().formItems("entry") );
    if (!entry.isNull()) {
        QString notice = "Created successfully.";
        tflash(notice);
        redirect(urla("show", entry.id()));
    } else {
        QString error = "Failed to create.";
        texport(error);
        render("entry");
    }
}
Exemplo n.º 16
0
std::string
HttpServer::TcpMessageReceived(const std::string &msg)
{
	HttpRequestMessage httpRequest(msg);
	HttpResponseMessage httpResponse = this->HttpMessageReceived(httpRequest);
	std::string tcpResponse = httpResponse.GetBytes();
	
	return tcpResponse;
}
Exemplo n.º 17
0
void ParksController::create()
{
    if (httpRequest().method() != Tf::Post) {
        return;
    }

    auto form = httpRequest().formItems("parks");
    auto parks = Parks::create(form);
    if (!parks.isNull()) {
        QString notice = "Created successfully.";
        tflash(notice);
        redirect(urla("show", parks.id()));
    } else {
        QString error = "Failed to create.";
        texport(error);
        renderEntry(form);
    }
}
Exemplo n.º 18
0
void MarketingunitController::create()
{
    if (httpRequest().method() != Tf::Post) {
        return;
    }

    auto form = httpRequest().formItems("marketingunit");
    auto marketingunit = Marketingunit::create(form);
    if (!marketingunit.isNull()) {
        QString notice = "Created successfully.";
        tflash(notice);
        redirect(urla("show", marketingunit.muid()));
    } else {
        QString error = "Failed to create.";
        texport(error);
        renderEntry(form);
    }
}
Exemplo n.º 19
0
void Burst::MinerSocket::httpRequestAsync(const std::string method,
                                          const std::string url,
                                          const std::string body,
                                          const std::string header,
                                          std::function< void ( std::string ) > responseCallback )
{
    std::string response = httpRequest(method, url, body, header);
    responseCallback(response);
}
Exemplo n.º 20
0
void WorldController::create()
{
    if (httpRequest().method() != Tf::Post) {
        return;
    }

    QVariantMap form = httpRequest().formItems("world");
    World world = World::create(form);
    if (!world.isNull()) {
        QString notice = "Created successfully.";
        tflash(notice);
        redirect(urla("show", world.id()));
    } else {
        QString error = "Failed to create.";
        texport(error);
        renderEntry(form);
    }
}
Exemplo n.º 21
0
void AssetsunitmanagerController::create()
{
    if (httpRequest().method() != Tf::Post) {
        return;
    }

    auto form = httpRequest().formItems("assetsunitmanager");
    auto assetsunitmanager = Assetsunitmanager::create(form);
    if (!assetsunitmanager.isNull()) {
       QString notice = "Created successfully.";
        tflash(notice);
        redirect(urla("Cms/list_manager"));
    } else {
        QString error = "Failed to create.";
        texport(error);
        renderEntry(form);
    }
}
Exemplo n.º 22
0
QString codes_entryView::toString()
{
  responsebody.reserve(4599);
    tfetch(QVariantMap, codes);
  responsebody += tr("\n<h3>");
  responsebody += THttpUtility::htmlEscape(H::tr("Adding new code"));
  responsebody += tr("</h3>\n\n");
  responsebody += QVariant(formTag(H::createUrl({"codes", "create"}, httpRequest().queryItemValue("page", "1")), Tf::Post, true)).toString();
  responsebody += tr("\n\n\n        <div class=\"field\">\n        <label>");
  responsebody += THttpUtility::htmlEscape(H::tr("Title"));
  responsebody += tr("</label>\n        <input type=\"text\" name=\"codes[title]\" value=\"\" style=\"width: 400px\" class=\"form-input\" />\n        </div>\n        <div class=\"bbcodes\">\n            <div class=\"bold\">\n                ");
  responsebody += QVariant(linkTo("B", QUrl("#"), Tf::Get, "", a("class", "bbcode html") | a("data-editor", "b"))).toString();
  responsebody += tr("\n                ");
  responsebody += QVariant(linkTo("I", QUrl("#"), Tf::Get, "", a("class", "bbcode cursive") | a("data-editor", "i"))).toString();
  responsebody += tr("\n                ");
  responsebody += QVariant(linkTo("U", QUrl("#"), Tf::Get, "", a("class", "bbcode underline") | a("data-editor", "u"))).toString();
  responsebody += tr("\n                ");
  responsebody += QVariant(linkTo("S", QUrl("#"), Tf::Get, "", a("class", "bbcode del") | a("data-editor", "s"))).toString();
  responsebody += tr("\n                ");
  responsebody += QVariant(linkTo("IMG", QUrl("#"), Tf::Get, "", a("class", "bbcode html") | a("data-editor", "img"))).toString();
  responsebody += tr("\n                ");
  responsebody += QVariant(linkTo("URL", QUrl("#"), Tf::Get, "", a("class", "bbcode html") | a("data-editor", "url"))).toString();
  responsebody += tr("\n            </div>\n            ");
  for(const auto& tag: H::codesTitles().toStdMap()) {;
  responsebody += tr("                ");
  responsebody += QVariant(linkTo(tag.first, QUrl("#"), Tf::Get, a("class", "bbcode") | a("data-editor", tag.second))).toString();
  responsebody += tr("\n            ");
  };
  responsebody += tr("        </div>\n        <br>\n        <div class=\"field\" style=\"\">\n\n            <textarea rows=\"15\" style=\"width:700px\" class=\"editor\" data-editor=\"javascript\" class=\"form-input\" required></textarea>\n        </div>\n<input type=\"hidden\" id=\"code\" name=\"codes[code]\" value=\"\">\n\n            <div class=\"field\">\n            <small><i>");
  responsebody += THttpUtility::htmlEscape(H::tr("Note: If picture less than 150x150, it will be resized to it"));
  responsebody += tr("</i></small><br>\n            <label>");
  responsebody += THttpUtility::htmlEscape(H::tr("Image"));
  responsebody += tr("</label>\n                   <input type=\"file\" name=\"attachments[]\" multiple>\n            </div>\n\n");
  if(controller()->isUserLoggedIn()) {;
  responsebody += tr("        <div class=\"field\">\n            <label>");
  responsebody += THttpUtility::htmlEscape(H::tr("Status"));
  responsebody += tr("</label>\n            <input type=\"checkbox\" name=\"codes[status]\" value=\"1\" checked>\n        </div>\n        <div class=\"field\">\n            <label>");
  responsebody += THttpUtility::htmlEscape(H::tr("Editable"));
  responsebody += tr("</label>\n            <input type=\"checkbox\" name=\"codes[editable]\" value=\"1\" checked>\n        </div>\n        <div class=\"field\">\n            <label>");
  responsebody += THttpUtility::htmlEscape(H::tr("Show from"));
  responsebody += tr("</label>\n            <input type=\"text\" name=\"codes[showFrom]\" value=\"\">\n        </div>\n");
  } else {;
  responsebody += tr("\n");
  tfetch(QString, captcha);
  responsebody += tr("\n<div class=\"field\">\n    <img id=\"captcha_code\" src=\"data:image/png;base64,");
  responsebody += THttpUtility::htmlEscape(captcha);
  responsebody += tr("\"><br>\n    <small><a href=\"#\" id=\"update_captcha\" class=\"link\">");
  responsebody += THttpUtility::htmlEscape(H::tr("Update code"));
  responsebody += tr("</a></small><br>\n    <input type=\"text\" name=\"captcha\" value=\"\">\n</div>\n<script type=\"text/javascript\">\n$(\"#update_captcha\").click(function() {\n   $.post('/captcha.html', function(data) {\n       $(\"#captcha_code\").attr(\"src\", \"data:image/png;base64,\" + data);\n   })\n   return false;\n})\n</script>\n\n");
  };
  responsebody += tr("         <div class=\"actions\" style=\"margin-top: 20px;\">\n            <input type=\"submit\" id=\"save_code\" value=\"");
  responsebody += THttpUtility::htmlEscape(H::tr("Save"));
  responsebody += tr("\" />\n        </div>\n        </form>\n");

  return responsebody;
}
void FortuneController::remove(const QString &pk)
{
    if (httpRequest().method() != Tf::Post) {
        return;
    }

    Fortune fortune = Fortune::get(pk.toUInt());
    fortune.remove();
    redirect(urla("index"));
}
Exemplo n.º 24
0
void WorldController::remove(const QString &pk)
{
    if (httpRequest().method() != Tf::Post) {
        return;
    }

    World world = World::get(pk.toUInt());
    world.remove();
    redirect(urla("index"));
}
Exemplo n.º 25
0
void AssetsunitmanagerController::remove(const QString &pk)
{
    if (httpRequest().method() != Tf::Post) {
        return;
    }

    auto assetsunitmanager = Assetsunitmanager::get(pk.toInt());
    assetsunitmanager.remove();
    redirect(urla("index"));
}
Exemplo n.º 26
0
void ParksController::remove(const QString &pk)
{
    if (httpRequest().method() != Tf::Post) {
        return;
    }

    auto parks = Parks::get(pk.toInt());
    parks.remove();
    redirect(urla("index"));
}
Exemplo n.º 27
0
void MarketingunitController::remove(const QString &pk)
{
    if (httpRequest().method() != Tf::Post) {
        return;
    }

    auto marketingunit = Marketingunit::get(pk.toInt());
    marketingunit.remove();
    redirect(urla("index"));
}
void EntryController::remove(const QString &pk)
{
    if (httpRequest().method() != Tf::Post) {
        return;
    }
    
    Entry entry = Entry::get(pk.toInt());
    entry.remove();
    redirect(urla("index"));
}
Exemplo n.º 29
0
void CmsController::createmanager()
{
    QString adminID = session().value("adminID").toString();
    if (httpRequest().method() != Tf::Post) {
        return;
    }
   auto form = httpRequest().formItems("assetsunitmanager");
   QString managerID = form["managerID"].toString();
   Assetsunitmanager a;
   auto assetsunitmanager = a.create(form);
   if(!assetsunitmanager.isNull() && a.new_manager(adminID,managerID)){
      // QString adminID = session().value("adminID").toString();
           redirect(urla("list_manager"));
   }else{
       QString error = "资产管理人编号已经存在!";
       texport(error);
       renderEntry2(form);
   }

}
Exemplo n.º 30
0
void MarketingunitController::searching(){
    QString val = httpRequest().formItemValue("muid");
     QString error;
    auto marketingunit = Marketingunit::get(val.toInt());
    if (marketingunit.isNull()) {
        error = "关键字不存在";
        tflash(error);
        redirect(urla("index"));
        return;
    }else{
    redirect(urla("showsearch", val));}
}