Renvoi mot de passe via Profil user opérationnel et avancement sur connexion via fenêtre modale
This commit is contained in:
parent
025d0a2cad
commit
8c32377738
|
@ -8,15 +8,29 @@ function connexion(nom_connecte, mdp, chemin) {
|
||||||
var result = JSON.parse(data);
|
var result = JSON.parse(data);
|
||||||
// Afficher l'avatar et le nom du connecté sur la barre d'état ou message d'erreur
|
// Afficher l'avatar et le nom du connecté sur la barre d'état ou message d'erreur
|
||||||
if (result.valide) {
|
if (result.valide) {
|
||||||
$("#bouton-connexion").html('');
|
$("#bouton-connexion").css('display',"none");
|
||||||
$("#bouton-connexion").append('<span><img src="/avatar_user.png" width="22" height="22" />');
|
$("#avatar-user").css('display',"block");
|
||||||
$("#bouton-connexion").append('</span>');
|
$("#avatar-user").html('');
|
||||||
$("#nom_connecte").css('display',"block");
|
$("#avatar-user").append('<span><img src="/avatar_user.png" width="22" height="22" />');
|
||||||
|
$("#avatar-user").append('</span>');
|
||||||
|
$("#user-connecte").css('display',"block");
|
||||||
|
//$("#nom_connecte").append('<span>');
|
||||||
|
$("#contenu_bouton").html('');
|
||||||
|
$("#contenu_bouton").append(result.username);
|
||||||
|
//$("#nom_connecte").append('</span>');
|
||||||
|
//$("#nom_connecte").css('display',"block");
|
||||||
$("#deconnexion").css('display',"block");
|
$("#deconnexion").css('display',"block");
|
||||||
$("#inscription").css('display',"none");
|
$("#inscription").css('display',"none");
|
||||||
$("#nom_connecte").append(result.username);
|
//alert('username='+result.username);
|
||||||
|
// die();
|
||||||
|
|
||||||
|
//$("#nom_connecte").html('test');
|
||||||
|
// $("#nom_connecte").append('<span>');
|
||||||
|
// $("#nom_connecte").append(result.username);
|
||||||
|
// $("#nom_connecte").append('</span>');
|
||||||
|
//die();
|
||||||
// On recharge la page pour tenir compte de la connexion de l'utilisateur
|
// On recharge la page pour tenir compte de la connexion de l'utilisateur
|
||||||
window.location.reload(true);
|
//window.location.reload(true);
|
||||||
} else {
|
} else {
|
||||||
$('.alert-danger').html('');
|
$('.alert-danger').html('');
|
||||||
$(".alert-danger").css('display',"block");
|
$(".alert-danger").css('display',"block");
|
||||||
|
|
|
@ -25,7 +25,7 @@ class AccountModule extends Module
|
||||||
$router->post('/inscription', SignupAction::class);
|
$router->post('/inscription', SignupAction::class);
|
||||||
$router->get('/mon-profil', [LoggedInMiddleware::class, AccountAction::class], 'account');
|
$router->get('/mon-profil', [LoggedInMiddleware::class, AccountAction::class], 'account');
|
||||||
$router->post('/mon-profil', [LoggedInMiddleware::class, AccountEditAction::class]);
|
$router->post('/mon-profil', [LoggedInMiddleware::class, AccountEditAction::class]);
|
||||||
$router->get('/password-utilisateur', [PasswordForgetAction::class, ProfilAction::class], 'account.profil');
|
$router->get('/profil/{user:[a-zA-Z\-0-9]+}', [LoggedInMiddleware::class, ProfilAction::class], 'account.profil');
|
||||||
$router->post('/password-utilisateur', ProfilAction::class);
|
$router->post('/profil/{user:[a-zA-Z\-0-9]+}', [LoggedInMiddleware::class, ProfilAction::class]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,18 +34,9 @@ class ProfilAction
|
||||||
|
|
||||||
public function __invoke(ServerRequestInterface $request)
|
public function __invoke(ServerRequestInterface $request)
|
||||||
{
|
{
|
||||||
/* Transmission du nom et de l'avatar de l'utilisateur connecté à la vue Twig */
|
$user_affiche = $request->getAttribute('user')->username;
|
||||||
if(!isset($_SESSION)) {
|
$nom_avatar = $request->getAttribute('user')->avatar;
|
||||||
//session_start();
|
$email = $request->getAttribute('user')->email;
|
||||||
}
|
return $this->renderer->render('@account/profil', compact('user_affiche', 'nom_avatar', 'email'));
|
||||||
if (isset($_SESSION['user'])) {
|
|
||||||
$nom_user = $_SESSION['user'];
|
|
||||||
$requete_user = $this->userTable->findBy('username', $nom_user);
|
|
||||||
$nom_avatar = $requete_user->avatar;
|
|
||||||
$email = $requete_user->email;
|
|
||||||
} else {
|
|
||||||
$nom_user = '';
|
|
||||||
}
|
|
||||||
return $this->renderer->render('@account/profil', compact('nom_user','nom_avatar','email'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<script type="text/javascript" src="/js/script.js"></script>
|
<script type="text/javascript" src="/js/script.js"></script>
|
||||||
<div class="profil_user">
|
<div class="profil_user">
|
||||||
<h4>Profil utilisateur {{ nom_user }}</h4>
|
<h4>Profil utilisateur - {{ user_affiche }}</h4>
|
||||||
<div id="avatar" class="col-sm-10 card" style="text-align:left;margin-left: 1.7rem;">
|
<div id="avatar" class="col-sm-10 card" style="text-align:left;margin-left: 1.7rem;">
|
||||||
<div class="card-block" style="margin-left: 1rem;">
|
<div class="card-block" style="margin-left: 1rem;">
|
||||||
<h5 class="card-title">Changement d'avatar</h5>
|
<h5 class="card-title">Changement d'avatar</h5>
|
||||||
|
@ -28,12 +28,13 @@
|
||||||
<div class="card-block" style="margin-left: 1rem;margin-top:0.6rem;">
|
<div class="card-block" style="margin-left: 1rem;margin-top:0.6rem;">
|
||||||
<h5 class="card-title">Changement de mot de passe</h5>
|
<h5 class="card-title">Changement de mot de passe</h5>
|
||||||
<h5 class="card-title">(via l'envoi d'un lien par mail)</h5>
|
<h5 class="card-title">(via l'envoi d'un lien par mail)</h5>
|
||||||
<div class="container" style="background-color: lightgray;opacity: 0.9;
|
<div class="container" style="color:black;background-color: lightgray;opacity: 0.9;margin:0.5rem 0.2rem;padding:0.4rem;">
|
||||||
margin-left: 0rem;margin-bottom:1rem; padding:1rem;">
|
<form action="{{ path('auth.password') }}" method="post">
|
||||||
<form action="/password" method="post">
|
<button class="btn btn-primary">Renvoyer un mot de passe</button>
|
||||||
{{ csrf_input() }}
|
<div style="width:0;height:0;">
|
||||||
{{ field('email', email, 'Votre Email', {type: 'email'}) }}
|
{{ field('username', user_affiche, "", {type: 'hidden'}) }}
|
||||||
<button class="btn btn-primary">Changer de mot de passe</button>
|
{{ field('email', email, "", {type: 'hidden'}) }}
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -25,11 +25,11 @@ class AdminModule extends Module
|
||||||
{
|
{
|
||||||
$router->get('/dashboard', [LoggedInMiddleware::class, DashboardAction::class], 'dashboard');
|
$router->get('/dashboard', [LoggedInMiddleware::class, DashboardAction::class], 'dashboard');
|
||||||
$router->get('/dashboard/{user:[a-zA-Z\-0-9]+}', [LoggedInMiddleware::class, DashboardUserAction::class], 'dashboard.user');
|
$router->get('/dashboard/{user:[a-zA-Z\-0-9]+}', [LoggedInMiddleware::class, DashboardUserAction::class], 'dashboard.user');
|
||||||
$router->get('/activation', ActiveAction::class, 'account.active');
|
$router->get('/activation', [LoggedInMiddleware::class, ActiveAction::class], 'account.active');
|
||||||
$router->post('/activation', ActiveAction::class);
|
$router->post('/activation', ActiveAction::class);
|
||||||
$router->get('/profil-user', [LoggedInMiddleware::class, AccountUserEditAction::class], 'account.user');
|
$router->get('/profil-user', [LoggedInMiddleware::class, AccountUserEditAction::class], 'account.user');
|
||||||
$router->post('/profil-user', [LoggedInMiddleware::class, AccountUserEditAction::class]);
|
$router->post('/profil-user', [LoggedInMiddleware::class, AccountUserEditAction::class]);
|
||||||
$router->any('/password_reinit', PasswordForgetAction::class, 'auth.password');
|
//$router->any('/password_reinit', PasswordForgetAction::class, 'auth.password');
|
||||||
if ($renderer instanceof TwigRenderer) {
|
if ($renderer instanceof TwigRenderer) {
|
||||||
$renderer->getTwig()->addExtension($adminTwigExtension);
|
$renderer->getTwig()->addExtension($adminTwigExtension);
|
||||||
// $renderer->getTwig()->addExtension($variableExtension);
|
// $renderer->getTwig()->addExtension($variableExtension);
|
||||||
|
|
|
@ -54,11 +54,8 @@ class DashboardUserAction
|
||||||
|
|
||||||
$url_part = explode('/',$_SERVER['REQUEST_URI']);
|
$url_part = explode('/',$_SERVER['REQUEST_URI']);
|
||||||
$user_affiche = $url_part[2];
|
$user_affiche = $url_part[2];
|
||||||
|
|
||||||
$user = $this->userTable->findBy('username', $user_affiche);
|
$user = $this->userTable->findBy('username', $user_affiche);
|
||||||
$id_affiche = $user->id;
|
$id_affiche = $user->id;
|
||||||
// echo "id_affiche=".$id_affiche;
|
|
||||||
// die();
|
|
||||||
$actif_affiche = $user->actif;
|
$actif_affiche = $user->actif;
|
||||||
$listeAntennes = $this->antenneTable->findAllAntennes();
|
$listeAntennes = $this->antenneTable->findAllAntennes();
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ namespace App\Auth\Action;
|
||||||
|
|
||||||
use App\Auth\Mailer\PasswordResetMailer;
|
use App\Auth\Mailer\PasswordResetMailer;
|
||||||
use App\Auth\UserTable;
|
use App\Auth\UserTable;
|
||||||
|
use App\Framework\Response\RedirectBackResponse;
|
||||||
use Framework\Actions\RouterAwareAction;
|
use Framework\Actions\RouterAwareAction;
|
||||||
use Framework\Database\NoRecordException;
|
use Framework\Database\NoRecordException;
|
||||||
use Framework\Renderer\RendererInterface;
|
use Framework\Renderer\RendererInterface;
|
||||||
|
@ -60,14 +61,13 @@ class PasswordForgetAction
|
||||||
return $this->renderer->render('@auth/password',compact('affichage_div'));
|
return $this->renderer->render('@auth/password',compact('affichage_div'));
|
||||||
}
|
}
|
||||||
$params = $request->getParsedBody();
|
$params = $request->getParsedBody();
|
||||||
$url_part = explode('/',$_SERVER['HTTP_REFERER']);
|
//$url_part = explode('/',$request->getServerParams()['HTTP_REFERER'] ?? '/');
|
||||||
$chemin = $url_part[3].'/'.$url_part[4];
|
//$chemin = $url_part[3].'/'.$url_part[4];
|
||||||
|
|
||||||
$validator = (new Validator($params))
|
$validator = (new Validator($params))
|
||||||
->notEmpty('email')
|
->notEmpty('email')
|
||||||
->email('email');
|
->email('email');
|
||||||
if ($validator->isValid()) {
|
if ($validator->isValid()) {
|
||||||
// try {
|
|
||||||
if ($user = $this->userTable->findBy('email', $params['email'])) {
|
if ($user = $this->userTable->findBy('email', $params['email'])) {
|
||||||
|
|
||||||
$token = $this->userTable->resetPassword($user->id);
|
$token = $this->userTable->resetPassword($user->id);
|
||||||
|
@ -78,15 +78,10 @@ class PasswordForgetAction
|
||||||
$this->flashService->success("Un email a été envoyé à l'utilisateur");
|
$this->flashService->success("Un email a été envoyé à l'utilisateur");
|
||||||
|
|
||||||
$affichage_div = false;
|
$affichage_div = false;
|
||||||
return new RedirectResponse($chemin);
|
return new RedirectBackResponse($request);
|
||||||
//return $this->renderer->render('@auth/password', compact('affichage_div'));
|
|
||||||
} else {
|
} else {
|
||||||
$this->flashService->error('Aucun utilisateur ne correspond à cet email');
|
$this->flashService->error('Aucun utilisateur ne correspond à cet email');
|
||||||
}
|
}
|
||||||
/* } catch (NoRecordException $e) {
|
|
||||||
//$errors = ['email' => 'Aucun utilisateur ne correspond à cet email'];
|
|
||||||
$this->flashService->error('Aucun utilisateur ne correspond à cet email');
|
|
||||||
}*/
|
|
||||||
} else {
|
} else {
|
||||||
$errors = $validator->getErrors();
|
$errors = $validator->getErrors();
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ class LoggedInMiddleware implements MiddlewareInterface
|
||||||
{
|
{
|
||||||
$user = $this->auth->getUser();
|
$user = $this->auth->getUser();
|
||||||
|
|
||||||
if (is_null($user) and (!$_SESSION['user'])) {
|
if (is_null($user)) {
|
||||||
//throw new ForbiddenException();
|
//throw new ForbiddenException();
|
||||||
//return $this->redirect('auth.login');
|
//return $this->redirect('auth.login');
|
||||||
//$this->session->set('auth.login', $request->getUri()->getPath());
|
//$this->session->set('auth.login', $request->getUri()->getPath());
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace App\Framework\Response;
|
||||||
|
|
||||||
|
use Framework\Response\RedirectResponse;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
|
class RedirectBackResponse extends RedirectResponse
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct(ServerRequestInterface $request)
|
||||||
|
{
|
||||||
|
parent::__construct($request->getServerParams()['HTTP_REFERER'] ?? '/');
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,21 +26,23 @@ class VariableExtension extends \Twig_Extension
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
new \Twig_SimpleFunction('affiche_username', [$this, 'affich_usrname']),
|
new \Twig_SimpleFunction('affiche_username', [$this, 'affich_usrname']),
|
||||||
new \Twig_SimpleFunction('affiche_role', [$this, 'affich_role'])
|
new \Twig_SimpleFunction('affiche_role', [$this, 'affich_role']),
|
||||||
|
new \Twig_SimpleFunction('affiche_mail', [$this, 'affich_mail'])
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
public function affich_role(): ?string
|
public function affich_role(): ?string
|
||||||
{
|
{
|
||||||
//echo "session=".$_SESSION['user'];
|
|
||||||
//die();
|
|
||||||
$retour_aff = $this->session->get('role') ?: '';
|
$retour_aff = $this->session->get('role') ?: '';
|
||||||
return $retour_aff;
|
return $retour_aff;
|
||||||
}
|
}
|
||||||
public function affich_usrname(): ?string
|
public function affich_usrname(): ?string
|
||||||
{
|
{
|
||||||
//echo "session=".$_SESSION['user'];
|
|
||||||
//die();
|
|
||||||
$retour_aff = $this->session->get('username') ?: '';
|
$retour_aff = $this->session->get('username') ?: '';
|
||||||
return $retour_aff;
|
return $retour_aff;
|
||||||
}
|
}
|
||||||
|
public function affich_mail(): ?string
|
||||||
|
{
|
||||||
|
$retour_aff = $this->session->get('email') ?: '';
|
||||||
|
return $retour_aff;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,10 +45,11 @@ class AntenneShowAction
|
||||||
|
|
||||||
public function __invoke(Request $request)
|
public function __invoke(Request $request)
|
||||||
{
|
{
|
||||||
|
if ($request->getMethod() === 'GET') {
|
||||||
$params = $request->getQueryParams();
|
$params = $request->getQueryParams();
|
||||||
$gmarchePrefix = $this->container->get('gmarche.prefix');
|
$gmarchePrefix = $this->container->get('gmarche.prefix');
|
||||||
// On récupère l'id de la région cliquée
|
// On récupère l'id de la région cliquée
|
||||||
$region_id = $this->regionTable->findBy('slug', $request->getAttribute('slug'))->id;
|
$region_id = $this->regionTable->findBy('slug', $request->getAttribute('slug'))->id ?: 1;
|
||||||
$slug = $request->getAttribute('slug');
|
$slug = $request->getAttribute('slug');
|
||||||
$page = $params['p'] ?? 1; // Si la page n'est pas définie, on l'initialise à 1
|
$page = $params['p'] ?? 1; // Si la page n'est pas définie, on l'initialise à 1
|
||||||
$antennes = $this->antenneTable->findAllbyRegion($region_id)->paginate(25, $page);
|
$antennes = $this->antenneTable->findAllbyRegion($region_id)->paginate(25, $page);
|
||||||
|
@ -71,3 +72,4 @@ class AntenneShowAction
|
||||||
return $this->renderer->render('@gmarche/antenne', compact('nom_user', 'slug', 'region', 'gmarchePrefix', 'antennes', 'page'));
|
return $this->renderer->render('@gmarche/antenne', compact('nom_user', 'slug', 'region', 'gmarchePrefix', 'antennes', 'page'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ namespace App\Gmarche;
|
||||||
|
|
||||||
use App\Gmarche\Actions\AntenneShowAction;
|
use App\Gmarche\Actions\AntenneShowAction;
|
||||||
use App\Gmarche\Actions\RegionIndexAction;
|
use App\Gmarche\Actions\RegionIndexAction;
|
||||||
use Framework\Auth;
|
|
||||||
use Framework\Module;
|
use Framework\Module;
|
||||||
use Framework\Renderer\RendererInterface;
|
use Framework\Renderer\RendererInterface;
|
||||||
use Framework\Router;
|
use Framework\Router;
|
||||||
|
@ -16,9 +15,8 @@ class GmarcheModule extends Module
|
||||||
const MIGRATIONS = __DIR__ . '/db/migrations';
|
const MIGRATIONS = __DIR__ . '/db/migrations';
|
||||||
const SEEDS = __DIR__ . '/db/seeds';
|
const SEEDS = __DIR__ . '/db/seeds';
|
||||||
|
|
||||||
public function __construct(ContainerInterface $container, Auth $auth)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
$this->auth = $auth;
|
|
||||||
$gmarchePrefix = $container->get('gmarche.prefix');
|
$gmarchePrefix = $container->get('gmarche.prefix');
|
||||||
$container->get(RendererInterface::class)->addPath('gmarche', __DIR__ . '/views');
|
$container->get(RendererInterface::class)->addPath('gmarche', __DIR__ . '/views');
|
||||||
$router = $container->get(Router::class);
|
$router = $container->get(Router::class);
|
||||||
|
|
|
@ -61,23 +61,36 @@
|
||||||
<div class="navbar-text" style="color:lightgray;margin-right:15px; margin-top:3px;">
|
<div class="navbar-text" style="color:lightgray;margin-right:15px; margin-top:3px;">
|
||||||
{{ "now"|date('d/m/y') }}
|
{{ "now"|date('d/m/y') }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if affiche_username() != '' %}
|
{% if affiche_username() != '' %}
|
||||||
<form method="post" style="margin-top:5px;" action="{{ path('account.profil') }}">
|
<form method="post" style="margin-top:5px;" action="{{ path('account.profil',{user:affiche_username()}) }}">
|
||||||
<span><img src="\avatar_user.png" width="22" height="22" /></span>
|
<span><img src="\avatar_user.png" width="22" height="22" /></span>
|
||||||
<button id="nom_connecte" style="color:white;font-size: 14px;" class="btn-primary">{{ affiche_username() }}</button>
|
<button id="nom_connecte_bis" style="color:white;font-size: 14px;" class="btn-primary">{{ affiche_username() }}</button>
|
||||||
|
<div style="width:0;height:0;">
|
||||||
|
{{ field('email', affiche_mail(), "", {type: 'hidden'}) }}
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<form method="post" action="{{ path('auth.logout') }}">
|
<form method="post" action="{{ path('auth.logout') }}">
|
||||||
<!-- csrf_input() }}-->
|
<!-- csrf_input() }}-->
|
||||||
<button class="btn btn-danger" style="margin-left: 7px; font-size:14px;">Se déconnecter</button>
|
<button class="btn btn-danger" style="margin-left: 7px; font-size:14px;">Se déconnecter</button>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
<form method="post" style="margin-top:5px;" action="{{ path('account.profil',{user:'nox'}) }}">
|
||||||
|
<div class="nav-item" id="avatar-user" style="display:none;padding-top:0.5rem;margin-right:0.4rem;">
|
||||||
|
</div>
|
||||||
|
<div class="nav-item" id="user-connecte" style="display:none;padding-top:0.4rem;">
|
||||||
|
<button style="color:white; font-size: 14px;" class="btn-primary" data-toggle="modal" data-target="#connexion_modal">
|
||||||
|
<span id="contenu_bouton"></span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
<div class="nav-item" id="bouton-connexion">
|
<div class="nav-item" id="bouton-connexion">
|
||||||
<button style="color:white; font-size: 14px;" class="btn btn-primary" data-toggle="modal" data-target="#connexion_modal">Se connecter</button>
|
<button style="color:white; font-size: 14px;" class="btn btn-primary" data-toggle="modal" data-target="#connexion_modal">SE CONNECTER</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="deconnexion" style="display:none;">
|
<div id="deconnexion" style="display:none;">
|
||||||
<form method="post" action="{{ path('auth.logout') }}">
|
<form method="post" action="{{ path('auth.logout') }}">
|
||||||
<!-- csrf_input() }}-->
|
<!-- csrf_input() }}-->
|
||||||
<button class="btn btn-danger" style="font-size:14px;">Se déconnecter</button>
|
<button class="btn btn-danger" style="font-size:14px;margin-left:0.5rem;">Se déconnecter</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="nav-item" id="inscription">
|
<div class="nav-item" id="inscription">
|
||||||
|
|
Loading…
Reference in New Issue