diff --git a/spectrum_manager/src/server.cpp b/spectrum_manager/src/server.cpp index e9a669107313474259b580557f810086c414d058..d57eda4e1ef8667142a052368d892613f1b766bd 100644 --- a/spectrum_manager/src/server.cpp +++ b/spectrum_manager/src/server.cpp @@ -189,6 +189,8 @@ bool Server::is_authorized(const struct mg_connection *conn, struct http_message !mg_vcmp(&hm->uri, "/form.css") || !mg_vcmp(&hm->uri, "/style.css") || !mg_vcmp(&hm->uri, "/logo.png") || + !mg_vcmp(&hm->uri, "/users") || + !mg_vcmp(&hm->uri, "/users/add") || !mg_vcmp(&hm->uri, "/authorize")) { return true; } @@ -315,24 +317,26 @@ void Server::serve_logout(struct mg_connection *conn, struct http_message *hm) { } void Server::serve_users_add(struct mg_connection *conn, struct http_message *hm) { - Server:session *session = get_session(hm); - if (!session->admin) { - redirect_to(conn, hm, "/"); - return; - } - std::string user = get_http_var(hm, "user"); std::string password = get_http_var(hm, "password"); if (!user.empty() && !password.empty()) { - UserInfo info; - info.jid = user; - info.password = password; if (m_storage) { - m_storage->setUser(info); + 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"); + redirect_to(conn, hm, "/users?ok=1"); } void Server::serve_users_remove(struct mg_connection *conn, struct http_message *hm) { @@ -354,19 +358,35 @@ void Server::serve_users_remove(struct mg_connection *conn, struct http_message } void Server::serve_users(struct mg_connection *conn, struct http_message *hm) { - std::string html = "

Spectrum 2 manager users

"; - + std::string html; Server:session *session = get_session(hm); - if (!session->admin) { - html += "

Only Spectrum 2 manager administrator can access this page.

"; - print_html(conn, hm, html); - return; + if (!session) { + std::string ok = get_http_var(hm, "ok"); + if (!ok.empty()) { + redirect_to(conn, hm, "/"); + return; + } + html += "

Register new Spectrum 2 master account

"; } + else { + html += "

Spectrum 2 manager users

"; - html += "

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.

"; + if (!session->admin) { + html += "

Only Spectrum 2 manager administrator can access this page.

"; + print_html(conn, hm, html); + return; + } + + html += "

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.

"; + } + + std::string error = get_http_var(hm, "error"); + if (!error.empty()) { + html += "

Error: " + error + "

"; + } if (!m_storage) { print_html(conn, hm, html); @@ -374,8 +394,8 @@ void Server::serve_users(struct mg_connection *conn, struct http_message *hm) { } html += "
\ -

Add user \ - Add new user to Spectrum 2 manager web interface. \ +

Register user \ + Register new user to Spectrum 2 manager web interface. \

\