index.js.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // Created by xcbosa on 2023-01-30
  3. //
  4. #include "../../processor/processor.h"
  5. #include "../../utils/utils.h"
  6. #include "../../webuiconf.h"
  7. using namespace std;
  8. using namespace xc::processor;
  9. using namespace xc::utils;
  10. using namespace xc::processor::templates;
  11. namespace xc::controller {
  12. static string ControllerPath = "/index.js";
  13. static ResponseData *controllerResponse(RequestData request) {
  14. return new TextResponseData(200,
  15. string("let app = new Framework7({\n") +
  16. string(" // App root element\n") +
  17. string(" el: \'#app\',\n") +
  18. string(" // App Name\n") +
  19. string(" name: \'FRPCWebUI\',\n") +
  20. string(" // App id\n") +
  21. string(" id: \'org.forgetive.frpcwebui\',\n") +
  22. string(" // Enable swipe panel\n") +
  23. string(" panel: {\n") +
  24. string(" swipe: true,\n") +
  25. string(" },\n") +
  26. string(" // Add default routes\n") +
  27. string(" routes: [\n") +
  28. string(" {\n") +
  29. string(" path: \'/about/\',\n") +
  30. string(" url: \'about.html\',\n") +
  31. string(" },\n") +
  32. string(" ]\n") +
  33. string("});\n") +
  34. string("\n") +
  35. string("function doLogin(salt) {\n") +
  36. string(" let data = app.form.convertToData(\"#loginForm\")\n") +
  37. string(" if (data.username.length == 0) {\n") +
  38. string(" app.dialog.alert(\"请输入用户名\")\n") +
  39. string(" return\n") +
  40. string(" }\n") +
  41. string(" if (data.password.length == 0) {\n") +
  42. string(" app.dialog.alert(\"请输入密码\")\n") +
  43. string(" return\n") +
  44. string(" }\n") +
  45. string(" data.password = sha256_digest(data.password + salt)\n") +
  46. string(" window.location = \"/login?v=\" + JSON.stringify(data)\n") +
  47. string(" return\n") +
  48. string("}\n")
  49. , mimeTypeOfFile(ControllerPath));
  50. }
  51. ContentGeneratorDefineS(request.getURLPath() == ControllerPath, controllerResponse(request))
  52. }