Web interface: remove useless serve_users* methods from Server class
This commit is contained in:
parent
6fdc1635e4
commit
ed670fc5a9
2 changed files with 0 additions and 113 deletions
|
@ -388,116 +388,6 @@ void Server::serve_logout(struct mg_connection *conn, struct http_message *hm) {
|
|||
delete session;
|
||||
}
|
||||
|
||||
void Server::serve_users_add(struct mg_connection *conn, struct http_message *hm) {
|
||||
std::string user = get_http_var(hm, "user");
|
||||
std::string password = get_http_var(hm, "password");
|
||||
|
||||
if (!user.empty() && !password.empty()) {
|
||||
if (m_storage) {
|
||||
UserInfo dummy;
|
||||
bool registered = m_storage->getUser(user, dummy);
|
||||
if (!registered) {
|
||||
UserInfo info;
|
||||
info.jid = user;
|
||||
info.password = password;
|
||||
m_storage->setUser(info);
|
||||
}
|
||||
else {
|
||||
redirect_to(conn, hm, "/users?error=This+username+is+already+registered");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
redirect_to(conn, hm, "/users?ok=1");
|
||||
}
|
||||
|
||||
void Server::serve_users_remove(struct mg_connection *conn, struct http_message *hm) {
|
||||
Server:session *session = get_session(hm);
|
||||
if (!session->admin) {
|
||||
redirect_to(conn, hm, "/");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_storage) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string user = get_http_var(hm, "user");
|
||||
UserInfo info;
|
||||
m_storage->getUser(user, info);
|
||||
m_storage->removeUser(info.id);
|
||||
redirect_to(conn, hm, "/users");
|
||||
}
|
||||
|
||||
void Server::serve_users(struct mg_connection *conn, struct http_message *hm) {
|
||||
std::string html;
|
||||
Server:session *session = get_session(hm);
|
||||
if (!session) {
|
||||
std::string ok = get_http_var(hm, "ok");
|
||||
if (!ok.empty()) {
|
||||
redirect_to(conn, hm, "/");
|
||||
return;
|
||||
}
|
||||
html += "<h2>Register new Spectrum 2 master account</h2>";
|
||||
}
|
||||
else {
|
||||
html += "<h2>Spectrum 2 manager users</h2>";
|
||||
|
||||
if (!session->admin) {
|
||||
html += "<p>Only Spectrum 2 manager administrator can access this page.</p>";
|
||||
print_html(conn, hm, html);
|
||||
return;
|
||||
}
|
||||
|
||||
html += "<p>Here, you can add new users who will have access to this web interface. "
|
||||
"These users will be able to register new accounts on all Spectrum 2 instances "
|
||||
"running on these server. They won't be able to change any Spectrum 2 instance "
|
||||
"configuration influencing other users.</p>";
|
||||
}
|
||||
|
||||
std::string error = get_http_var(hm, "error");
|
||||
if (!error.empty()) {
|
||||
html += "<p><b>Error: " + error + "</b></p>";
|
||||
}
|
||||
|
||||
if (!m_storage) {
|
||||
print_html(conn, hm, html);
|
||||
return;
|
||||
}
|
||||
|
||||
html += "<form action=\"/users/add\" class=\"basic-grey\" method=\"POST\"> \
|
||||
<h1>Register user \
|
||||
<span>Register new user to Spectrum 2 manager web interface.</span> \
|
||||
</h1> \
|
||||
<label> \
|
||||
<span>Username:</span> \
|
||||
<input type=\"text\" id=\"user\" name=\"user\"placeholder=\"Username\"></textarea> \
|
||||
</label> \
|
||||
<label><span>Password:</span> \
|
||||
<input type=\"password\" id=\"password\" name=\"password\" placeholder=\"Password\"></textarea> \
|
||||
</label> \
|
||||
<label> \
|
||||
<span> </span> \
|
||||
<input type=\"submit\" class=\"button\" value=\"Add user\" />\
|
||||
</label> \
|
||||
</form><br/>";
|
||||
std::vector<std::string> users;
|
||||
m_storage->getUsers(users);
|
||||
|
||||
if (session) {
|
||||
html += "<table><tr><th>User<th>Action</th></tr>";
|
||||
BOOST_FOREACH(std::string &user, users) {
|
||||
html += "<tr>";
|
||||
html += "<td><a href=\"/users?jid=" + user + "\">" + user + "</a></td>";
|
||||
html += "<td><a href=\"/users/remove?user=" + user + "\">Remove</a></td>";
|
||||
html += "</tr>";
|
||||
}
|
||||
html += "</table>";
|
||||
}
|
||||
|
||||
print_html(conn, hm, html);
|
||||
}
|
||||
|
||||
void Server::serve_oauth2(struct mg_connection *conn, struct http_message *hm) {
|
||||
std::cout << "OAUTH2 handler\n";
|
||||
}
|
||||
|
|
|
@ -66,9 +66,6 @@ class Server {
|
|||
std::string send_command(const std::string &jid, const std::string &cmd);
|
||||
|
||||
private:
|
||||
void serve_users(struct mg_connection *conn, struct http_message *hm);
|
||||
void serve_users_add(struct mg_connection *conn, struct http_message *hm);
|
||||
void serve_users_remove(struct mg_connection *conn, struct http_message *hm);
|
||||
void serve_logout(struct mg_connection *conn, struct http_message *hm);
|
||||
void serve_oauth2(struct mg_connection *conn, struct http_message *hm);
|
||||
void print_html(struct mg_connection *conn, struct http_message *hm, const std::string &html);
|
||||
|
|
Loading…
Add table
Reference in a new issue