Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Merge Deconflict of /dev and /master #503

Merged
merged 2 commits into from May 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions database/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,15 @@ INSERT INTO `configuration` (field, value, description) VALUES("ldap_domain_suff
INSERT INTO `configuration` (field, value, description) VALUES("login", "1", "(Boolean) Ability to login");
INSERT INTO `configuration` (field, value, description) VALUES("login_select", "0", "(Boolean) Login selecting the team");
INSERT INTO `configuration` (field, value, description) VALUES("login_strongpasswords", "0", "(Boolean) Enforce using strong passwords");
INSERT INTO `configuration` (field, value, description) VALUES("password_type", "1", "(Integer) Type of passwords: See password_types");
INSERT INTO `configuration` (field, value, description) VALUES("password_type", "1", "(Integer) Type of passwords: See table password_types");
INSERT INTO `configuration` (field, value, description) VALUES("default_bonus", "30", "(Integer) Default value for bonus in levels");
INSERT INTO `configuration` (field, value, description) VALUES("default_bonusdec", "10", "(Integer) Default bonus decrement in levels");
INSERT INTO `configuration` (field, value, description) VALUES("language", "en", "(String) Language of the system");
INSERT INTO `configuration` (field, value, description) VALUES("livesync", "0", "(Boolean) LiveSync functionality");
INSERT INTO `configuration` (field, value, description) VALUES("livesync_auth_key", "", "(String) Optional LiveSync Auth Key");
INSERT INTO `configuration` (field, value, description) VALUES("custom_logo", "0", "(Boolean) Custom branding logo");
INSERT INTO `configuration` (field, value, description) VALUES("custom_text", "Powered By Facebook", "(String) Custom branding text");
INSERT INTO `configuration` (field, value, description) VALUES("custom_logo_image", "static/img/favicon.png", "(String) Custom logo image file");
UNLOCK TABLES;

--
Expand All @@ -243,17 +246,18 @@ DROP TABLE IF EXISTS `password_types`;
CREATE TABLE `password_types` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`field` varchar(100) NOT NULL,
`value` text NOT NULL,
`description` text NOT NULL,
`regex` text NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `field` (`field`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

LOCK TABLES `password_types` WRITE;
INSERT INTO `password_types` (field, regex, description) VALUES("1", "/.*^(?=.{8,})(?=.*[a-z])(?=.*[0-9]).*$/", "Length > 8, [a-z] and [0-9]");
INSERT INTO `password_types` (field, regex, description) VALUES("2", "/.*^(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).*$/", "Length > 8, [a-z], [A-Z] and [0-9]");
INSERT INTO `password_types` (field, regex, description) VALUES("3", "/.*^(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\W).*$/", "Length > 8, [a-z], [A-Z], [0-9] and Special chars");
INSERT INTO `password_types` (field, value, description) VALUES("1", "/.+/", "Length > 0");
INSERT INTO `password_types` (field, value, description) VALUES("2", "/.*^(?=.{8,})(?=.*[a-z])(?=.*[0-9]).*$/", "Length > 8, [a-z] and [0-9]");
INSERT INTO `password_types` (field, value, description) VALUES("3", "/.*^(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).*$/", "Length > 8, [a-z], [A-Z] and [0-9]");
INSERT INTO `password_types` (field, value, description) VALUES("4", "/.*^(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[\\W]+).*$/", "Length > 8, [a-z], [A-Z], [0-9] and Special chars");

UNLOCK TABLES;

Expand Down
17 changes: 9 additions & 8 deletions database/test_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ CREATE TABLE `teams` (
`active` tinyint(1) NOT NULL DEFAULT 1,
`name` text NOT NULL,
`password_hash` text NOT NULL,
`points` int(11) NOT NULL,
`points` int(11) NOT NULL DEFAULT 0,
`last_score` timestamp NOT NULL,
`logo` text NOT NULL,
`admin` tinyint(1) NOT NULL,
`protected` tinyint(1) NOT NULL,
`admin` tinyint(1) NOT NULL DEFAULT 0,
`protected` tinyint(1) NOT NULL DEFAULT 0,
`visible` tinyint(1) NOT NULL DEFAULT 1,
`created_ts` timestamp NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
Expand Down Expand Up @@ -225,7 +225,7 @@ INSERT INTO `configuration` (field, value, description) VALUES("ldap_domain_suff
INSERT INTO `configuration` (field, value, description) VALUES("login", "1", "(Boolean) Ability to login");
INSERT INTO `configuration` (field, value, description) VALUES("login_select", "0", "(Boolean) Login selecting the team");
INSERT INTO `configuration` (field, value, description) VALUES("login_strongpasswords", "0", "(Boolean) Enforce using strong passwords");
INSERT INTO `configuration` (field, value, description) VALUES("password_type", "1", "(Integer) Type of passwords: See password_types");
INSERT INTO `configuration` (field, value, description) VALUES("password_type", "1", "(Integer) Type of passwords: See table password_types");
INSERT INTO `configuration` (field, value, description) VALUES("default_bonus", "30", "(Integer) Default value for bonus in levels");
INSERT INTO `configuration` (field, value, description) VALUES("default_bonusdec", "10", "(Integer) Default bonus decrement in levels");
INSERT INTO `configuration` (field, value, description) VALUES("language", "en", "(String) Language of the system");
Expand All @@ -243,17 +243,18 @@ DROP TABLE IF EXISTS `password_types`;
CREATE TABLE `password_types` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`field` varchar(100) NOT NULL,
`value` text NOT NULL,
`description` text NOT NULL,
`regex` text NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `field` (`field`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

LOCK TABLES `password_types` WRITE;
INSERT INTO `password_types` (field, regex, description) VALUES("1", "/.*^(?=.{8,})(?=.*[a-z])(?=.*[0-9]).*$/", "Length > 8, [a-z] and [0-9]");
INSERT INTO `password_types` (field, regex, description) VALUES("2", "/.*^(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).*$/", "Length > 8, [a-z], [A-Z] and [0-9]");
INSERT INTO `password_types` (field, regex, description) VALUES("3", "/.*^(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\W).*$/", "Length > 8, [a-z], [A-Z], [0-9] and Special chars");
INSERT INTO `password_types` (field, value, description) VALUES("1", "/.+/", "Length > 0");
INSERT INTO `password_types` (field, value, description) VALUES("2", "/.*^(?=.{8,})(?=.*[a-z])(?=.*[0-9]).*$/", "Length > 8, [a-z] and [0-9]");
INSERT INTO `password_types` (field, value, description) VALUES("3", "/.*^(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).*$/", "Length > 8, [a-z], [A-Z] and [0-9]");
INSERT INTO `password_types` (field, value, description) VALUES("4", "/.*^(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[\\W]+).*$/", "Length > 8, [a-z], [A-Z], [0-9] and Special chars");

UNLOCK TABLES;

Expand Down
168 changes: 143 additions & 25 deletions src/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,25 @@ class="fb--conf--registration_type"
return $select;
}

// TODO: Translate password types
private async function genStrongPasswordsSelect(): Awaitable<:xhp> {
$types = await Configuration::genAllPasswordTypes();
$config = await Configuration::genCurrentPasswordType();
$select = <select name="fb--conf--password_type"></select>;
foreach ($types as $type) {
$select->appendChild(
<option
class="fb--conf--password_type"
value={strval($type->getField())}
selected={($type->getField() === $config->getField())}>
{$type->getDescription()}
</option>
);
}

return $select;
}

private async function genConfigurationDurationSelect(): Awaitable<:xhp> {
$config = await Configuration::gen('game_duration_unit');
$duration_unit = $config->getValue();
Expand Down Expand Up @@ -295,6 +314,9 @@ class="fb-cta cta--yellow"
'end_ts' => Configuration::gen('end_ts'),
'livesync' => Configuration::gen('livesync'),
'livesync_auth_key' => Configuration::gen('livesync_auth_key'),
'custom_logo' => Configuration::gen('custom_logo'),
'custom_text' => Configuration::gen('custom_text'),
'custom_logo_image' => Configuration::gen('custom_logo_image'),
};

$results = await \HH\Asio\m($awaitables);
Expand Down Expand Up @@ -322,6 +344,9 @@ class="fb-cta cta--yellow"
$end_ts = $results['end_ts'];
$livesync = $results['livesync'];
$livesync_auth_key = $results['livesync_auth_key'];
$custom_logo = $results['custom_logo'];
$custom_text = $results['custom_text'];
$custom_logo_image = $results['custom_logo_image'];

$registration_on = $registration->getValue() === '1';
$registration_off = $registration->getValue() === '0';
Expand All @@ -343,6 +368,8 @@ class="fb-cta cta--yellow"
$timer_off = $timer->getValue() === '0';
$livesync_on = $livesync->getValue() === '1';
$livesync_off = $livesync->getValue() === '0';
$custom_logo_on = $custom_logo->getValue() === '1';
$custom_logo_off = $custom_logo->getValue() === '0';

$game_start_array = array();
if ($start_ts->getValue() !== '0' && $start_ts->getValue() !== 'NaN') {
Expand Down Expand Up @@ -416,13 +443,52 @@ class="fb-cta cta--yellow"
'configuration_duration_select' =>
$this->genConfigurationDurationSelect(),
'language_select' => $this->genLanguageSelect(),
'password_types_select' => $this->genStrongPasswordsSelect(),
};
$results = await \HH\Asio\m($awaitables);

$registration_type_select = $results['registration_type_select'];
$configuration_duration_select =
$results['configuration_duration_select'];
$language_select = $results['language_select'];
$password_types_select = $results['password_types_select'];

if ($login_strongpasswords->getValue() === '0') { // Strong passwords are not enforced
$strong_passwords = <div></div>;
} else {
$strong_passwords =
<div class="form-el el--block-label">
<label>{tr('Password Types')}</label>
{$password_types_select}
</div>;
}

if ($custom_logo->getValue() === '0') { // Custom branding is not enabled
$custom_logo_xhp = <div></div>;
} else {
$custom_logo_xhp =
<div class="form-el el--block-label el--full-text">
<label for="">{tr('Logo')}</label>
<img
id="custom-logo-image"
class="icon--badge"
src={$custom_logo_image->getValue()}
/>
<br/>
<h6>
<a class="icon-text" href="#" id="custom-logo-link">
{tr('Change')}
</a>
</h6>
<input
autocomplete="off"
name="custom-logo-input"
id="custom-logo-input"
type="file"
accept="image/*"
/>
</div>;
}

return
<div>
Expand Down Expand Up @@ -527,56 +593,59 @@ class="fb-cta cta--yellow"
</div>
</header>
<div class="fb-column-container">
<div class="col col-pad col-1-2">
<div class="col col-pad col-1-3">
<div class="form-el el--block-label">
<label>{tr('Strong Passwords')}</label>
<label>{tr('Team Selection')}</label>
<div class="admin-section-toggle radio-inline">
<input
type="radio"
name="fb--conf--login_strongpasswords"
id="fb--conf--login_strongpasswords--on"
checked={$strong_passwords_on}
name="fb--conf--login_select"
id="fb--conf--login_select--on"
checked={$login_select_on}
/>
<label for="fb--conf--login_strongpasswords--on">
<label for="fb--conf--login_select--on">
{tr('On')}
</label>
<input
type="radio"
name="fb--conf--login_strongpasswords"
id="fb--conf--login_strongpasswords--off"
checked={$strong_passwords_off}
name="fb--conf--login_select"
id="fb--conf--login_select--off"
checked={$login_select_off}
/>
<label for="fb--conf--login_strongpasswords--off">
<label for="fb--conf--login_select--off">
{tr('Off')}
</label>
</div>
</div>
</div>
<div class="col col-pad col-2-2">
<div class="col col-pad col-1-3">
<div class="form-el el--block-label">
<label>{tr('Team Selection')}</label>
<label>{tr('Strong Passwords')}</label>
<div class="admin-section-toggle radio-inline">
<input
type="radio"
name="fb--conf--login_select"
id="fb--conf--login_select--on"
checked={$login_select_on}
name="fb--conf--login_strongpasswords"
id="fb--conf--login_strongpasswords--on"
checked={$strong_passwords_on}
/>
<label for="fb--conf--login_select--on">
<label for="fb--conf--login_strongpasswords--on">
{tr('On')}
</label>
<input
type="radio"
name="fb--conf--login_select"
id="fb--conf--login_select--off"
checked={$login_select_off}
name="fb--conf--login_strongpasswords"
id="fb--conf--login_strongpasswords--off"
checked={$strong_passwords_off}
/>
<label for="fb--conf--login_select--off">
<label for="fb--conf--login_strongpasswords--off">
{tr('Off')}
</label>
</div>
</div>
</div>
<div class="col col-pad col-2-3">
{$strong_passwords}
</div>
</div>
</section>
<section class="admin-box">
Expand Down Expand Up @@ -932,11 +1001,59 @@ class="fb-cta cta--yellow"
</section>
<section class="admin-box">
<header class="admin-box-header">
<h3>{tr('Language')}</h3>
<h3>{tr('Internationalization')}</h3>
</header>
<div class="fb-column-container">
<div class="col col-pad col-2-4">
<div class="form-el el--block-label">
<label for="">{tr('Language')}</label>
{$language_select}
</div>
</div>
</div>
</section>
<section class="admin-box">
<header class="admin-box-header">
<h3>{tr('Branding')}</h3>
</header>
<div class="col col-pad col-1-2">
<div class="form-el el--block-label el--full-text">
{$language_select}
<div class="fb-column-container">
<div class="col col-pad col-1-3">
<div class="form-el el--block-label">
<label>{tr('Custom Logo')}</label>
<div class="admin-section-toggle radio-inline">
<input
type="radio"
name="fb--conf--custom_logo"
id="fb--conf--custom_logo--on"
checked={$custom_logo_on}
/>
<label for="fb--conf--custom_logo--on">
{tr('On')}
</label>
<input
type="radio"
name="fb--conf--custom_logo"
id="fb--conf--custom_logo--off"
checked={$custom_logo_off}
/>
<label for="fb--conf--custom_logo--off">
{tr('Off')}
</label>
</div>
</div>
</div>
<div class="col col-pad col-1-3">
{$custom_logo_xhp}
</div>
<div class="col col-pad col-1-3">
<div class="form-el el--block-label el--full-text">
<label for="">{tr('Custom Text')}</label>
<input
type="text"
name="fb--conf--custom_text"
value={$custom_text->getValue()}
/>
</div>
</div>
</div>
</section>
Expand Down Expand Up @@ -3786,6 +3903,7 @@ public function renderMainContent(): :xhp {
{tr('Begin Game')}
</a>;
}
$branding_xhp = await $this->genRenderBranding();
return
<div id="fb-admin-nav" class="admin-nav-bar fb-row-container">
<header class="admin-nav-header row-fixed">
Expand Down Expand Up @@ -3858,7 +3976,7 @@ public function renderMainContent(): :xhp {
<a href="/index.php?p=game">{tr('Gameboard')}</a>
<a href="" class="js-prompt-logout">{tr('Logout')}</a>
<a></a>
<fbbranding />
{$branding_xhp}
</div>
</div>;
}
Expand Down
25 changes: 25 additions & 0 deletions src/controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ abstract protected function getPages(): array<string>;

abstract protected function genRenderBody(string $page): Awaitable<:xhp>;

public async function genRenderBranding(): Awaitable<:xhp> {
$awaitables = Map {
'custom_logo' => Configuration::gen('custom_logo'),
'custom_text' => Configuration::gen('custom_text'),
'custom_logo_image' => Configuration::gen('custom_logo_image'),
};
$results = await \HH\Asio\m($awaitables);
$branding = $results['custom_logo'];
$custom_text = $results['custom_text'];
if ($branding->getValue() === '0') {
$branding_xhp =
<fbbranding
brandingText={tr(strval($custom_text->getValue()))}
/>;
} else {
$custom_logo_image = $results['custom_logo_image'];
$branding_xhp =
<custombranding
brandingText={strval($custom_text->getValue())}
brandingLogo={strval($custom_logo_image->getValue())}
/>;
}
return $branding_xhp;
}

public async function genRender(): Awaitable<:xhp> {
$page = $this->processRequest();
$body = await $this->genRenderBody($page);
Expand Down
Loading