diff options
author | Mario <mario@mariovavti.com> | 2021-03-26 20:54:48 +0100 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2021-03-26 20:54:48 +0100 |
commit | 725e57a27a41c8780c08fe598ec6c7b24a633cf4 (patch) | |
tree | 4839ee3a5f5102caeab6da4bb811d7fde2d5107f | |
parent | b50f1657c3e5772dd6235ce98c55e71630b0c626 (diff) | |
download | volse-hubzilla-725e57a27a41c8780c08fe598ec6c7b24a633cf4.tar.gz volse-hubzilla-725e57a27a41c8780c08fe598ec6c7b24a633cf4.tar.bz2 volse-hubzilla-725e57a27a41c8780c08fe598ec6c7b24a633cf4.zip |
air: more work on UX during register
-rw-r--r-- | Zotlabs/Module/Admin/Site.php | 3 | ||||
-rw-r--r-- | Zotlabs/Module/Regate.php | 3 | ||||
-rw-r--r-- | Zotlabs/Module/Register.php | 94 | ||||
-rw-r--r-- | Zotlabs/Render/SmartyTemplate.php | 16 | ||||
-rw-r--r-- | view/tpl/plain.tpl | 28 | ||||
-rw-r--r-- | view/tpl/regate.tpl | 7 | ||||
-rw-r--r-- | view/tpl/register.tpl | 13 |
7 files changed, 108 insertions, 56 deletions
diff --git a/Zotlabs/Module/Admin/Site.php b/Zotlabs/Module/Admin/Site.php index 530eb272a..bf47f8c62 100644 --- a/Zotlabs/Module/Admin/Site.php +++ b/Zotlabs/Module/Admin/Site.php @@ -611,7 +611,8 @@ class Site { } if (! $this->register_duty) - $this->register_duty = '1-7'; + $this->register_duty = '-:-'; + $ranges = preg_split('/\s+/', $this->register_duty); $this->msgbg .= '..ranges: ' . print_r(count($ranges),true) . $this->eol; diff --git a/Zotlabs/Module/Regate.php b/Zotlabs/Module/Regate.php index 4cd902f7b..4fcae83e4 100644 --- a/Zotlabs/Module/Regate.php +++ b/Zotlabs/Module/Regate.php @@ -310,7 +310,7 @@ class Regate extends \Zotlabs\Web\Controller { '$atform' => $atform, '$resend' => $resend, '$submit' => t('Submit'), - '$acpin' => [ 'acpin', t('Validation token'),'','' ], + '$acpin' => [ 'acpin', t('Validation token'),'','' ] ]); } else { @@ -324,6 +324,7 @@ class Regate extends \Zotlabs\Web\Controller { $o = replace_macros(get_markup_template('plain.tpl'), [ '$title' => $title, '$now' => $nowf, + '$countdown' => datetime_convert('UTC', 'UTC', $r['reg_startup'], 'c'), '$infos' => 'ZAR1132W' . ' ' . t('Request not inside time frame') . EOL, ]); } diff --git a/Zotlabs/Module/Register.php b/Zotlabs/Module/Register.php index d865b7b49..98a682611 100644 --- a/Zotlabs/Module/Register.php +++ b/Zotlabs/Module/Register.php @@ -69,19 +69,21 @@ class Register extends Controller { $invite_code = ( (x($arr,'invite_code')) ? notags(trim($arr['invite_code'])) : ''); $email = ( (x($arr,'email')) ? notags(punify(trim($arr['email']))) : ''); $password = ( (x($arr,'password')) ? trim($arr['password']) : ''); + $password2 = ( (x($arr,'password2')) ? trim($arr['password2']) : ''); + $reonar = array(); // case when an invited prepares the own account by supply own pw, accept tos, prepage channel (if auto) if ($email && $invite_code) { - if ( preg_match('/^.{2,64}\@[a-z0-9.-]{4,32}\.[a-z]{2,12}$/', $email ) ) { if ( preg_match('/^[a-z0-9]{12,12}$/', $invite_code ) ) { $is247 = true; } } - } + +/* // assume someone tries to validate (dId2 C/D/E), because only field email entered if ( $email && ( ! $invite_code ) && ( ! $password ) && ( ! $_POST['password2'] ) ) { @@ -102,14 +104,27 @@ class Register extends Controller { } } +*/ + $email_verify = get_config('system','verify_email'); + if ($email_verify && ! $email) { + notice(t('Email address required') . EOL); + return; + } + if ($email) { + if ( ! preg_match('/^.{2,64}\@[a-z0-9.-]{4,32}\.[a-z]{2,12}$/', $_POST['email'] ) ) { + // msg! + notice(t('Not a valid email address') . EOL); + return; + } + } if ($act > 0 && !$is247 && !$duty['isduty']) { // normally (except very 1st timr after install), that should never arrive here (ie js hack or sth like) // log suitable for f2b also $logmsg = 'ZAR0230S Unexpected registration request off duty'; zar_log($logmsg); - goaway(z_root() . '/~'); + return; } if ($sameip && !$is247) { @@ -119,7 +134,7 @@ class Register extends Controller { if ($f && $f[0]['atip'] > $sameip) { $logmsg = 'ZAR0239S Exceeding same ip register request of ' . $sameip; zar_log($logmsg); - goaway(z_root() . '/~'); + return; } } @@ -127,41 +142,41 @@ class Register extends Controller { // msg? if ( !$is247 && self::check_reg_limits()['is'] ) return; - // accept tos - if(! x($_POST,'tos')) { + if(!$password) { // msg! - notice( 'ZAR0230E ' - . t('Please indicate acceptance of the Terms of Service. Registration failed.') . EOL); + notice(t('No password provided') . EOL); return; } // pw1 == pw2 - if((! $_POST['password']) || ($_POST['password'] !== $_POST['password2'])) { + if($password !== $password2) { // msg! - notice( 'ZAR0230E ' - . t('Passwords do not match.') . EOL); + notice(t('Passwords do not match') . EOL); return; } + $password_result = check_account_password($password); + if(!empty($password_result['error'])) { + $msg = $password_result['message']; + notice($msg); + zar_log($msg . ' ' . $did2); + return; + } - $email_verify = intval(get_config('system','verify_email')); - - if ($email) { - if ( ! preg_match('/^.{2,64}\@[a-z0-9.-]{4,32}\.[a-z]{2,12}$/', $_POST['email'] ) ) { - // msg! - notice('ZAR0239E ' - . t('Email address mistake') . EOL); - return; - } + // accept tos + if(! x($_POST,'tos')) { + // msg! + notice(t('Terms of Service not accepted') . EOL); + return; } + $policy = intval(get_config('system','register_policy')); $invonly = intval(get_config('system','invitation_only')); $invalso = intval(get_config('system','invitation_also')); $auto_create = (get_config('system','auto_channel_create') ? true : false); $auto_create = true; - switch($policy) { case REGISTER_OPEN: @@ -349,6 +364,7 @@ class Register extends Controller { ] ); pop_lang(); + hz_syslog(print_r($reonar,true)); zar_reg_mail($reonar); } else { @@ -369,13 +385,6 @@ class Register extends Controller { $reonar['chan.did1'] = notags(trim($arr['nickname'])); } - if($password_result['error']) { - $msg = $password_result['message']; - notice($msg); - zar_log($msg . ' ' . $did2); - goaway('register'); - } - $salt = random_string(32); $password = $salt . ',' . hash('whirlpool', $salt . $password); @@ -420,13 +429,15 @@ class Register extends Controller { // notice( 'ZAR0239I,' . t( 'Your digital id is' ) . EOL . 'd' . $didnew . EOL $_SESSION['zar']['msg'] = ( t('Your validation token is') . ' ' . $pass2 . EOL . t('Please remember your token and reload this page between') . EOL - . '<code class="inline-code"><span data-utc="' . datetime_convert('UTC', 'UTC', $regdelay, 'c') . '" class="register_date">' . datetime_convert('UTC', 'UTC', $regdelay, 'c') . '</span></code> ' . t('and') . ' <code class="inline-code"><span data-utc="' . datetime_convert('UTC', 'UTC', $regexpire, 'c') . '" class="register_date">' . datetime_convert('UTC', 'UTC', $regexpire, 'c') . '</span></code>' . EOL + . '<code class="inline-code"><span id="register_start" data-utc="' . datetime_convert('UTC', 'UTC', $regdelay, 'c') . '" class="register_date">' . datetime_convert('UTC', 'UTC', $regdelay, 'c') . '</span></code> ' . t('and') . ' <code class="inline-code"><span data-utc="' . datetime_convert('UTC', 'UTC', $regexpire, 'c') . '" class="register_date">' . datetime_convert('UTC', 'UTC', $regexpire, 'c') . '</span></code>' . EOL . t('to complete registration.') ); } else { $_SESSION['zar']['pin'] = $pass2; } + $_SESSION['zar']['pin'] = $pass2; + goaway(z_root() . '/regate/' . bin2hex('d' . $didnew) . 'a' ); } else { @@ -435,6 +446,8 @@ class Register extends Controller { zar_log( $msg . ' ' . $did2); } } + goaway(z_root() . '/regate/' . bin2hex($email) . $didx ); + } } } @@ -508,15 +521,21 @@ class Register extends Controller { $enable_tos = 1 - intval(get_config('system','no_termsofservice')); + $auto_create = (get_config('system','auto_channel_create') ? true : false); + $default_role = get_config('system','default_permissions_role'); + $email_verify = get_config('system','verify_email'); + $emailval = ((x($_REQUEST,'email')) ? strip_tags(trim($_REQUEST['email'])) : ""); - $email = array('email', - t('Your email address (or leave blank to register without email)') . ' <sup>ZAR0136I</sup>', - $emailval, - t('If the registation was already submitted with your data once ago, enter your identity (like email) here and submit') . '<sup>ZAR0133I</sup>' - ); + $email = ['email', + t('Your email address'), + $emailval, + (($email_verify) ? t('Required') : t('Optional')), + (($email_verify) ? '*' : ''), + $duty['atform'] + ]; - $password = array('password', t('Choose a password'), ''); - $password2 = array('password2', t('Please re-enter your password'), ''); + $password = array('password', t('Choose a password'), '', '', '', $duty['atform']); + $password2 = array('password2', t('Please re-enter your password'), '', '', '', $duty['atform']); $invite_code = array('invite_code', t('Please enter your invitation code'), ((x($_REQUEST,'invite_code')) ? strip_tags(trim($_REQUEST['invite_code'])) : "")); @@ -538,9 +557,6 @@ class Register extends Controller { $tos = array('tos', $label_tos, '', '', array(t('no'),t('yes'))); - $auto_create = (get_config('system','auto_channel_create') ? true : false); - $default_role = get_config('system','default_permissions_role'); - $email_verify = get_config('system','verify_email'); require_once('include/bbcode.php'); diff --git a/Zotlabs/Render/SmartyTemplate.php b/Zotlabs/Render/SmartyTemplate.php index 61fb72f8a..2cb96521b 100644 --- a/Zotlabs/Render/SmartyTemplate.php +++ b/Zotlabs/Render/SmartyTemplate.php @@ -8,16 +8,16 @@ use App; class SmartyTemplate implements TemplateEngine { static $name ="smarty3"; - + public function __construct() { // Cannot use get_config() here because it is called during installation when there is no DB. // FIXME: this may leak private information such as system pathnames. - $basecompiledir = ((array_key_exists('smarty3_folder', App::$config['system'])) + $basecompiledir = ((array_key_exists('smarty3_folder', App::$config['system'])) ? App::$config['system']['smarty3_folder'] : ''); if (! $basecompiledir) { - $basecompiledir = str_replace('Zotlabs','',dirname(__dir__)) . "/" . TEMPLATE_BUILD_PATH; + $basecompiledir = str_replace('Zotlabs','',dirname(__dir__)) . TEMPLATE_BUILD_PATH; } if (! is_dir($basecompiledir)) { @os_mkdir(TEMPLATE_BUILD_PATH, STORAGE_DEFAULT_PERMISSIONS, true); @@ -30,7 +30,7 @@ class SmartyTemplate implements TemplateEngine { } App::$config['system']['smarty3_folder'] = $basecompiledir; } - + // TemplateEngine interface public function replace_macros($s, $r) { @@ -52,9 +52,9 @@ class SmartyTemplate implements TemplateEngine { } $s->assign($key, $value); } - return $s->parsed($template); + return $s->parsed($template); } - + public function get_markup_template($file, $root = '') { $template_file = theme_include($file, $root); if ($template_file) { @@ -62,7 +62,7 @@ class SmartyTemplate implements TemplateEngine { $template->filename = $template_file; return $template; - } + } return EMPTY_STR; } @@ -84,7 +84,7 @@ class SmartyTemplate implements TemplateEngine { $template = new SmartyInterface(); $template->filename = $template_file; return $template; - } + } return ""; } diff --git a/view/tpl/plain.tpl b/view/tpl/plain.tpl index b0c7b3081..e7aa9c63c 100644 --- a/view/tpl/plain.tpl +++ b/view/tpl/plain.tpl @@ -1,9 +1,37 @@ <h2>{{$title}}</h2> {{if $now}}<div>{{$now}}</div>{{/if}} <div style="font-weight: normal; font-family: monospace;">{{$infos}}</div> +<div id="countdown" class="h3"></div> <script> $('.register_date').each( function () { var date = new Date($(this).data('utc')); $(this).html(date.toLocaleString()); }); + + + var date = '{{$countdown}}'; + + date = date !== '' ? date : $('#register_start').data('utc'); + + if(date) { + doCountDown(date, 'countdown'); + var x = setInterval(doCountDown, 1000, date, 'countdown'); + } + function doCountDown(date, id) { + var countDownDate = new Date(date).getTime(); + var now = new Date().getTime(); + var distance = countDownDate - now; + var days = Math.floor(distance / (1000 * 60 * 60 * 24)); + var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); + var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); + var seconds = Math.floor((distance % (1000 * 60)) / 1000); + + document.getElementById(id).innerHTML = days + "d " + hours + "h "+ minutes + "m " + seconds + "s "; + + if (distance < 0) { + clearInterval(x); + document.getElementById(id).innerHTML = 'Reloading...'; + window.location.reload(); + } + } </script> diff --git a/view/tpl/regate.tpl b/view/tpl/regate.tpl index bae0884dc..04a9df1de 100644 --- a/view/tpl/regate.tpl +++ b/view/tpl/regate.tpl @@ -20,3 +20,10 @@ </form> <div class="clear"></div> +<script> + var week_days = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']; + $('.register_date').each( function () { + var date = new Date($(this).data('utc')); + $(this).html(date.toLocaleString(undefined, {weekday: 'short', hour: 'numeric', minute: 'numeric'})); + }); +</script> diff --git a/view/tpl/register.tpl b/view/tpl/register.tpl index 8033d0a76..b38507f92 100644 --- a/view/tpl/register.tpl +++ b/view/tpl/register.tpl @@ -5,14 +5,13 @@ <div class="section-content-wrapper"> <form action="register" method="post" id="register-form"> <input type='hidden' name='form_security_token' value='{{$form_security_token}}'> + {{if $reg_is || $other_sites || $now}} <div class="section-content-warning-wrapper"> - {{if $reg_is}} + <h3>{{$now}}</h3> <div id="register-desc" class="descriptive-paragraph">{{$reg_is}}</div> - {{/if}} <div id="register-sites" class="descriptive-paragraph">{{$other_sites}}</div> - <h2>{{$now}}</h2> </div> - + {{/if}} {{if $registertext}} <div class="section-content-info-wrapper"> <div id="register-text" class="descriptive-paragraph">{{$registertext}}</div> @@ -27,12 +26,12 @@ </div> {{/if}} - {{include file="field_input.tpl" field=[$email.0,$email.1,"",$email.3,"",""]}} + {{include file="field_input.tpl" field=$email}} </div> - {{include file="field_password.tpl" field=[$pass1.0,$pass1.1,"","","",$atform]}} + {{include file="field_password.tpl" field=$pass1}} - {{include file="field_password.tpl" field=[$pass2.0,$pass2.1,"","","",$atform]}} + {{include file="field_password.tpl" field=$pass2}} {{if $auto_create}} {{if $default_role}} |