Skip to content

Commit

Permalink
Updating installation code
Browse files Browse the repository at this point in the history
  • Loading branch information
benkeen committed Apr 21, 2013
1 parent cb5da59 commit 86ef6fb
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 29 deletions.
2 changes: 1 addition & 1 deletion index.php
Expand Up @@ -6,7 +6,7 @@
// if need be, redirect to the install instructions page
Utils::maybeShowInstallationPage();

if (!Core::checkIsLoggedIn() && !Core::checkDemoModeAllowAnonymousUse()) {
if (!Core::checkIsLoggedIn() && !Core::checkAllowMultiUserAnonymousUse()) {
header("location: login.php#t1");
exit;
}
Expand Down
2 changes: 1 addition & 1 deletion login.php
Expand Up @@ -7,7 +7,7 @@
Utils::maybeShowInstallationPage();

$isLoggedIn = Core::checkIsLoggedIn();
if ($isLoggedIn || (!$isLoggedIn && Core::checkDemoModeAllowAnonymousUse())) {
if ($isLoggedIn || (!$isLoggedIn && Core::checkAllowMultiUserAnonymousUse())) {
header("location: ./");
exit;
}
Expand Down
20 changes: 10 additions & 10 deletions resources/classes/Account.class.php
Expand Up @@ -396,13 +396,13 @@ public static function createAccount($accountInfo) {
first_name, last_name, email, password)
VALUES ('$now', '$now', '$now', NULL, '$accountType', '$firstName', '$lastName', '$email', '$password')
");

if ($autoEmail) {
$content = $L["account_created_msg"] + "\n";
$content = $L["account_created_msg"] . "\n\n";
if (isset($_SERVER["HTTP_REFERER"]) && !empty($_SERVER["HTTP_REFERER"])) {
$content .= "Login URL: {$_SERVER["HTTP_REFERER"]}\n";
$content .= "{$L["login_url_c"]} {$_SERVER["HTTP_REFERER"]}\n";
}
$content .= "Email: $email\nPassword: {$accountInfo["password"]}\n";
$content .= "{$L["email_c"]} $email\n{$L["password_c"]} {$accountInfo["password"]}\n";

$response = Emails::sendEmail(array(
"recipient" => $email,
Expand All @@ -411,12 +411,12 @@ public static function createAccount($accountInfo) {
));
}

// if ($result["success"]) {
// $accountID = mysql_insert_id();;
// Core::initSessions();
// $_SESSION["account_id"] = $accountID;
// Core::initUser(true);
// }
if ($result["success"]) {
$accountID = mysql_insert_id();
Core::initSessions();
$_SESSION["account_id"] = $accountID;
Core::initUser(true);
}
}


Expand Down
3 changes: 3 additions & 0 deletions resources/classes/AjaxRequest.class.php
Expand Up @@ -77,6 +77,8 @@ public function __construct($action, $post = array()) {
Settings::setSetting("userAccountSetup", $post["userAccountSetup"]);
Settings::setSetting("installationStepComplete_Core", "yes");
Settings::setSetting("defaultLanguage", $post["defaultLanguage"]);
Settings::setSetting("allowAnonymousAccess", $post["allowAnonymousAccess"]);
Settings::setSetting("anonymousUserPermissionDeniedMsg", $post["anonymousUserPermissionDeniedMsg"]);

$this->response["success"] = 1;
$this->response["content"] = "";
Expand Down Expand Up @@ -106,6 +108,7 @@ public function __construct($action, $post = array()) {
} catch (Exception $e) {
$this->response["success"] = false;
$this->response["content"] = "Unknown error.";

}
}
break;
Expand Down
13 changes: 6 additions & 7 deletions resources/classes/Core.class.php
Expand Up @@ -13,7 +13,7 @@ class Core {

// overridable settings that the user may define in settings.php
private static $demoMode = false;
private static $allowDemoModeAnonymousUse = true;
private static $allowMultiUserAnonymousUse = true;
private static $dbHostname;
private static $dbName;
private static $dbUsername;
Expand Down Expand Up @@ -77,7 +77,7 @@ public static function init($runtimeContext = "ui") {
// the order is significant in all of this
if ($runtimeContext != "installation" || $runtimeContext != "installation_db_ready") {
self::initDatabase();
if ($runtimeContext == "ui" || $runtimeContext == "generation") {
if ($runtimeContext == "installation_db_ready" || $runtimeContext == "ui" || $runtimeContext == "generation") {
self::initSessions();
}

Expand Down Expand Up @@ -161,8 +161,8 @@ public function checkDemoMode() {
/**
* @access public
*/
public function checkDemoModeAllowAnonymousUse() {
return self::$allowDemoModeAnonymousUse;
public function checkAllowMultiUserAnonymousUse() {
return self::$allowMultiUserAnonymousUse;
}

/**
Expand Down Expand Up @@ -342,7 +342,6 @@ private function initGeoData() {
self::$geoData = new GeoData();
}


/**
* Initializes the Database object and stores it in Core::$db.
* @access private
Expand Down Expand Up @@ -382,9 +381,9 @@ private function initExportTypes($runtimeContext) {
* if self::allowDemoModeAnonymousUse is enabled and the user isn't logged in, this won't
* initialize the user - however, they can still access the script (just not save anything). You
* can always detect for this by checking self::$isLoggedIn
* @access private
* @access public
*/
private function initUser($bypass = false) {
public function initUser($bypass = false) {
if ($bypass || self::checkIsInstalled()) {
$setup = Settings::getSetting("userAccountSetup");
if ($setup == "anonymousAdmin") {
Expand Down
4 changes: 3 additions & 1 deletion resources/classes/Installation.class.php
Expand Up @@ -46,6 +46,7 @@ public static function createDatabase() {
if ($response["success"] == 1) {
return array(true, "");
} else {
print_r($response);
return array(false, "There was a problem creating the Core tables. Please report this problem.");
}
}
Expand Down Expand Up @@ -141,9 +142,10 @@ public static function createCoreTables() {
('installedDataTypes', ''),
('installedExportTypes', ''),
('installedCountries', ''),
('allowAnonymousAccess', ''),
('anonymousUserPermissionDeniedMsg', ''),
('theme', '$defaultTheme')
";

$queries[] = "
CREATE TABLE {$prefix}sessions (
session_id varchar(100) NOT NULL default '',
Expand Down
5 changes: 4 additions & 1 deletion resources/lang/en.php
Expand Up @@ -274,5 +274,8 @@
$L["feature_enabled"] = "Enabled";
$L["anonymous_access"] = "Anonymous access";
$L["anonymous_user_desc"] = "Anonymous users can use the script but have limited access: they cannot save, link to their data sets or generate more than 200 rows at a time.";
$L["anonymous_user_message"] = "Message to display to anonymous users when trying to save.";
$L["anonymous_user_message"] = "Message to display to anonymous users when trying to save:";
$L["anonymous_user_default_message"] = "Please email someone@yoursite.com to get a user account.";
$L["login_url_c"] = "Login URL:";
$L["email_c"] = "Email:";
$L["password_c"] = "Password:";
10 changes: 9 additions & 1 deletion resources/scripts/install.js
Expand Up @@ -70,7 +70,6 @@ require([
}

function _toggleAnonymousAccess(e) {
console.log(e, e.target);
if (e.target.checked) {
$("#anonymousUserPermissionDeniedMsg").removeClass("gdDisabled").removeAttr("disabled");
} else {
Expand Down Expand Up @@ -208,6 +207,8 @@ require([
var lastName = "";
var email = "";
var password = "";
var allowAnonymousAccess = "";
var anonymousUserPermissionDeniedMsg = "";

if (userAccountSetup == "single" || userAccountSetup == "multiple") {
firstName = $.trim($("#firstName").val());
Expand All @@ -226,6 +227,11 @@ require([
if (password === "") {
errors.push({ fieldId: "password", error: _L.validation_no_password });
}

if (userAccountSetup == "multiple") {
allowAnonymousAccess = $("#allowAnonymousAccess").attr("checked") ? "yes" : "no";
anonymousUserPermissionDeniedMsg = $("#anonymousUserPermissionDeniedMsg").val();
}
}

if (errors.length) {
Expand All @@ -248,6 +254,8 @@ require([
lastName: lastName,
email: email,
password: password,
allowAnonymousAccess: allowAnonymousAccess,
anonymousUserPermissionDeniedMsg: anonymousUserPermissionDeniedMsg,

// weird, because the field was on the first page
defaultLanguage: _defaultLanguage
Expand Down
7 changes: 3 additions & 4 deletions resources/templates/install.tab1.tpl
Expand Up @@ -89,9 +89,8 @@
</div>

<div class="gdFields">

<div class="gdCol" id="gdInstallAccountDetails" style="display:none">
<h4 id="gdInstallAccountDetailsMessage"></h4>
<h3 id="gdInstallAccountDetailsMessage"></h3>

<div class="gdError" id="firstName_error"></div>
<div class="gdError" id="lastName_error"></div>
Expand Down Expand Up @@ -124,9 +123,9 @@
<span class="rightBox">
<input type="checkbox" id="allowAnonymousAccess" /><label for="allowAnonymousAccess">{$L.feature_enabled}</label>
</span>
<h4>{$L.anonymous_access}</h4>
<h3>{$L.anonymous_access}</h3>
<div>{$L.anonymous_user_desc}</div>
<div>{$L.anonymous_user_message}</div>
<div><i>{$L.anonymous_user_message}</i></div>
<textarea id="anonymousUserPermissionDeniedMsg" name="anonymousUserPermissionDeniedMsg" class="gdDisabled"
disabled="disabled">{$L.anonymous_user_default_message}</textarea>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/themes/classic/compiled/general.css
Expand Up @@ -100,7 +100,7 @@ ul {
.gdFields .gdCol {
float: left;
width: 350px; }
.gdFields .gdCol h4 {
.gdFields .gdCol h3 {
margin-top: 0px; }
.gdFields .gdCol .rightBox {
float: right; }
Expand Down
2 changes: 1 addition & 1 deletion resources/themes/classic/compiled/styles.css
Expand Up @@ -100,7 +100,7 @@ ul {
.gdFields .gdCol {
float: left;
width: 350px; }
.gdFields .gdCol h4 {
.gdFields .gdCol h3 {
margin-top: 0px; }
.gdFields .gdCol .rightBox {
float: right; }
Expand Down
2 changes: 1 addition & 1 deletion resources/themes/classic/sass/general.scss
Expand Up @@ -109,7 +109,7 @@ ul {
.gdCol {
float: left;
width: 350px;
h4 {
h3 {
margin-top: 0px;
}
.rightBox {
Expand Down

0 comments on commit 86ef6fb

Please sign in to comment.