void UserModule::sendAccount(WebPage *page, HttpRequest &request) { MySQL *query = manager->newQuery(); String guid = generateUUID(); String email = request.header.POST.getValue("email"); String login = request.header.POST.getValue("login"); if (email != "") { String password = manager->generateUserPassword(); String sql = "select * from users where email='" + email + "'"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { guid = query->getFieldValue(0, "uuid"); sql = "update users set newPassword='******', uuid='" + guid + "' where email='" + email + "'"; if (query->exec(sql)) {} } else { sql = "insert into users (email, login, newPassword, uuid) values('" + email + "', '" + login + "', '" + password + "', '" + guid + "')"; if (query->exec(sql)) {} } } } WebTemplate * tplEmail = new WebTemplate(); String userTpl = "email_tpl.html"; if (tplEmail->open(manager->modulePath + "/user/" + userTpl)) { tplEmail->out("host", page->site->host); tplEmail->out("email", email); tplEmail->out("password", password); tplEmail->out("guid", guid); tplEmail->exec(); sendMail(email, "no-reply@" + page->site->host, page->site->host + ": подтверждение аккаунта", tplEmail->html); } WebTemplate * tpl = new WebTemplate(); if (tpl->open(manager->modulePath + "/user/loginSendAccount_tpl.html")) { tpl->out("out", email); tpl->exec(); page->out("content", tpl->html); } } manager->deleteQuery(query); }
MySQL* ConnectionPool::init_connect() { MySQL *query = new MySQL(); if (!query->init()) { printf("!query->init()\n"); return NULL; } if (!query->connect("127.0.0.1", "root", "", "sitev")) { printf("!query->connect()\n"); return NULL; } query->exec("SET NAMES utf8"); return query; }
String WebModule::getModuleUrl() { MySQL *query = manager->newQuery(); String sql = "select * from modules where id='" + (String)moduleId + "'"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { String url = query->getFieldValue(0, "url"); return url; } } } return ""; }
void StaticPageModule::paint(WebPage *page, HttpRequest &request) { MySQL *query = manager->newQuery(); String sql = "select txt.value from data d, dataText txt where d.dataId=txt.id and d.pageId='" + (String)page->pageId + "'"; printf("sql = %s\n", sql.toString8().c_str()); if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { String content = query->getFieldValue(0, "value"); page->out("content", content); } } } }
void WebModule::setOptionsFromDB(int moduleId) { this->moduleId = moduleId; MySQL *query = manager->newQuery(); String sql = "select * from modules where id='" + (String)moduleId + "'"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { name = query->getFieldValue(0, "name"); about = query->getFieldValue(0, "about"); url = query->getFieldValue(0, "url"); return; } } } }
void UserModule::activate(WebPage *page, HttpRequest &request) { MySQL *query = manager->newQuery(); String p3 = request.header.GET.getValue("p3"); String sql = "update users set active = '1', password=newPassword where uuid = '" + p3 + "'"; WebTemplate * tpl = new WebTemplate(); String activateTpl = ""; if (query->exec(sql)) { activateTpl = "activateSuccess_tpl.html"; } else { activateTpl = "activateFail_tpl.html"; } if (tpl->open(manager->modulePath + "/user/" + activateTpl)) { tpl->exec(); page->out("content", tpl->html); } manager->deleteQuery(query); }
void NewsModule::paintTags(WebPage *page, String num, WebTemplate *tpl) { WebTemplate *tplTag = new WebTemplate(); if (tplTag->open(manager->modulePath + "/" + url + "/tag_tpl.html")) { MySQL *query = manager->newQuery(); String sql = "select tag1, tag2, tag3, tag4, tag5 from dataNews n, data d where d.dataId=n.id and d.pageId='" + (String)page->pageId + "' and d.moduleId='" + (String)moduleId + "' and n.num='" + num + "' order by n.num desc"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { for (int i = 1; i <= 5; i++) { String tag = query->getFieldValue(0, "tag" + (String)i); if (tag != "") { tplTag->out("name", tag); tplTag->exec(); tpl->out("tags", tplTag->html); } } } } } } }
void UserModule::ajax(WebPage *page, HttpRequest &request) { MySQL *query = manager->newQuery(); String obj = request.header.GET.getValue("p1"); String func = request.header.GET.getValue("p2"); String uuid = request.header.COOKIE.getValue("uuid"); if (obj == "user") { if (func == "login") { String login = request.header.POST.getValue("login"); String password = request.header.POST.getValue("password"); String chkSave = request.header.POST.getValue("chkSave"); page->tplIndex->out("out", "<note>\n"); page->tplIndex->out("out", "<login>" + login + "</login>\n"); String sql = (String)"select * from users where (email='" + login + "' or login='******') and password='******'"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { String userId = query->getFieldValue(0, "id"); // if (userId == 1) { if (true) { String sql = (String)"insert into uuid (uuid, userId, sec) values ('" + uuid + "', '" + userId + "', '10000')"; if (chkSave == "") sql = (String)"insert into uuid (uuid, userId, sec) values ('" + uuid + "', '" + userId + "', '0')"; if (query->exec(sql)) { page->tplIndex->out("out", "<result>" + ((String)1) + "</result>\n"); } bool flag = false; sql = "select serviceId, u.id from uuidPartner up, users u where isnull(up.deleted) and up.userId=u.id and cookie='" + uuid + "' order by u.id"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { flag = true; String ref = query->getFieldValue(0, "id"); String serviceId = query->getFieldValue(0, "serviceId"); sql = "select * from users where id='" + userId + "' and isnull(ref" + serviceId + ")"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { //String ref1_1 = query->getFieldValue(0, "ref1_1"); sql = "update users set ref" + serviceId + "='" + ref + "' where id='" + userId + "'"; query->exec(sql); for (int i = 1; i <= 4; i++) { String si = i; sql = "update users set ref" + serviceId + "_" + si + "=ref" + serviceId + "_" + si + "+1 where id='" + ref + "'"; query->exec(sql); sql = "select * from users where id='" + ref + "' and ref1<>id"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { ref = query->getFieldValue(0, "ref" + serviceId); } else break; } } } } } } sql = "update uuidPartner set deleted=1 where cookie='" + uuid + "'"; query->exec(sql); } } } if (flag == false) { sql = "update users set ref1=0 where id='" + userId + "'"; query->exec(sql); } } else { page->tplIndex->out("out", "<error>���� �������� ������������ - ���� � ������ ����������...</error>"); } } } } page->tplIndex->out("out", "</note>\n"); } else if (func == "logout") { if (uuid != "") { int userId = manager->getUserId(uuid); String sql = (String)"delete from uuid where userId='" + (String)userId + "'"; if (query->exec(sql)) { page->tplIndex->out("out", "<note>\n"); page->tplIndex->out("out", "<result>1</result>"); page->tplIndex->out("out", "</note>\n"); } } } else if (func == "isEmailExist") ajaxIsEmailExist(page, request); } manager->deleteQuery(query); }
void UserModule::changePassword(WebPage *page, HttpRequest &request) { MySQL *query = manager->newQuery(); String uuid = request.header.COOKIE.getValue("uuid"); int userId = manager->getUserId(uuid); WebTemplate * tpl = new WebTemplate(); String p3 = request.header.GET.getValue("p3"); if (p3 == "") { if (userId != 0) { if (tpl->open(manager->modulePath + "/2/changePassword_tpl.html")) { tpl->exec(); page->out("out", tpl->html); } } else { if (tpl->open(manager->documentRoot + "/tpl/message_tpl.html")) { tpl->out("caption", "����� ������"); tpl->out("error", "��� ����� ������ ������� �� ���� ��� ����� ������� � ������ �������"); tpl->exec(); page->out("out", tpl->html); } } } else if (p3 == "done") { if (tpl->open(manager->documentRoot + "/tpl/message_tpl.html")) { tpl->out("caption", "����� ������"); String message, error; if (userId != 0) { String oldPassword = request.header.POST.getValue("oldPassword"); String sql = "select * from users where id='" + (String)userId + "' and password='******'"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { String newPassword = request.header.POST.getValue("newPassword"); String repeatPassword = request.header.POST.getValue("repeatPassword"); error = manager->isPasswordCorrect(newPassword); if (error == "") { if (newPassword == repeatPassword) { String sql = "update users set password='******' where id='" + userId + "'"; if (query->exec(sql)) { message = "������ ��� ������� ������!"; } else { error = "������ ���� ������"; } } else error = "������ �� ���������"; } } else error = "������ ������ ����� �� ���������"; } } } else { error = "��� ����� ������ ������� �� ���� ��� ����� ������� � ������ �������"; } tpl->out("message", message); tpl->out("error", error); tpl->exec(); page->out("out", tpl->html); } } }
void NewsModule::paintNewsItemView(WebPage *page, HttpRequest &request, String num) { MySQL *query = manager->newQuery(); String uuid = request.header.COOKIE.getValue("uuid"); int userId = manager->getUserId(uuid); String sql = "select dt, name, about, text, n.num, n.id newsId from dataNews n, data d where d.dataId=n.id and d.pageId='" + (String)page->pageId + "' and d.moduleId='" + (String)moduleId + "' and n.num='" + num + "' order by n.num desc"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); if (count > 0) { WebTemplate * tpl = new WebTemplate(); if (tpl->open(manager->modulePath + "/" + url + "/view_tpl.html")) { String dt = query->getFieldValue(0, "dt"); dt = dtRus(dt, 0); String name = query->getFieldValue(0, "name"); String about = query->getFieldValue(0, "about"); String text = query->getFieldValue(0, "text"); //String num = query->getFieldValue(0, "num"); int newsId = query->getFieldValue(0, "newsId").toInt(); tpl->out("dt", dt); tpl->out("name", name); tpl->out("text", text); tpl->out("num", num); tpl->out("itemId", newsId); paintTags(page, num, tpl); sql = "select c.dt, c.comment, u.login from comments c, users u where u.id=c.userId and newsId='" + (String)newsId + "' order by c.id"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); for (int i = 0; i < count; i++) { String dt = query->getFieldValue(i, "dt"); String comment = query->getFieldValue(i, "comment"); String login = query->getFieldValue(i, "login"); WebTemplate * tplCommentItem = new WebTemplate(); if (tplCommentItem->open(manager->modulePath + "/" + url + "/commentItem_tpl.html")) { tplCommentItem->out("login", login); tplCommentItem->out("dt", dt); tplCommentItem->out("comment", comment); tplCommentItem->exec(); tpl->out("comments", tplCommentItem->html); } } } } WebTemplate * tplSendComment = new WebTemplate(); if (userId != 0) { if (tplSendComment->open(manager->modulePath + "/" + url + "/sendComment_tpl.html")) { tplSendComment->out("newsId", newsId); } } else { if (tplSendComment->open(manager->modulePath + "/" + url + "/sendCommentNotEnter_tpl.html")) { tplSendComment->out("newsId", newsId); } } tplSendComment->exec(); tpl->out("sendComment", tplSendComment->html); tpl->exec(); page->out("title", name); page->out("keywords", name); page->out("description", name); page->out("content", tpl->html); } } } } }
void NewsModule::paintNews(WebPage *page, HttpRequest &request) { WebTemplate *tpl = new WebTemplate(); if (!tpl->open(manager->modulePath + "/" + url + "/index_tpl.html")) return; WebTemplate *tplItem = new WebTemplate(); if (!tplItem->open(manager->modulePath + "/" + url + "/item_tpl.html")) return; WebTemplate *tplLast = new WebTemplate(); if (!tplLast->open(manager->modulePath + "/" + url + "/itemLast_tpl.html")) return; WebTemplate *tplTag = new WebTemplate(); if (!tplTag->open(manager->modulePath + "/" + url + "/tag_tpl.html")) return; MySQL *query = manager->newQuery(); String sql = "select count(*) cnt from dataNews n, data d where not isnull(num) and d.dataId=n.id and d.pageId='" + (String)page->pageId + "' and d.moduleId='" + (String)moduleId + "' order by dt desc"; int newsCount = 0; if (query->active(sql) > 0) { newsCount = query->getFieldValue(0, "cnt").toInt(); } int p = request.header.GET.getValue("p").toInt(); sql = "select * from dataNews n, data d where not isnull(num) and d.dataId=n.id and d.pageId='" + (String)page->pageId + "' and d.moduleId='" + (String)moduleId + "' order by dt desc limit " + (String)(p * 10) + ", 10"; if (query->exec(sql)) { if (query->storeResult()) { int count = query->getRowCount(); for (int i = 0; i < count; i++) { String id = query->getFieldValue(i, "id"); String dt = query->getFieldValue(i, "dt"); dt = dtRus(dt, 0); String name = query->getFieldValue(i, "name"); String about = query->getFieldValue(i, "about"); String text = query->getFieldValue(i, "text"); int num = query->getFieldValue(i, "num").toInt(); String tag1 = query->getFieldValue(i, "tag1"); String tag2 = query->getFieldValue(i, "tag2"); String tag3 = query->getFieldValue(i, "tag3"); String tag4 = query->getFieldValue(i, "tag4"); String tag5 = query->getFieldValue(i, "tag5"); WebTemplate *tpli = tplItem; if (i + 1 == count) tpli = tplLast; tpli->clearAllTags(); tpli->out("page", page->page); tpli->out("num", num); tpli->out("itemId", id); tpli->out("dt", dt); tpli->out("name", name); tpli->out("about", about); tpli->out("text", text); tpli->out("host", page->site->host); tplTag->clearAllTags(); tplTag->out("tag1", tag1); tplTag->out("tag2", tag2); tplTag->out("tag3", tag3); tplTag->out("tag4", tag4); tplTag->out("tag5", tag5); tplTag->exec(); tpli->out("tags", tplTag->html); tpli->exec(); tpl->out("out", tpli->html); } } } if (newsCount != 0) { WebTemplate *tplPag = new WebTemplate(); if (!tplPag->open(manager->modulePath + "/" + url + "/pagination_tpl.html")) return; int pageCount = newsCount / 10; if (newsCount % 10 != 0) pageCount++; for (int i = 0; i < pageCount; i++) { if (i == 0) tplPag->out("out", "<li><a href=\"/\">" + (String)(i + 1) + "</a></li>"); else tplPag->out("out", "<li><a href=\"/post?p=" + (String)i + "\">" + (String)(i + 1) + "</a></li>"); if (i + 1 == pageCount) tplPag->out("next", "/post?p=" + (String)i); } tplPag->exec(); tpl->out("out", tplPag->html); } String uuid = request.header.COOKIE.getValue("uuid"); int userId = manager->getUserId(uuid); WebTemplate *tplWrite = new WebTemplate(); if (userId != 0) { if (!tplWrite->open(manager->modulePath + "/" + url + "/addPostButton_tpl.html")) return; } else { if (!tplWrite->open(manager->modulePath + "/" + url + "/addPostButtonNotEnter_tpl.html")) return; } tplWrite->exec(); tpl->out("out", tplWrite->html); tpl->out("caption", caption); tpl->exec(); page->out("content", tpl->html); }