Urldecode and other things

parent 2808b71c
......@@ -10,6 +10,14 @@ function notify(content)
if(typeof(notifycb)=="function")
notifycb(content);
}
function msgalert(content)
{
if(typeof(alertcb)=="function")
alertcb(content);
else
alert(content);
}
SkyliveX.changeContent.connect(changeContent);
SkyliveX.notify.connect(notify);
SkyliveX.alert.connect(msgalert);
......@@ -7,6 +7,14 @@
{
SkyliveX.pushLogin(document.forms.loginform.user.value, document.forms.loginform.pass.value);
}
function notifycb(msg)
{
document.getElementById("res").innerHTML=msg;
}
function alertcb(msg)
{
document.getElementById("alert").innerHTML=msg;
}
</script>
<style>
#page {
......@@ -20,6 +28,8 @@
<body>
<div id="page">
<b>SkyliveX 0.1.0 Login</b>
<div id="res"></div>
<div id="alert"></div>
<form id="login" name="loginform">
Username: <input type="text" value="" name="user" placeholder="username">
Password: <input type="password" value="" name="pass" placeholder="password">
......
......@@ -121,7 +121,7 @@ void SkyliveProtocol::processPackets()
std::cout << "Packet in Queue CRC " << pkt.crc.toInt() << " computed CRC " << pkt.computed_crc << std::endl;
if(pkt.crc.toInt()==pkt.computed_crc)
{
std::cout << "Packet CRC OK command: " << pkt.cmd.toStdString() <<std::endl;
std::cout << "Packet CRC OK command: " << pkt.cmd.toStdString() << " Params: " << pkt.params.toStdString() <<std::endl;
if(pkt.cmd=="LOGIN")
{
SKMessage::SKMessage msg("getlogin");
......@@ -143,6 +143,49 @@ void SkyliveProtocol::processPackets()
else if(pkt.cmd=="STATUS")
{
}
else if(pkt.cmd=="ENABLE")
{
SKMessage::SKMessage loginmsg("loginfailed");
if(pkt.params=="USERERRATO")
{
loginmsg.parameters.insert("why", "wronguser");
}
else if(pkt.params=="ADMIN")
{
loginmsg.handle="loginok";
loginmsg.parameters.insert("level", "admin");
}
else if(pkt.params=="ENABLED")
{
loginmsg.handle="loginok";
loginmsg.parameters.insert("level", "enabled");
}
else if(pkt.params=="GUEST")
{
loginmsg.handle="loginok";
loginmsg.parameters.insert("level", "guest");
}
else
{
loginmsg.parameters.insert("why", "unknown");
}
loginmsg.parameters.insert("response", pkt.params);
sendMessage(loginmsg);
}
else if(pkt.cmd=="SERMES")
{
QList<QString> paramlist = pkt.params.split(PARAM_SEPARATOR);
if(paramlist[0]=="ALERT")
{
if(paramlist.size() > 1) // For safety
{
SKMessage::SKMessage alertmsg("alert");
alertmsg.parameters.insert("msg", QByteArray::fromPercentEncoding(paramlist[1].toLocal8Bit()));
sendMessage(alertmsg);
}
}
}
else
{
......
......@@ -66,6 +66,10 @@ MainWin::MainWin(QString &htmlfile)
registerHandler((QString)"coreStarted", &MainWin::handle_corestarted);
registerHandler((QString)"telescopeConnected", &MainWin::handle_connected);
registerHandler((QString)"asklogin", &MainWin::handle_asklogin);
registerHandler((QString)"alert", &MainWin::handle_alert);
registerHandler((QString)"notify", &MainWin::handle_notify);
registerHandler((QString)"loginok", &MainWin::handle_loginres);
registerHandler((QString)"loginfailed", &MainWin::handle_loginres);
}
MainWin::~MainWin()
......@@ -200,6 +204,31 @@ void MainWin::handle_asklogin(SKMessage::SKMessage &msg)
}
void MainWin::handle_alert(SKMessage::SKMessage &msg)
{
if(msg.parameters.contains("msg"))
jsbridge.alert(msg.parameters["msg"]);
}
void MainWin::handle_notify(SKMessage::SKMessage &msg)
{
if(msg.parameters.contains("msg"))
jsbridge.notify(msg.parameters["msg"]);
}
void MainWin::handle_loginres(SKMessage::SKMessage &msg)
{
if(msg.handle=="loginok")
{
std::cout << "LOGIN OK" << std::endl;
}
else
{
std::cout << "LOGIN FAILED" << std::endl;
}
}
void JSBridge::changePageContent(QString elementid, QString content)
{
emit changeContent(elementid, content);
......
......@@ -65,6 +65,8 @@ class JSBridge : public QObject
signals:
void changeContent(QString elementid, QString content);
void notify(QString content);
void alert(QString content);
public slots:
void pushLogin(QString username, QString password);
void resizeWin(int width, int height);
......@@ -103,6 +105,9 @@ class MainWin : public QWebView
void handle_corestarted(SKMessage::SKMessage &msg);
void handle_connected(SKMessage::SKMessage &msg);
void handle_asklogin(SKMessage::SKMessage &msg);
void handle_alert(SKMessage::SKMessage &msg);
void handle_notify(SKMessage::SKMessage &msg);
void handle_loginres(SKMessage::SKMessage &msg);
void toggleBorders(bool borders);
void toggleTransparentBackground(bool transparentbg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment