Skip to content

Commit

Permalink
Setting to turn on/off ability to create accounts.
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Feb 27, 2024
1 parent a4d869f commit 7f323c2
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 120 deletions.
73 changes: 39 additions & 34 deletions config/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <cstdlib>
#include <webserver/request.h>
#include <config/globals.h>
using namespace std;


namespace config::logic {
Expand All @@ -49,18 +48,18 @@ const char * version ()
void load_settings ()
{
// Read the setting whether to log network connections.
string path = filter_url_create_root_path ({config::logic::config_folder (), "log-network"});
const std::string path = filter_url_create_root_path ({config::logic::config_folder (), "log-network"});
config_globals_log_network = file_or_dir_exists (path);
}


// Return the network port configured for the server.
string http_network_port ()
std::string http_network_port ()
{
// If a port number is known already, take that.
if (!config_globals_negotiated_port_number.empty()) return config_globals_negotiated_port_number;
// Read the port number from file.
string path = filter_url_create_root_path ({config::logic::config_folder (), "network-port"});
const std::string path = filter_url_create_root_path ({config::logic::config_folder (), "network-port"});
config_globals_negotiated_port_number = filter_url_file_get_contents (path);
// Remove white-space, e.g. a new line, that easily makes its way into the configuration file.
config_globals_negotiated_port_number = filter::strings::trim (config_globals_negotiated_port_number);
Expand All @@ -72,11 +71,11 @@ string http_network_port ()


// Return the secure network port for the secure server.
string https_network_port ()
std::string https_network_port ()
{
// Read the port number from file.
string path = filter_url_create_root_path ({config::logic::config_folder (), "network-port-secure"});
string port = filter_url_file_get_contents (path);
const std::string path = filter_url_create_root_path ({config::logic::config_folder (), "network-port-secure"});
std::string port = filter_url_file_get_contents (path);
// Remove white-space, e.g. a new line, that easily makes its way into the configuration file.
port = filter::strings::trim (port);
// Default value.
Expand All @@ -93,49 +92,49 @@ string https_network_port ()
// Returns whether demo mode is enabled during configure.
bool demo_enabled ()
{
string path = filter_url_create_root_path ({config::logic::config_folder (), "demo"});
const std::string path = filter_url_create_root_path ({config::logic::config_folder (), "demo"});
return file_or_dir_exists (path);
}


// The configured admin's username.
string admin_username ()
std::string admin_username ()
{
string path = filter_url_create_root_path ({config::logic::config_folder (), "admin-username"});
const std::string path = filter_url_create_root_path ({config::logic::config_folder (), "admin-username"});
return filter::strings::trim (filter_url_file_get_contents (path));
}


// The configured admin's password.
string admin_password ()
std::string admin_password ()
{
string path = filter_url_create_root_path ({config::logic::config_folder (), "admin-password"});
const std::string path = filter_url_create_root_path ({config::logic::config_folder (), "admin-password"});
return filter::strings::trim (filter_url_file_get_contents (path));
}


// The configured admin's email.
string admin_email ()
std::string admin_email ()
{
string path = filter_url_create_root_path ({config::logic::config_folder (), "admin-email"});
const std::string path = filter_url_create_root_path ({config::logic::config_folder (), "admin-email"});
return filter::strings::trim (filter_url_file_get_contents (path));
}


// Returns whether the interface is supposed to be in basic mode.
bool basic_mode (Webserver_Request& webserver_request)
{
bool basic_mode {webserver_request.database_config_user ()->getBasicInterfaceMode ()};
const bool basic_mode {webserver_request.database_config_user ()->getBasicInterfaceMode ()};
return basic_mode;
}


// This returns the URL of Bibledit Cloud that faces the user.
string site_url (Webserver_Request& webserver_request)
std::string site_url (Webserver_Request& webserver_request)
{
// When the administrator has entered a fixed value for the user-facing URL, take that.
// It overrides everything.
string url = config::logic::manual_user_facing_url ();
std::string url = config::logic::manual_user_facing_url ();
if (!url.empty ()) return url;

// If a webserver request is passed, take the host from there.
Expand All @@ -158,14 +157,14 @@ string site_url (Webserver_Request& webserver_request)


// This returns the filtered value of file userfacingurl.conf.
string manual_user_facing_url ()
std::string manual_user_facing_url ()
{
#ifdef HAVE_CLIENT
return string();
return std::string();
#else
// Read the configuration file.
string path = filter_url_create_root_path ({config::logic::config_folder (), "userfacingurl.conf"});
string url = filter_url_file_get_contents (path);
const std::string path = filter_url_create_root_path ({config::logic::config_folder (), "userfacingurl.conf"});
std::string url = filter_url_file_get_contents (path);
// Remove white space.
url = filter::strings::trim (url);
// The previous file contained dummy text by default. Remove that.
Expand All @@ -179,24 +178,24 @@ string manual_user_facing_url ()


// Returns the path to the secure server's private key.
string server_key_path (const bool force)
std::string server_key_path (const bool force)
{
// Try the correct config file first.
string path = filter_url_create_root_path ({config::logic::config_folder (), "privkey.pem"});
const std::string path = filter_url_create_root_path ({config::logic::config_folder (), "privkey.pem"});
if (force || file_or_dir_exists (path)) return path;
// Nothing found.
return string();
return std::string();
}


// Returns the path to the secure server's public certificate.
string server_certificate_path (const bool force)
std::string server_certificate_path (const bool force)
{
// Try the correct config file first.
string path = filter_url_create_root_path ({config::logic::config_folder (), "cert.pem"});
const std::string path = filter_url_create_root_path ({config::logic::config_folder (), "cert.pem"});
if (force || file_or_dir_exists (path)) return path;
// Nothing found.
return string();
return std::string();
}


Expand All @@ -205,13 +204,13 @@ string server_certificate_path (const bool force)
// At the top of the file will be the intermediate authority that issued the server certificate.
// Next can be more intermediate authorities.
// At the bottom of the file should be the trusted root certificate.
string authorities_certificates_path (const bool force)
std::string authorities_certificates_path (const bool force)
{
// Try the correct config file first.
string path = filter_url_create_root_path ({config::logic::config_folder (), "chain.pem"});
const std::string path = filter_url_create_root_path ({config::logic::config_folder (), "chain.pem"});
if (force || file_or_dir_exists (path)) return path;
// Nothing found.
return string();
return std::string();
}


Expand All @@ -229,9 +228,9 @@ bool enforce_https_client ()
}


void swipe_enabled (Webserver_Request& webserver_request, string & script)
void swipe_enabled (Webserver_Request& webserver_request, std::string& script)
{
string true_false {"false"};
std::string true_false {"false"};
if (webserver_request.session_logic ()->touchEnabled ()) {
if (webserver_request.database_config_user ()->getSwipeActionsAvailable ()) {
true_false = "true";
Expand All @@ -254,7 +253,7 @@ bool indonesian_member_cloud ()
if (read) return status;

// Read the status from disk and cache it.
string path = filter_url_create_root_path ({config::logic::config_folder (), "indonesianmembercloud"});
const std::string path = filter_url_create_root_path ({config::logic::config_folder (), "indonesianmembercloud"});
status = file_or_dir_exists (path);
read = true;

Expand All @@ -273,10 +272,16 @@ bool default_bibledit_configuration ()
}


string google_translate_json_key_path ()
std::string google_translate_json_key_path ()
{
return filter_url_create_root_path ({config::logic::config_folder (), "googletranslate.json"});
}


bool create_no_accounts()
{
return file_or_dir_exists (filter_url_create_root_path ({config::logic::config_folder (), "create-no-accounts"}));
}


} // End of namespace.
3 changes: 2 additions & 1 deletion config/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ std::string server_certificate_path (const bool force);
std::string authorities_certificates_path (const bool force);
bool enforce_https_browser ();
bool enforce_https_client ();
void swipe_enabled (Webserver_Request& webserver_request, std::string & script);
void swipe_enabled (Webserver_Request& webserver_request, std::string& script);
bool indonesian_member_cloud ();
bool default_bibledit_configuration ();
std::string google_translate_json_key_path ();
bool create_no_accounts();

} // End of namespace.
7 changes: 7 additions & 0 deletions help/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ <h3>Administrator details</h3>
Now the admin credentials will take effect, and you can login using those.
</p>

<h3>Account creation</h3>
<p>
Normally anyone can create an account on Bibledit-Cloud.
If this is not desired, tnen put a file called "create-no-accounts" in the "config" folder.
Now creation of accounts is no longer possible, and public feedback is no longer possible.
</p>

<h3>Demo</h3>
<p>
If the file "demo" is in the "config" folder,
Expand Down
16 changes: 11 additions & 5 deletions menu/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ string menu_logic_main_categories (Webserver_Request& webserver_request, string
// put the public feedback into the main menu, rather than in a sub menu.
if (menu_logic_public_or_guest (webserver_request)) {
if (!public_logic_bibles (webserver_request).empty ()) {
html.push_back (menu_logic_create_item (public_index_url (), menu_logic_public_feedback_text (), true, "", ""));
tooltipbits.push_back (menu_logic_public_feedback_text ());
if (!config::logic::create_no_accounts()) {
html.push_back (menu_logic_create_item (public_index_url (), menu_logic_public_feedback_text (), true, "", ""));
tooltipbits.push_back (menu_logic_public_feedback_text ());
}
}
}
#endif
Expand Down Expand Up @@ -327,7 +329,9 @@ string menu_logic_basic_categories (Webserver_Request& webserver_request)
if (public_feedback_possible) {
if (menu_logic_public_or_guest (webserver_request)) {
if (!public_logic_bibles (webserver_request).empty ()) {
html.push_back (menu_logic_create_item (public_index_url (), menu_logic_public_feedback_text (), true, "", ""));
if (!config::logic::create_no_accounts()) {
html.push_back (menu_logic_create_item (public_index_url (), menu_logic_public_feedback_text (), true, "", ""));
}
}
}
}
Expand Down Expand Up @@ -442,8 +446,10 @@ string menu_logic_translate_category (Webserver_Request& webserver_request, stri
if (!webserver_request.session_logic ()->currentUser ().empty ()) {
if (!menu_logic_public_or_guest (webserver_request)) {
if (!public_logic_bibles (webserver_request).empty ()) {
html.push_back (menu_logic_create_item (public_index_url (), menu_logic_public_feedback_text (), true, "", ""));
labels.push_back (menu_logic_public_feedback_text ());
if (!config::logic::create_no_accounts()) {
html.push_back (menu_logic_create_item (public_index_url (), menu_logic_public_feedback_text (), true, "", ""));
labels.push_back (menu_logic_public_feedback_text ());
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions public/chapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <filter/css.h>
#include <webserver/request.h>
#include <database/config/bible.h>
#include <config/logic.h>


std::string public_chapter_url ()
Expand All @@ -35,6 +36,7 @@ std::string public_chapter_url ()

bool public_chapter_acl (Webserver_Request& webserver_request)
{
if (config::logic::create_no_accounts()) return false;
return Filter_Roles::access_control (webserver_request, Filter_Roles::guest ());
}

Expand Down
21 changes: 11 additions & 10 deletions public/comment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,56 +32,57 @@
#include <ipc/focus.h>
#include <navigation/passage.h>
#include <public/note.h>
using namespace std;
#include <config/logic.h>


string public_comment_url ()
std::string public_comment_url ()
{
return "public/comment";
}


bool public_comment_acl (Webserver_Request& webserver_request)
{
if (config::logic::create_no_accounts()) return false;
return Filter_Roles::access_control (webserver_request, Filter_Roles::guest ());
}


string public_comment (Webserver_Request& webserver_request)
std::string public_comment (Webserver_Request& webserver_request)
{
Database_Notes database_notes (webserver_request);
Notes_Logic notes_logic (webserver_request);


string page;
std::string page;
Assets_Header header = Assets_Header (translate("Feedback"), webserver_request);
page += header.run ();
Assets_View view;


int id = filter::strings::convert_to_int (webserver_request.query ["id"]);
const int id = filter::strings::convert_to_int (webserver_request.query ["id"]);
view.set_variable ("id", filter::strings::convert_to_string (id));


if (webserver_request.post.count ("submit")) {
string comment = filter::strings::trim (webserver_request.post ["comment"]);
const std::string comment = filter::strings::trim (webserver_request.post ["comment"]);
notes_logic.addComment (id, comment);
redirect_browser (webserver_request, public_note_url () + "?id=" + filter::strings::convert_to_string (id));
return "";
return std::string();
}


if (webserver_request.post.count ("cancel")) {
redirect_browser (webserver_request, public_note_url () + "?id=" + filter::strings::convert_to_string (id));
return "";
return std::string();
}


string summary = database_notes.get_summary (id);
const std::string summary = database_notes.get_summary (id);
view.set_variable ("summary", summary);


string content = database_notes.get_contents (id);
const std::string content = database_notes.get_contents (id);
view.set_variable ("content", content);


Expand Down
Loading

0 comments on commit 7f323c2

Please sign in to comment.