Fotobot
Get data from your photovoltaic plant
mrequesthandler.cpp
Go to the documentation of this file.
1 
7 #include "mrequesthandler.h"
8 #include "static.h"
9 #include <QVariant>
10 #include <QDateTime>
11 
12 MRequestHandler::MRequestHandler() : HttpRequestHandler() {
13  m_needs_access_data = true;
14  m_needs_change_settings = true;
15  m_cacheable = false;
16 }
17 
18 bool MRequestHandler::needsLogin(HttpRequest& request, HttpResponse& response) {
19  if (!m_needs_access_data && !m_needs_change_settings) {
20  return false;
21  }
22  HttpSession session=Static::sessionStore->getSession(request,response);
23  if ((m_needs_access_data && !session.contains("can_access_data")) ||
24  (m_needs_change_settings && !session.contains("can_change_settings"))) {
25  Static::sessionStore->removeSession(session);
26  QByteArray path = request.getPath();
27  QString location = QString("/login?returnPath=%1").arg(QString(path.toPercentEncoding()));
28  response.setStatus(301, "Moved Permanently");
29  response.setHeader("Location", location.toUtf8());
30  response.setHeader("Content-Type", "text/html; charset=utf-8");
31  response.write(tr("<h1>Moved Permanently</h1><p>The document has moved <a href=\"%1\">here</a>.</p>\n").arg(location).toUtf8());
32  return true;
33  }
34 
35  return false;
36 }
37 
38 
static HttpSessionStore * sessionStore
Definition: static.h:57