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

Commit 51e06a7

Browse files
justinwraygsingh93
authored andcommitted
Merge Deconflict of /dev and /master (#503)
* Registration enforcing strong passwords (#442) * Password types in admin * Fully functional password complexity enforcement for registration * lowercase word in text * Adding test for password types regex and fixing all errors for hh_client * Updating outdated schema for tests * Custom branding for icon and text (#448) * Custom branding for icon and text * Replace async calls branding xhp by attributes * Use genRenderBranding in genRenderMobilePage and combine awaitables
1 parent dd3c874 commit 51e06a7

21 files changed

+421
-76
lines changed

database/schema.sql

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,15 @@ INSERT INTO `configuration` (field, value, description) VALUES("ldap_domain_suff
225225
INSERT INTO `configuration` (field, value, description) VALUES("login", "1", "(Boolean) Ability to login");
226226
INSERT INTO `configuration` (field, value, description) VALUES("login_select", "0", "(Boolean) Login selecting the team");
227227
INSERT INTO `configuration` (field, value, description) VALUES("login_strongpasswords", "0", "(Boolean) Enforce using strong passwords");
228-
INSERT INTO `configuration` (field, value, description) VALUES("password_type", "1", "(Integer) Type of passwords: See password_types");
228+
INSERT INTO `configuration` (field, value, description) VALUES("password_type", "1", "(Integer) Type of passwords: See table password_types");
229229
INSERT INTO `configuration` (field, value, description) VALUES("default_bonus", "30", "(Integer) Default value for bonus in levels");
230230
INSERT INTO `configuration` (field, value, description) VALUES("default_bonusdec", "10", "(Integer) Default bonus decrement in levels");
231231
INSERT INTO `configuration` (field, value, description) VALUES("language", "en", "(String) Language of the system");
232232
INSERT INTO `configuration` (field, value, description) VALUES("livesync", "0", "(Boolean) LiveSync functionality");
233233
INSERT INTO `configuration` (field, value, description) VALUES("livesync_auth_key", "", "(String) Optional LiveSync Auth Key");
234+
INSERT INTO `configuration` (field, value, description) VALUES("custom_logo", "0", "(Boolean) Custom branding logo");
235+
INSERT INTO `configuration` (field, value, description) VALUES("custom_text", "Powered By Facebook", "(String) Custom branding text");
236+
INSERT INTO `configuration` (field, value, description) VALUES("custom_logo_image", "static/img/favicon.png", "(String) Custom logo image file");
234237
UNLOCK TABLES;
235238

236239
--
@@ -243,17 +246,18 @@ DROP TABLE IF EXISTS `password_types`;
243246
CREATE TABLE `password_types` (
244247
`id` int(11) NOT NULL AUTO_INCREMENT,
245248
`field` varchar(100) NOT NULL,
249+
`value` text NOT NULL,
246250
`description` text NOT NULL,
247-
`regex` text NOT NULL,
248251
PRIMARY KEY (`id`),
249252
UNIQUE KEY `field` (`field`)
250253
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
251254
/*!40101 SET character_set_client = @saved_cs_client */;
252255

253256
LOCK TABLES `password_types` WRITE;
254-
INSERT INTO `password_types` (field, regex, description) VALUES("1", "/.*^(?=.{8,})(?=.*[a-z])(?=.*[0-9]).*$/", "Length > 8, [a-z] and [0-9]");
255-
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]");
256-
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");
257+
INSERT INTO `password_types` (field, value, description) VALUES("1", "/.+/", "Length > 0");
258+
INSERT INTO `password_types` (field, value, description) VALUES("2", "/.*^(?=.{8,})(?=.*[a-z])(?=.*[0-9]).*$/", "Length > 8, [a-z] and [0-9]");
259+
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]");
260+
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");
257261

258262
UNLOCK TABLES;
259263

database/test_schema.sql

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ CREATE TABLE `teams` (
118118
`active` tinyint(1) NOT NULL DEFAULT 1,
119119
`name` text NOT NULL,
120120
`password_hash` text NOT NULL,
121-
`points` int(11) NOT NULL,
121+
`points` int(11) NOT NULL DEFAULT 0,
122122
`last_score` timestamp NOT NULL,
123123
`logo` text NOT NULL,
124-
`admin` tinyint(1) NOT NULL,
125-
`protected` tinyint(1) NOT NULL,
124+
`admin` tinyint(1) NOT NULL DEFAULT 0,
125+
`protected` tinyint(1) NOT NULL DEFAULT 0,
126126
`visible` tinyint(1) NOT NULL DEFAULT 1,
127127
`created_ts` timestamp NOT NULL DEFAULT 0,
128128
PRIMARY KEY (`id`)
@@ -225,7 +225,7 @@ INSERT INTO `configuration` (field, value, description) VALUES("ldap_domain_suff
225225
INSERT INTO `configuration` (field, value, description) VALUES("login", "1", "(Boolean) Ability to login");
226226
INSERT INTO `configuration` (field, value, description) VALUES("login_select", "0", "(Boolean) Login selecting the team");
227227
INSERT INTO `configuration` (field, value, description) VALUES("login_strongpasswords", "0", "(Boolean) Enforce using strong passwords");
228-
INSERT INTO `configuration` (field, value, description) VALUES("password_type", "1", "(Integer) Type of passwords: See password_types");
228+
INSERT INTO `configuration` (field, value, description) VALUES("password_type", "1", "(Integer) Type of passwords: See table password_types");
229229
INSERT INTO `configuration` (field, value, description) VALUES("default_bonus", "30", "(Integer) Default value for bonus in levels");
230230
INSERT INTO `configuration` (field, value, description) VALUES("default_bonusdec", "10", "(Integer) Default bonus decrement in levels");
231231
INSERT INTO `configuration` (field, value, description) VALUES("language", "en", "(String) Language of the system");
@@ -243,17 +243,18 @@ DROP TABLE IF EXISTS `password_types`;
243243
CREATE TABLE `password_types` (
244244
`id` int(11) NOT NULL AUTO_INCREMENT,
245245
`field` varchar(100) NOT NULL,
246+
`value` text NOT NULL,
246247
`description` text NOT NULL,
247-
`regex` text NOT NULL,
248248
PRIMARY KEY (`id`),
249249
UNIQUE KEY `field` (`field`)
250250
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
251251
/*!40101 SET character_set_client = @saved_cs_client */;
252252

253253
LOCK TABLES `password_types` WRITE;
254-
INSERT INTO `password_types` (field, regex, description) VALUES("1", "/.*^(?=.{8,})(?=.*[a-z])(?=.*[0-9]).*$/", "Length > 8, [a-z] and [0-9]");
255-
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]");
256-
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");
254+
INSERT INTO `password_types` (field, value, description) VALUES("1", "/.+/", "Length > 0");
255+
INSERT INTO `password_types` (field, value, description) VALUES("2", "/.*^(?=.{8,})(?=.*[a-z])(?=.*[0-9]).*$/", "Length > 8, [a-z] and [0-9]");
256+
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]");
257+
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");
257258

258259
UNLOCK TABLES;
259260

src/controllers/AdminController.php

Lines changed: 143 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,25 @@ class="fb--conf--registration_type"
149149
return $select;
150150
}
151151

152+
// TODO: Translate password types
153+
private async function genStrongPasswordsSelect(): Awaitable<:xhp> {
154+
$types = await Configuration::genAllPasswordTypes();
155+
$config = await Configuration::genCurrentPasswordType();
156+
$select = <select name="fb--conf--password_type"></select>;
157+
foreach ($types as $type) {
158+
$select->appendChild(
159+
<option
160+
class="fb--conf--password_type"
161+
value={strval($type->getField())}
162+
selected={($type->getField() === $config->getField())}>
163+
{$type->getDescription()}
164+
</option>
165+
);
166+
}
167+
168+
return $select;
169+
}
170+
152171
private async function genConfigurationDurationSelect(): Awaitable<:xhp> {
153172
$config = await Configuration::gen('game_duration_unit');
154173
$duration_unit = $config->getValue();
@@ -295,6 +314,9 @@ class="fb-cta cta--yellow"
295314
'end_ts' => Configuration::gen('end_ts'),
296315
'livesync' => Configuration::gen('livesync'),
297316
'livesync_auth_key' => Configuration::gen('livesync_auth_key'),
317+
'custom_logo' => Configuration::gen('custom_logo'),
318+
'custom_text' => Configuration::gen('custom_text'),
319+
'custom_logo_image' => Configuration::gen('custom_logo_image'),
298320
};
299321

300322
$results = await \HH\Asio\m($awaitables);
@@ -322,6 +344,9 @@ class="fb-cta cta--yellow"
322344
$end_ts = $results['end_ts'];
323345
$livesync = $results['livesync'];
324346
$livesync_auth_key = $results['livesync_auth_key'];
347+
$custom_logo = $results['custom_logo'];
348+
$custom_text = $results['custom_text'];
349+
$custom_logo_image = $results['custom_logo_image'];
325350

326351
$registration_on = $registration->getValue() === '1';
327352
$registration_off = $registration->getValue() === '0';
@@ -343,6 +368,8 @@ class="fb-cta cta--yellow"
343368
$timer_off = $timer->getValue() === '0';
344369
$livesync_on = $livesync->getValue() === '1';
345370
$livesync_off = $livesync->getValue() === '0';
371+
$custom_logo_on = $custom_logo->getValue() === '1';
372+
$custom_logo_off = $custom_logo->getValue() === '0';
346373

347374
$game_start_array = array();
348375
if ($start_ts->getValue() !== '0' && $start_ts->getValue() !== 'NaN') {
@@ -416,13 +443,52 @@ class="fb-cta cta--yellow"
416443
'configuration_duration_select' =>
417444
$this->genConfigurationDurationSelect(),
418445
'language_select' => $this->genLanguageSelect(),
446+
'password_types_select' => $this->genStrongPasswordsSelect(),
419447
};
420448
$results = await \HH\Asio\m($awaitables);
421449

422450
$registration_type_select = $results['registration_type_select'];
423451
$configuration_duration_select =
424452
$results['configuration_duration_select'];
425453
$language_select = $results['language_select'];
454+
$password_types_select = $results['password_types_select'];
455+
456+
if ($login_strongpasswords->getValue() === '0') { // Strong passwords are not enforced
457+
$strong_passwords = <div></div>;
458+
} else {
459+
$strong_passwords =
460+
<div class="form-el el--block-label">
461+
<label>{tr('Password Types')}</label>
462+
{$password_types_select}
463+
</div>;
464+
}
465+
466+
if ($custom_logo->getValue() === '0') { // Custom branding is not enabled
467+
$custom_logo_xhp = <div></div>;
468+
} else {
469+
$custom_logo_xhp =
470+
<div class="form-el el--block-label el--full-text">
471+
<label for="">{tr('Logo')}</label>
472+
<img
473+
id="custom-logo-image"
474+
class="icon--badge"
475+
src={$custom_logo_image->getValue()}
476+
/>
477+
<br/>
478+
<h6>
479+
<a class="icon-text" href="#" id="custom-logo-link">
480+
{tr('Change')}
481+
</a>
482+
</h6>
483+
<input
484+
autocomplete="off"
485+
name="custom-logo-input"
486+
id="custom-logo-input"
487+
type="file"
488+
accept="image/*"
489+
/>
490+
</div>;
491+
}
426492

427493
return
428494
<div>
@@ -527,56 +593,59 @@ class="fb-cta cta--yellow"
527593
</div>
528594
</header>
529595
<div class="fb-column-container">
530-
<div class="col col-pad col-1-2">
596+
<div class="col col-pad col-1-3">
531597
<div class="form-el el--block-label">
532-
<label>{tr('Strong Passwords')}</label>
598+
<label>{tr('Team Selection')}</label>
533599
<div class="admin-section-toggle radio-inline">
534600
<input
535601
type="radio"
536-
name="fb--conf--login_strongpasswords"
537-
id="fb--conf--login_strongpasswords--on"
538-
checked={$strong_passwords_on}
602+
name="fb--conf--login_select"
603+
id="fb--conf--login_select--on"
604+
checked={$login_select_on}
539605
/>
540-
<label for="fb--conf--login_strongpasswords--on">
606+
<label for="fb--conf--login_select--on">
541607
{tr('On')}
542608
</label>
543609
<input
544610
type="radio"
545-
name="fb--conf--login_strongpasswords"
546-
id="fb--conf--login_strongpasswords--off"
547-
checked={$strong_passwords_off}
611+
name="fb--conf--login_select"
612+
id="fb--conf--login_select--off"
613+
checked={$login_select_off}
548614
/>
549-
<label for="fb--conf--login_strongpasswords--off">
615+
<label for="fb--conf--login_select--off">
550616
{tr('Off')}
551617
</label>
552618
</div>
553619
</div>
554620
</div>
555-
<div class="col col-pad col-2-2">
621+
<div class="col col-pad col-1-3">
556622
<div class="form-el el--block-label">
557-
<label>{tr('Team Selection')}</label>
623+
<label>{tr('Strong Passwords')}</label>
558624
<div class="admin-section-toggle radio-inline">
559625
<input
560626
type="radio"
561-
name="fb--conf--login_select"
562-
id="fb--conf--login_select--on"
563-
checked={$login_select_on}
627+
name="fb--conf--login_strongpasswords"
628+
id="fb--conf--login_strongpasswords--on"
629+
checked={$strong_passwords_on}
564630
/>
565-
<label for="fb--conf--login_select--on">
631+
<label for="fb--conf--login_strongpasswords--on">
566632
{tr('On')}
567633
</label>
568634
<input
569635
type="radio"
570-
name="fb--conf--login_select"
571-
id="fb--conf--login_select--off"
572-
checked={$login_select_off}
636+
name="fb--conf--login_strongpasswords"
637+
id="fb--conf--login_strongpasswords--off"
638+
checked={$strong_passwords_off}
573639
/>
574-
<label for="fb--conf--login_select--off">
640+
<label for="fb--conf--login_strongpasswords--off">
575641
{tr('Off')}
576642
</label>
577643
</div>
578644
</div>
579645
</div>
646+
<div class="col col-pad col-2-3">
647+
{$strong_passwords}
648+
</div>
580649
</div>
581650
</section>
582651
<section class="admin-box">
@@ -932,11 +1001,59 @@ class="fb-cta cta--yellow"
9321001
</section>
9331002
<section class="admin-box">
9341003
<header class="admin-box-header">
935-
<h3>{tr('Language')}</h3>
1004+
<h3>{tr('Internationalization')}</h3>
1005+
</header>
1006+
<div class="fb-column-container">
1007+
<div class="col col-pad col-2-4">
1008+
<div class="form-el el--block-label">
1009+
<label for="">{tr('Language')}</label>
1010+
{$language_select}
1011+
</div>
1012+
</div>
1013+
</div>
1014+
</section>
1015+
<section class="admin-box">
1016+
<header class="admin-box-header">
1017+
<h3>{tr('Branding')}</h3>
9361018
</header>
937-
<div class="col col-pad col-1-2">
938-
<div class="form-el el--block-label el--full-text">
939-
{$language_select}
1019+
<div class="fb-column-container">
1020+
<div class="col col-pad col-1-3">
1021+
<div class="form-el el--block-label">
1022+
<label>{tr('Custom Logo')}</label>
1023+
<div class="admin-section-toggle radio-inline">
1024+
<input
1025+
type="radio"
1026+
name="fb--conf--custom_logo"
1027+
id="fb--conf--custom_logo--on"
1028+
checked={$custom_logo_on}
1029+
/>
1030+
<label for="fb--conf--custom_logo--on">
1031+
{tr('On')}
1032+
</label>
1033+
<input
1034+
type="radio"
1035+
name="fb--conf--custom_logo"
1036+
id="fb--conf--custom_logo--off"
1037+
checked={$custom_logo_off}
1038+
/>
1039+
<label for="fb--conf--custom_logo--off">
1040+
{tr('Off')}
1041+
</label>
1042+
</div>
1043+
</div>
1044+
</div>
1045+
<div class="col col-pad col-1-3">
1046+
{$custom_logo_xhp}
1047+
</div>
1048+
<div class="col col-pad col-1-3">
1049+
<div class="form-el el--block-label el--full-text">
1050+
<label for="">{tr('Custom Text')}</label>
1051+
<input
1052+
type="text"
1053+
name="fb--conf--custom_text"
1054+
value={$custom_text->getValue()}
1055+
/>
1056+
</div>
9401057
</div>
9411058
</div>
9421059
</section>
@@ -3786,6 +3903,7 @@ public function renderMainContent(): :xhp {
37863903
{tr('Begin Game')}
37873904
</a>;
37883905
}
3906+
$branding_xhp = await $this->genRenderBranding();
37893907
return
37903908
<div id="fb-admin-nav" class="admin-nav-bar fb-row-container">
37913909
<header class="admin-nav-header row-fixed">
@@ -3858,7 +3976,7 @@ public function renderMainContent(): :xhp {
38583976
<a href="/index.php?p=game">{tr('Gameboard')}</a>
38593977
<a href="" class="js-prompt-logout">{tr('Logout')}</a>
38603978
<a></a>
3861-
<fbbranding />
3979+
{$branding_xhp}
38623980
</div>
38633981
</div>;
38643982
}

src/controllers/Controller.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@ abstract protected function getPages(): array<string>;
77

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

10+
public async function genRenderBranding(): Awaitable<:xhp> {
11+
$awaitables = Map {
12+
'custom_logo' => Configuration::gen('custom_logo'),
13+
'custom_text' => Configuration::gen('custom_text'),
14+
'custom_logo_image' => Configuration::gen('custom_logo_image'),
15+
};
16+
$results = await \HH\Asio\m($awaitables);
17+
$branding = $results['custom_logo'];
18+
$custom_text = $results['custom_text'];
19+
if ($branding->getValue() === '0') {
20+
$branding_xhp =
21+
<fbbranding
22+
brandingText={tr(strval($custom_text->getValue()))}
23+
/>;
24+
} else {
25+
$custom_logo_image = $results['custom_logo_image'];
26+
$branding_xhp =
27+
<custombranding
28+
brandingText={strval($custom_text->getValue())}
29+
brandingLogo={strval($custom_logo_image->getValue())}
30+
/>;
31+
}
32+
return $branding_xhp;
33+
}
34+
1035
public async function genRender(): Awaitable<:xhp> {
1136
$page = $this->processRequest();
1237
$body = await $this->genRenderBody($page);

0 commit comments

Comments
 (0)