mirror of
https://gitnet.fr/deblan/gist.git
synced 2021-08-14 08:30:49 +02:00
#5 Remember me feature
This commit is contained in:
parent
e65d19e627
commit
f36c0b8eeb
@ -25,6 +25,8 @@ Installation
|
||||
$ # EDIT propel.yaml (dsn)
|
||||
$ make propel
|
||||
|
||||
Edit `app/bootstrap.php.d/70-security.php` and modify the valye of `$app['token']` with a strong secret phrase.
|
||||
|
||||
Screencast: https://asciinema.org/a/19814
|
||||
|
||||
### Git
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
use Gist\Service\UserProvider;
|
||||
use Silex\Provider\SecurityServiceProvider;
|
||||
use Silex\Provider\RememberMeServiceProvider;
|
||||
use Gist\Service\SaltGenerator;
|
||||
use Gist\Security\AuthenticationProvider;
|
||||
use Gist\Security\AuthenticationListener;
|
||||
@ -12,6 +13,7 @@ use Symfony\Component\Security\Http\HttpUtils;
|
||||
|
||||
$app['enable_registration'] = true;
|
||||
$app['enable_login'] = true;
|
||||
$app['token'] = 'ThisTokenIsNotSoSecretChangeIt';
|
||||
|
||||
$app['salt_generator'] = $app->share(function($app) {
|
||||
return new SaltGenerator();
|
||||
@ -24,8 +26,6 @@ $app['user.provider'] = $app->share(function ($app) {
|
||||
);
|
||||
});
|
||||
|
||||
$app->register(new SessionServiceProvider());
|
||||
|
||||
$app['security.authentication_listener.factory.form'] = $app->protect(function ($name, $options) use ($app) {
|
||||
$app['security.authentication_provider.'.$name.'.form'] = $app->share(function ($app) {
|
||||
return new AuthenticationProvider($app['user.provider']);
|
||||
@ -65,6 +65,11 @@ $app->register(
|
||||
'users' => $app->share(function () use ($app) {
|
||||
return $app['user.provider'];
|
||||
}),
|
||||
'remember_me' => [
|
||||
'key' => $app['token'],
|
||||
'path' => '/',
|
||||
'always_remember_me' => false,
|
||||
],
|
||||
],
|
||||
],
|
||||
'security.access_rules' => [
|
||||
@ -73,6 +78,9 @@ $app->register(
|
||||
]
|
||||
);
|
||||
|
||||
$app->register(new SessionServiceProvider());
|
||||
$app->register(new RememberMeServiceProvider());
|
||||
|
||||
$app['security.authentication.logout_handler._proto'] = $app->protect(function ($name, $options) use ($app) {
|
||||
return $app->share(function () use ($name, $options, $app) {
|
||||
return new LogoutSuccessHandler(
|
||||
|
@ -49,6 +49,8 @@ login:
|
||||
placeholder: 'Username'
|
||||
password:
|
||||
placeholder: 'Password'
|
||||
remember_me:
|
||||
label: 'Remember me'
|
||||
register:
|
||||
title: 'New account'
|
||||
already_exists: 'This username is already registred!'
|
||||
|
@ -46,9 +46,11 @@ login:
|
||||
invalid: 'Nom d''utilisateur ou mot de passe incorrect.'
|
||||
form:
|
||||
username:
|
||||
placeholder: 'Username'
|
||||
placeholder: 'Nom d''utilisateur'
|
||||
password:
|
||||
placeholder: 'Password'
|
||||
placeholder: 'Mot de passe'
|
||||
remember_me:
|
||||
label: 'Se souvenir de moi'
|
||||
register:
|
||||
title: 'Nouveau compte'
|
||||
already_exists: 'Ce nom d''utilisateur est déjà enregistré'
|
||||
|
@ -19,7 +19,7 @@ class UserLoginForm extends AbstractForm
|
||||
'required' => true,
|
||||
'attr' => array(
|
||||
'class' => 'form-control',
|
||||
'placeholder' => $this->translator->trans('login.register.form.username.placeholder'),
|
||||
'placeholder' => $this->translator->trans('login.login.form.username.placeholder'),
|
||||
),
|
||||
'constraints' => array(
|
||||
new NotBlank(array(
|
||||
@ -36,9 +36,8 @@ class UserLoginForm extends AbstractForm
|
||||
'required' => true,
|
||||
'attr' => array(
|
||||
'class' => 'form-control',
|
||||
'placeholder' => $this->translator->trans('login.register.form.password.placeholder'),
|
||||
'placeholder' => $this->translator->trans('login.login.form.password.placeholder'),
|
||||
),
|
||||
'trim' => false,
|
||||
'constraints' => array(
|
||||
new NotBlank(array(
|
||||
'message' => $this->translator->trans('form.error.not_blank'),
|
||||
@ -47,6 +46,20 @@ class UserLoginForm extends AbstractForm
|
||||
)
|
||||
);
|
||||
|
||||
$this->builder->add(
|
||||
'_remember_me',
|
||||
'checkbox',
|
||||
array(
|
||||
'label' => $this->translator->trans('login.login.form.remember_me.label'),
|
||||
'required' => false,
|
||||
'mapped' => false,
|
||||
'attr' => array(
|
||||
),
|
||||
'constraints' => array(
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,12 @@
|
||||
{{ form_widget(form._password) }}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
{{ form_errors(form._remember_me) }}
|
||||
{{ form_widget(form._remember_me) }}
|
||||
{{ form_label(form._remember_me) }}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<input type="submit" class="btn btn-primary" value="{{ 'form.submit'|trans }}">
|
||||
</p>
|
||||
|
Loading…
Reference in New Issue
Block a user