Merge branch 'dev' into nomadic

This commit is contained in:
Mike Macgirvin 2024-06-15 14:28:12 +10:00
commit 12fdab2b00
18 changed files with 1434 additions and 1356 deletions

View file

@ -65,7 +65,7 @@ App::$config['system']['ssl_cookie_protection'] = 1;
// In order to perform system administration via the admin panel, admin_email // In order to perform system administration via the admin panel, admin_email
// must precisely match the email address of the person logged in. // must precisely match the email address of the person logged in.
App::$config['system']['register_policy'] = REGISTER_OPEN; App::$config['system']['register_policy'] = REGISTER_APPROVE;
App::$config['system']['register_text'] = ''; App::$config['system']['register_text'] = '';
App::$config['system']['admin_email'] = ''; App::$config['system']['admin_email'] = '';

48
src/Lib/DataUrl.php Normal file
View file

@ -0,0 +1,48 @@
<?php
namespace Code\Lib;
class DataUrl
{
protected $data = null;
protected $mediaType = null;
protected $encoding = null;
public function __construct($data, $mediaType = '', $encoding = '')
{
$this->data = $data;
$this->mediaType = $mediaType;
$this->encoding = $encoding;
return $this;
}
public function encode()
{
return 'data:' . $this->mediaType . (($this->encoding) ? ';' . $this->encoding : '') . ','
. (($this->encoding) ? base64_encode($this->data) : urlencode($this->data));
}
public function decode()
{
if (str_starts_with($this->data, 'data:')) {
$explode = explode(',', $this->data);
if (count($explode) === 2) {
$this->mediaType = substr($explode[0], strlen('data:'));
if (str_ends_with($this->mediaType, ';base64')) {
$this->encoding = 'base64';
$this->mediaType = substr($this->mediaType, 0, strlen($this->mediaType) - strlen(';base64'));
} else {
$this->encoding = '';
}
return [
'data' => $this->encoding ? base64_decode($this->data) : urldecode($this->data),
'encoding' => $this->encoding,
'mediaType' => $this->mediaType ?: 'text/plain;charset=US-ASCII',
];
}
}
return null;
}
}

View file

@ -85,6 +85,20 @@ class Register extends Controller
$email_verify = get_config('system', 'verify_email'); $email_verify = get_config('system', 'verify_email');
// If this is the first account to be created, the login email must match the
// admin email. Other attempts will be rejected. If it is the admin email, bypass
// some restrictive policies.
$totalAccounts = Account::account_total();
if ($totalAccounts === 0) {
if (Account::check_admin($_POST)) {
$policy = REGISTER_OPEN;
$email_verify = false;
} else {
notice(t('The first account <strong>must</strong> be registered using the admin email which was supplied during setup.') . EOL);
return;
}
}
switch ($policy) { switch ($policy) {
case REGISTER_OPEN: case REGISTER_OPEN:
@ -125,8 +139,10 @@ class Register extends Controller
return; return;
} }
require_once('include/security.php'); // At this point the account has been created without error. Purge any error messages from prior failed
// registration attempts which haven't yet been delivered to the browser and start fresh.
$_SESSION['sysmsg'] = [];
if ($_REQUEST['name']) { if ($_REQUEST['name']) {
set_aconfig($result['account']['account_id'], 'register', 'channel_name', $_REQUEST['name']); set_aconfig($result['account']['account_id'], 'register', 'channel_name', $_REQUEST['name']);
@ -141,12 +157,6 @@ class Register extends Controller
set_aconfig($result['account']['account_id'], 'register', 'reason', substr(trim(escape_tags($_REQUEST['reason'])),0, 500)); set_aconfig($result['account']['account_id'], 'register', 'reason', substr(trim(escape_tags($_REQUEST['reason'])),0, 500));
} }
// At this point the account has been created without error. Purge any error messages from prior failed registration
// attempts which haven't yet been delivered to the browser and start fresh. If you're willing to figure out why they
// weren't delivered to the browser please adopt zap issue 34.
$_SESSION['sysmsg'] = [];
$using_invites = intval(get_config('system', 'invitation_only')); $using_invites = intval(get_config('system', 'invitation_only'));
$num_invites = intval(get_config('system', 'number_invites')); $num_invites = intval(get_config('system', 'number_invites'));
$invite_code = ((x($_POST, 'invite_code')) ? notags(trim($_POST['invite_code'])) : ''); $invite_code = ((x($_POST, 'invite_code')) ? notags(trim($_POST['invite_code'])) : '');
@ -164,7 +174,7 @@ class Register extends Controller
$res = Account::send_register_success_email($result['email'], $result['password']); $res = Account::send_register_success_email($result['email'], $result['password']);
} }
if ($res) { if ($res) {
if ($invite_code) { if ($invite_code || !$email_verify) {
info(t('Registration successful. Continue to create your first channel...') . EOL); info(t('Registration successful. Continue to create your first channel...') . EOL);
} else { } else {
info(t('Registration successful. Please check your email for validation instructions.') . EOL); info(t('Registration successful. Please check your email for validation instructions.') . EOL);
@ -215,13 +225,21 @@ class Register extends Controller
public function get() public function get()
{ {
$registration_is = EMPTY_STR; $registration_is = EMPTY_STR;
$other_sites = false; $other_sites = false;
$policy = (int)Config::Get('system','register_policy'); $policy = (int)Config::Get('system','register_policy');
$email_verify = get_config('system', 'verify_email');
if ($policy === REGISTER_CLOSED) { $totalAccounts = Account::account_total();
if($totalAccounts === 0) {
$policy = REGISTER_OPEN;
$email_verify = false;
info( t('Please use the admin email address supplied during setup.') . EOL);
}
if ($policy === REGISTER_CLOSED && !is_site_admin()) {
notice(t('Registration on this website is disabled.') . EOL); notice(t('Registration on this website is disabled.') . EOL);
$registration_is = t('Registration on this website is disabled.');
$other_sites = true; $other_sites = true;
} }
@ -298,8 +316,6 @@ class Register extends Controller
$auto_create = (bool)get_config('system', 'auto_channel_create'); $auto_create = (bool)get_config('system', 'auto_channel_create');
$default_role = get_config('system', 'default_permissions_role', 'social_restricted'); $default_role = get_config('system', 'default_permissions_role', 'social_restricted');
$email_verify = get_config('system', 'verify_email');
$o = replace_macros(Theme::get_template('register.tpl'), [ $o = replace_macros(Theme::get_template('register.tpl'), [
'$form_security_token' => get_form_security_token("register"), '$form_security_token' => get_form_security_token("register"),
@ -321,6 +337,7 @@ class Register extends Controller
'$pass1' => $password, '$pass1' => $password,
'$pass2' => $password2, '$pass2' => $password2,
'$reason' => $reason, '$reason' => $reason,
'$disabled' => $policy === REGISTER_CLOSED && !is_site_admin(),
'$submit' => t('Register'), '$submit' => t('Register'),
'$verify_note' => (($email_verify) ? t('This site requires email verification. After completing this form, please check your email for further instructions.') : ''), '$verify_note' => (($email_verify) ? t('This site requires email verification. After completing this form, please check your email for further instructions.') : ''),
]); ]);

View file

@ -47,7 +47,7 @@ if($argc > 1 && $argv[1] === 'list') {
if($argc > 2 && $argv[1] === 'add' && intval($argv[2])) { if($argc > 2 && $argv[1] === 'add' && intval($argv[2])) {
$r = q('update account set account_roles = (account_roles | 4096) where account_id = %d', $r = q('update account set account_roles = 4096, account_flags = 0 where account_id = %d',
intval($argv[2]) intval($argv[2])
); );
} }

File diff suppressed because it is too large Load diff

View file

@ -1,2 +1,2 @@
<?php <?php
define ('STD_VERSION', '24.06.10'); define ('STD_VERSION', '24.06.14');

View file

@ -50,7 +50,7 @@ App::$config['system']['ssl_cookie_protection'] = 1;
// to the email address of an already registered person who can authorise // to the email address of an already registered person who can authorise
// and/or approve/deny the request. // and/or approve/deny the request.
App::$config['system']['register_policy'] = REGISTER_OPEN; App::$config['system']['register_policy'] = REGISTER_APPROVE;
App::$config['system']['register_text'] = ''; App::$config['system']['register_text'] = '';
App::$config['system']['admin_email'] = '{{$adminmail}}'; App::$config['system']['admin_email'] = '{{$adminmail}}';

View file

@ -51,7 +51,7 @@ App::$config['system']['ssl_cookie_protection'] = 1;
// to the email address of an already registered person who can authorise // to the email address of an already registered person who can authorise
// and/or approve/deny the request. // and/or approve/deny the request.
App::$config['system']['register_policy'] = REGISTER_OPEN; App::$config['system']['register_policy'] = REGISTER_APPROVE;
App::$config['system']['register_text'] = ''; App::$config['system']['register_text'] = '';
App::$config['system']['admin_email'] = '{{$adminmail}}'; App::$config['system']['admin_email'] = '{{$adminmail}}';

View file

@ -51,7 +51,7 @@ App::$config['system']['ssl_cookie_protection'] = 1;
// to the email address of an already registered person who can authorise // to the email address of an already registered person who can authorise
// and/or approve/deny the request. // and/or approve/deny the request.
App::$config['system']['register_policy'] = REGISTER_OPEN; App::$config['system']['register_policy'] = REGISTER_APPROVE;
App::$config['system']['register_text'] = ''; App::$config['system']['register_text'] = '';
App::$config['system']['admin_email'] = '{{$adminmail}}'; App::$config['system']['admin_email'] = '{{$adminmail}}';

View file

@ -51,7 +51,7 @@ App::$config['system']['ssl_cookie_protection'] = 1;
// to the email address of an already registered person who can authorise // to the email address of an already registered person who can authorise
// and/or approve/deny the request. // and/or approve/deny the request.
App::$config['system']['register_policy'] = REGISTER_OPEN; App::$config['system']['register_policy'] = REGISTER_APPROVE;
App::$config['system']['register_text'] = ''; App::$config['system']['register_text'] = '';
App::$config['system']['admin_email'] = '{{$adminmail}}'; App::$config['system']['admin_email'] = '{{$adminmail}}';

View file

@ -50,7 +50,7 @@ App::$config['system']['ssl_cookie_protection'] = 1;
// to the email address of an already registered person who can authorise // to the email address of an already registered person who can authorise
// and/or approve/deny the request. // and/or approve/deny the request.
App::$config['system']['register_policy'] = REGISTER_OPEN; App::$config['system']['register_policy'] = REGISTER_APPROVE;
App::$config['system']['register_text'] = ''; App::$config['system']['register_text'] = '';
App::$config['system']['admin_email'] = '{{$adminmail}}'; App::$config['system']['admin_email'] = '{{$adminmail}}';

View file

@ -51,7 +51,7 @@ App::$config['system']['ssl_cookie_protection'] = 1;
// to the email address of an already registered person who can authorise // to the email address of an already registered person who can authorise
// and/or approve/deny the request. // and/or approve/deny the request.
App::$config['system']['register_policy'] = REGISTER_OPEN; App::$config['system']['register_policy'] = REGISTER_APPROVE;
App::$config['system']['register_text'] = ''; App::$config['system']['register_text'] = '';
App::$config['system']['admin_email'] = '{{$adminmail}}'; App::$config['system']['admin_email'] = '{{$adminmail}}';

View file

@ -51,7 +51,7 @@ App::$config['system']['ssl_cookie_protection'] = 1;
// to the email address of an already registered person who can authorise // to the email address of an already registered person who can authorise
// and/or approve/deny the request. // and/or approve/deny the request.
App::$config['system']['register_policy'] = REGISTER_OPEN; App::$config['system']['register_policy'] = REGISTER_APPROVE;
App::$config['system']['register_text'] = ''; App::$config['system']['register_text'] = '';
App::$config['system']['admin_email'] = '{{$adminmail}}'; App::$config['system']['admin_email'] = '{{$adminmail}}';

View file

@ -52,7 +52,7 @@ App::$config['system']['ssl_cookie_protection'] = 1;
// REGISTER_APPROVE wymaga ustawienia 'admin_email' na adres e-mail już // REGISTER_APPROVE wymaga ustawienia 'admin_email' na adres e-mail już
// zarejestrowanej osoby, która może autoryzować i/lub zatwierdź/odrzuć wniosek. // zarejestrowanej osoby, która może autoryzować i/lub zatwierdź/odrzuć wniosek.
App::$config['system']['register_policy'] = REGISTER_OPEN; App::$config['system']['register_policy'] = REGISTER_APPROVE;
App::$config['system']['register_text'] = ''; App::$config['system']['register_text'] = '';
App::$config['system']['admin_email'] = '{{$adminmail}}'; App::$config['system']['admin_email'] = '{{$adminmail}}';

View file

@ -51,7 +51,7 @@ App::$config['system']['ssl_cookie_protection'] = 1;
// to the email address of an already registered person who can authorise // to the email address of an already registered person who can authorise
// and/or approve/deny the request. // and/or approve/deny the request.
App::$config['system']['register_policy'] = REGISTER_OPEN; App::$config['system']['register_policy'] = REGISTER_APPROVE;
App::$config['system']['register_text'] = ''; App::$config['system']['register_text'] = '';
App::$config['system']['admin_email'] = '{{$adminmail}}'; App::$config['system']['admin_email'] = '{{$adminmail}}';

View file

@ -51,7 +51,7 @@ App::$config['system']['ssl_cookie_protection'] = 1;
// to the email address of an already registered person who can authorise // to the email address of an already registered person who can authorise
// and/or approve/deny the request. // and/or approve/deny the request.
App::$config['system']['register_policy'] = REGISTER_OPEN; App::$config['system']['register_policy'] = REGISTER_APPROVE;
App::$config['system']['register_text'] = ''; App::$config['system']['register_text'] = '';
App::$config['system']['admin_email'] = '{{$adminmail}}'; App::$config['system']['admin_email'] = '{{$adminmail}}';

View file

@ -51,7 +51,7 @@ App::$config['system']['ssl_cookie_protection'] = 1;
// to the email address of an already registered person who can authorise // to the email address of an already registered person who can authorise
// and/or approve/deny the request. // and/or approve/deny the request.
App::$config['system']['register_policy'] = REGISTER_OPEN; App::$config['system']['register_policy'] = REGISTER_APPROVE;
App::$config['system']['register_text'] = ''; App::$config['system']['register_text'] = '';
App::$config['system']['admin_email'] = '{{$adminmail}}'; App::$config['system']['admin_email'] = '{{$adminmail}}';

View file

@ -60,7 +60,7 @@
{{include file="field_input.tpl" field=$phrase}} {{include file="field_input.tpl" field=$phrase}}
{{/if}} {{/if}}
<button class="btn btn-primary" type="submit" name="submit" id="newchannel-submit-button" value="{{$submit}}">{{$submit}}</button> <button class="btn btn-primary" type="submit" name="submit" id="newchannel-submit-button" {{if $disabled}}disabled="disabled" {{/if}}value="{{$submit}}">{{$submit}}</button>
<div id="register-submit-end" class="register-field-end"></div> <div id="register-submit-end" class="register-field-end"></div>
</form> </form>
<br> <br>