* Form refactoring 2

This commit is contained in:
Visman 2018-10-22 20:39:49 +07:00
parent 6731167d40
commit f593ed632c
13 changed files with 248 additions and 134 deletions

View file

@ -293,7 +293,7 @@ abstract class Page extends Model
if (empty($this->a['fIswev'])) {
$this->a['fIswev'] = [];
}
if (isset($val[0]) && isset($val[1]) && \is_string($val[0]) && \is_string($val[1])) {
if (isset($val[0], $val[1]) && \is_string($val[0]) && \is_string($val[1])) {
$this->a['fIswev'][$val[0]][] = $val[1];
} else {
$this->a['fIswev'] = \array_merge_recursive((array) $this->a['fIswev'], $val);

View file

@ -72,17 +72,68 @@ class Auth extends Page
$this->onlinePos = 'login';
$this->robots = 'noindex';
$this->titles = \ForkBB\__('Login');
$this->formAction = $this->c->Router->link('Login');
$this->formToken = $this->c->Csrf->create('Login');
$this->forgetLink = $this->c->Router->link('Forget');
$this->regLink = $this->c->config->o_regs_allow == '1' ? $this->c->Router->link('Register') : null;
$this->username = $v ? $v->username : (isset($args['_username']) ? $args['_username'] : '');
$this->redirect = $v ? $v->redirect : $this->c->Router->validate($ref, 'Index');
$this->save = $v ? $v->save : 1;
$username = $v ? $v->username : (isset($args['_username']) ? $args['_username'] : '');
$save = $v ? $v->save : 1;
$redirect = $v ? $v->redirect : $this->c->Router->validate($ref, 'Index');
$this->form = $this->formLogin($username, $save, $redirect);
return $this;
}
/**
* Подготавливает массив данных для формы
*
* @param array $args
*
* @return array
*/
protected function formLogin($username, $save, $redirect)
{
return [
'action' => $this->c->Router->link('Login'),
'hidden' => [
'token' => $this->c->Csrf->create('Login'),
'redirect' => $redirect,
],
'sets' => [
'login' => [
'fields' => [
'username' => [
'autofocus' => true,
'type' => 'text',
'value' => $username,
'caption' => \ForkBB\__('Username'),
'required' => true,
],
'password' => [
'id' => 'passinlogin',
'autofocus' => true,
'type' => 'password',
'caption' => \ForkBB\__('Passphrase'),
'info' => \ForkBB\__('<a href="%s">Forgotten?</a>', $this->c->Router->link('Forget')),
'required' => true,
],
'save' => [
'type' => 'checkbox',
'label' => \ForkBB\__('Remember me'),
'value' => '1',
'checked' => $save,
],
],
],
],
'btns' => [
'login' => [
'type' => 'submit',
'value' => \ForkBB\__('Sign in'),
'accesskey' => 's',
],
],
];
}
/**
* Проверка по базе и вход
*
@ -196,13 +247,53 @@ class Auth extends Page
$this->onlinePos = 'passphrase_reset';
$this->robots = 'noindex';
$this->titles = \ForkBB\__('Passphrase reset');
$this->formAction = $this->c->Router->link('Forget');
$this->formToken = $this->c->Csrf->create('Forget');
$this->email = $v ? $v->email : (isset($args['_email']) ? $args['_email'] : '');
$email = $v ? $v->email : (isset($args['_email']) ? $args['_email'] : '');
$this->form = $this->formForget($email);
return $this;
}
/**
* Подготавливает массив данных для формы
*
* @param string $email
*
* @return array
*/
protected function formForget($email)
{
return [
'action' => $this->c->Router->link('Forget'),
'hidden' => [
'token' => $this->c->Csrf->create('Forget'),
],
'sets' => [
'forget' => [
'fields' => [
'email' => [
'autofocus' => true,
'type' => 'text',
'maxlength' => 80,
'value' => $email,
'caption' => \ForkBB\__('Email'),
'info' => \ForkBB\__('Passphrase reset info'),
'required' => true,
'pattern' => '.+@.+',
],
],
],
],
'btns' => [
'submit' => [
'type' => 'submit',
'value' => \ForkBB\__('Send email'),
'accesskey' => 's',
],
],
];
}
/**
* Смена кодовой фразы
*
@ -213,12 +304,12 @@ class Auth extends Page
*/
public function changePass(array $args, $method)
{
// что-то пошло не так
if (! \hash_equals($args['hash'], $this->c->Secury->hash($args['email'] . $args['key']))
|| ! ($user = $this->c->users->load($args['email'], 'email')) instanceof User
|| empty($user->activate_string)
|| ! \hash_equals($user->activate_string, $args['key'])
) {
// что-то пошло не так
return $this->c->Message->message('Bad request', false);
}
@ -267,9 +358,53 @@ class Auth extends Page
$this->onlinePos = 'change_passphrase';
$this->robots = 'noindex';
$this->titles = \ForkBB\__('Passphrase reset');
$this->formAction = $this->c->Router->link('ChangePassword', $args);
$this->formToken = $this->c->Csrf->create('ChangePassword', $args);
$this->form = $this->formChange($args);
return $this;
}
/**
* Подготавливает массив данных для формы
*
* @param array $args
*
* @return array
*/
protected function formChange(array $args)
{
return [
'action' => $this->c->Router->link('ChangePassword', $args),
'hidden' => [
'token' => $this->c->Csrf->create('ChangePassword', $args),
],
'sets' => [
'forget' => [
'fields' => [
'password' => [
'autofocus' => true,
'type' => 'password',
'caption' => \ForkBB\__('New pass'),
'required' => true,
'pattern' => '^.{16,}$',
],
'password2' => [
'autofocus' => true,
'type' => 'password',
'caption' => \ForkBB\__('Confirm new pass'),
'info' => \ForkBB\__('Pass format') . ' ' . \ForkBB\__('Pass info'),
'required' => true,
'pattern' => '^.{16,}$',
],
],
],
],
'btns' => [
'login' => [
'type' => 'submit',
'value' => \ForkBB\__('Change passphrase'),
'accesskey' => 's',
],
],
];
}
}

View file

@ -47,7 +47,7 @@ class Register extends Page
// нет согласия с правилами
if (isset($this->fIswev['cancel'])) {
return $this->c->Redirect->page('Index')->message('Reg cancel redirect');
return $this->c->Message->message('Reg cancel', true, 403);
}
$this->fIndex = 'register';
@ -55,16 +55,72 @@ class Register extends Page
$this->onlinePos = 'register';
$this->titles = \ForkBB\__('Register');
$this->robots = 'noindex';
$this->formAction = $this->c->Router->link('RegisterForm');
$this->formToken = $this->c->Csrf->create('RegisterForm');
$this->agree = $v->agree;
$this->on = '1';
$this->email = $v->email;
$this->username = $v->username;
$this->form = $this->formReg($v);
return $this;
}
/**
* Подготавливает массив данных для формы
*
* @param Validator $v
*
* @return array
*/
protected function formReg(Validator $v)
{
return [
'action' => $this->c->Router->link('RegisterForm'),
'hidden' => [
'token' => $this->c->Csrf->create('RegisterForm'),
'agree' => $v->agree,
'on' => '1',
],
'sets' => [
'reg' => [
'fields' => [
'email' => [
'autofocus' => true,
'class' => 'hint',
'type' => 'text',
'maxlength' => 80,
'value' => $v->email,
'caption' => \ForkBB\__('Email'),
'info' => \ForkBB\__('Email info'),
'required' => true,
'pattern' => '.+@.+',
],
'username' => [
'class' => 'hint',
'type' => 'text',
'maxlength' => 25,
'value' => $v->username,
'caption' => \ForkBB\__('Username'),
'info' => \ForkBB\__('Login format'),
'required' => true,
'pattern' => '^.{2,25}$',
],
'password' => [
'class' => 'hint',
'type' => 'password',
'caption' => \ForkBB\__('Passphrase'),
'info' => \ForkBB\__('Pass format') . ' ' . \ForkBB\__('Pass info'),
'required' => true,
'pattern' => '^.{16,}$',
],
],
],
],
'btns' => [
'register' => [
'type' => 'submit',
'value' => \ForkBB\__('Sign up'),
'accesskey' => 's',
],
],
];
}
/**
* Завершение регистрации
*
@ -163,13 +219,13 @@ class Register extends Page
// форма сброса пароля
} else {
$auth = $this->c->Auth;
$auth->fIswev = ['w' => [\ForkBB\__('Error welcom mail', $this->c->config->o_admin_email)]];
$auth->fIswev = ['w', \ForkBB\__('Error welcom mail', $this->c->config->o_admin_email)];
return $auth->forget(['_email' => $v->email], 'GET');
}
// форма логина
} else {
$auth = $this->c->Auth;
$auth->fIswev = ['s' => [\ForkBB\__('Reg complete')]];
$auth->fIswev = ['s', \ForkBB\__('Reg complete')];
return $auth->login(['_username' => $v->username], 'GET');
}
}
@ -202,7 +258,7 @@ class Register extends Page
$this->c->Lang->load('register');
$auth = $this->c->Auth;
$auth->fIswev = ['s' => [\ForkBB\__('Reg complete')]];
$auth->fIswev = ['s', \ForkBB\__('Reg complete')];
return $auth->login(['_username' => $user->username], 'GET');
}
}

View file

@ -24,8 +24,8 @@ msgstr "Account is not activated."
msgid "Wrong user/pass"
msgstr "Wrong username and/or passphrase."
msgid "Forgotten pass"
msgstr "Forgotten?"
msgid "<a href=\"%s\">Forgotten?</a>"
msgstr "<a href=\"%s\">Forgotten?</a>"
msgid "Login redirect"
msgstr "Logged in successfully. Redirecting …"

View file

@ -21,8 +21,8 @@ msgstr "Treat other people the way you want to be treated yourself."
msgid "Bad agree"
msgstr "ID forms obsolete. Please begin <a href=\"%s\">registration</a> again."
msgid "Reg cancel redirect"
msgstr "No you agree with the forum rules. Registration cancelled. Redirecting …"
msgid "Reg cancel"
msgstr "You did not agree with the rules of this board."
msgid "Registration flood"
msgstr "A new user was registered with the same IP address as you within the last hour. To prevent registration flooding, at least an hour has to pass between registrations from the same IP. Sorry for the inconvenience."

View file

@ -24,8 +24,8 @@ msgstr "Аккаунт не активирован."
msgid "Wrong user/pass"
msgstr "Неверное имя и/или кодовая фраза. Имя и кодовая фраза чувствительны к регистру!"
msgid "Forgotten pass"
msgstr "Забыли?"
msgid "<a href=\"%s\">Forgotten?</a>"
msgstr "<a href=\"%s\">Забыли?</a>"
msgid "Login redirect"
msgstr "Успешный вход. Переадресация &hellip;"

View file

@ -21,8 +21,8 @@ msgstr "Относитесь к другим так, как хотите, что
msgid "Bad agree"
msgstr "Идентификатор формы устарел. Пожалуйста, начните <a href=\"%s\">регистрацию</a> заново."
msgid "Reg cancel redirect"
msgstr "Нет вашего согласия с правилами форума. Регистрация отменена. Переадресация &hellip;"
msgid "Reg cancel"
msgstr "Вы не согласились с правилами форума."
msgid "Registration flood"
msgstr "Недавно с вашего IP адреса был зарегистрирован новый пользователь. Должно пройти не менее часа до следующей регистрации с этого IP адреса. Извините за неудобства."

View file

@ -2,26 +2,8 @@
<section class="f-main f-login">
<div class="f-fdiv f-lrdiv">
<h2>{!! __('Change pass') !!}</h2>
<form class="f-form" method="post" action="{!! $p->formAction !!}">
<input type="hidden" name="token" value="{!! $p->formToken !!}">
<fieldset>
<dl>
<dt><label class="f-child1 f-req" for="id-password">{!! __('New pass') !!}</label></dt>
<dd>
<input required class="f-ctrl" id="id-password" type="password" name="password" pattern="^.{16,}$" autofocus tabindex="1">
</dd>
</dl>
<dl>
<dt><label class="f-child1 f-req" for="id-password2">{!! __('Confirm new pass') !!}</label></dt>
<dd>
<input required class="f-ctrl" id="id-password2" type="password" name="password2" pattern="^.{16,}$" tabindex="2">
<p class="f-child4">{!! __('Pass format') !!} {!! __('Pass info') !!}</p>
</dd>
</dl>
</fieldset>
<p class="f-btns">
<input class="f-btn" type="submit" name="login" value="{!! __('Change passphrase') !!}" tabindex="3">
</p>
</form>
@if ($form = $p->form)
@include ('layouts/form')
@endif
</div>
</section>

View file

@ -2,35 +2,9 @@
<section class="f-main f-login">
<div class="f-fdiv f-lrdiv">
<h2>{!! __('Login') !!}</h2>
<form class="f-form" method="post" action="{!! $p->formAction !!}">
<input type="hidden" name="token" value="{!! $p->formToken !!}">
<input type="hidden" name="redirect" value="{{ $p->redirect }}">
<fieldset>
<dl>
<dt><label class="f-child1 f-req" for="id-username">{!! __('Username') !!}</label></dt>
<dd>
<input required class="f-ctrl" id="id-username" type="text" name="username" value="{{ $p->username }}" maxlength="25" autofocus spellcheck="false" tabindex="1">
</dd>
</dl>
<dl>
<dt><label class="f-child1 f-req" for="id-password">{!! __('Passphrase') !!}<a class="f-forgetlink" href="{!! $p->forgetLink !!}" tabindex="5">{!! __('Forgotten pass') !!}</a></label></dt>
<dd>
<input required class="f-ctrl" id="id-password" type="password" name="password" tabindex="2">
</dd>
</dl>
<dl>
<dt></dt>
@if ($p->save)
<dd><label class="f-child2"><input type="checkbox" name="save" value="1" tabindex="3" checked>{!! __('Remember me') !!}</label></dd>
@else
<dd><label class="f-child2"><input type="checkbox" name="save" value="1" tabindex="3">{!! __('Remember me') !!}</label></dd>
@if ($form = $p->form)
@include ('layouts/form')
@endif
</dl>
</fieldset>
<p class="f-btns">
<input class="f-btn" type="submit" name="login" value="{!! __('Sign in') !!}" tabindex="4">
</p>
</form>
</div>
@if ($p->regLink)
<div class="f-fdiv f-lrdiv">

View file

@ -2,20 +2,8 @@
<section class="f-main f-login">
<div class="f-fdiv f-lrdiv">
<h2>{!! __('Passphrase reset') !!}</h2>
<form class="f-form" method="post" action="{!! $p->formAction !!}">
<input type="hidden" name="token" value="{!! $p->formToken !!}">
<fieldset>
<dl>
<dt><label class="f-child1 f-req" for="id-email">{!! __('Email') !!}</label></dt>
<dd>
<input required class="f-ctrl" id="id-email" type="text" name="email" value="{{ $p->email }}" maxlength="80" pattern=".+@.+" autofocus spellcheck="false" tabindex="1">
<p class="f-child4">{!! __('Passphrase reset info') !!}</p>
</dd>
</dl>
</fieldset>
<p class="f-btns">
<input class="f-btn" type="submit" name="submit" value="{!! __('Send email') !!}" tabindex="2">
</p>
</form>
@if ($form = $p->form)
@include ('layouts/form')
@endif
</div>
</section>

View file

@ -2,36 +2,8 @@
<section class="f-main f-register">
<div class="f-fdiv f-lrdiv">
<h2>{!! __('Register') !!}</h2>
<form class="f-form" method="post" action="{!! $p->formAction !!}">
<input type="hidden" name="token" value="{!! $p->formToken !!}">
<input type="hidden" name="agree" value="{!! $p->agree !!}">
<input type="hidden" name="on" value="{!! $p->on !!}">
<fieldset>
<dl>
<dt><label class="f-child1 f-req" for="id-email">{!! __('Email') !!}</label></dt>
<dd>
<input required class="f-ctrl" id="id-email" type="text" name="email" value="{{ $p->email }}" maxlength="80" pattern=".+@.+" autofocus spellcheck="false" tabindex="1">
<p class="f-child4 f-fhint">{!! __('Email info') !!}</p>
</dd>
</dl>
<dl>
<dt><label class="f-child1 f-req" for="id-username">{!! __('Username') !!}</label></dt>
<dd>
<input required class="f-ctrl" id="id-username" type="text" name="username" value="{{ $p->username }}" maxlength="25" pattern="^.{2,25}$" spellcheck="false" tabindex="2">
<p class="f-child4 f-fhint">{!! __('Login format') !!}</p>
</dd>
</dl>
<dl>
<dt><label class="f-child1 f-req" for="id-password">{!! __('Passphrase') !!}</label></dt>
<dd>
<input required class="f-ctrl" id="id-password" type="password" name="password" pattern="^.{16,}$" tabindex="3">
<p class="f-child4 f-fhint">{!! __('Pass format') !!} {!! __('Pass info') !!}</p>
</dd>
</dl>
</fieldset>
<p class="f-btns">
<input class="f-btn" type="submit" name="register" value="{!! __('Sign up') !!}" tabindex="4">
</p>
</form>
@if ($form = $p->form)
@include ('layouts/form')
@endif
</div>
</section>

View file

@ -20,7 +20,7 @@
<div id="id-rules">{!! $p->rules !!}</div>
@if ($form = $p->form)
<div class="f-fdiv f-lrdiv">
@include('layouts/form')
@include ('layouts/form')
</div>
@endif
</section>

View file

@ -610,17 +610,18 @@ body,
box-shadow: inset 0 0 0.5rem 0 rgba(170,121,57,0.75), 0 0 0.5rem 0 rgba(170,121,57,0.75);
}
#fork .f-ctrl + .f-fhint {
#fork .f-field-hint .f-child4 {
overflow: hidden;
max-height: 0;
-webkit-transition: max-height 0.5s, margin 0.5s;
-webkit-transition-delay: 0.2s;
transition: max-height 0.5s, margin 0.5s;
transition-delay: 0.2s;
}
#fork .f-ctrl:focus + .f-fhint,
#fork .f-ctrl:active + .f-fhint {
#fork .f-field-hint .f-ctrl:focus + .f-child4,
#fork .f-field-hint .f-ctrl:active + .f-child4 {
max-height: 10rem;
}
@ -1117,10 +1118,16 @@ body,
text-align: center;
}
#fork .f-forgetlink {
font-size: 0.875rem;
float: right;
font-weight: normal;
#fork #id-dl-passinlogin {
position: relative;
}
#fork #id-dl-passinlogin .f-child4 {
position: absolute;
top: 0.5rem;
right: 0.3125rem;
width: auto;
margin: 0;
}
/***************************************/