{% extends 'base.html.twig' %}
{% block title %}Log in!{% endblock %}
{% block body %}
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
{{ include('_header.html.twig') }}
<form method="post" action="{{ path('app_login') }}">
{% if error %}
<div class="alert alert-danger">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}
{% if app.user %}
<div class="mb-3">
Vous êtes déjà connecté en tant que {{ app.user.userIdentifier }}, <a href="{{ path('app_logout') }}">Logout</a>
</div>
{% endif %}
<h1 class="h3 mb-3 font-weight-normal">Connection</h1>
<label for="inputEmail">Email</label>
<input type="email" value="{{ last_username }}" name="email" id="inputEmail" class="form-control" autocomplete="email" required autofocus>
<label for="inputPassword">Mot de passe</label>
<input type="password" name="password" id="inputPassword" class="form-control" autocomplete="current-password" required>
<input type="hidden" name="_csrf_token"
value="{{ csrf_token('authenticate') }}"
>
<div class="checkbox mb-3">
<label>
<input type="checkbox" name="_remember_me"> Remember me
</label>
</div>
<button class="btn btn-lg btn-primary mt-2" type="submit">
Se connecter
</button>
</form>
<div class="mt-3">
<button class="btn btn-lg btn-primary" onclick="forgotPassword()">
Mot de passe oublié ?
</button>
</div>
{{ include('_footer.html.twig') }}
{% endblock %}
{% block javascripts %}
<script>
$(document).ready(function() {
// check if error in url
const urlParams = new URLSearchParams(window.location.search);
const error = urlParams.get('error');
if(error == 'Email inconnu') {
Swal.fire({
icon: 'error',
title: 'Email inconnu !',
text: 'Veuillez rensigner un email d\' un compte existant pour vous demander un nouveau mot de passe.',
})
}
});
function forgotPassword() {
var email = $('#inputEmail').val();
if(email == '') {
Swal.fire({
icon: 'error',
title: 'Email manquant !',
text: 'Veuillez rensigner un email pour vous demander un nouveau mot de passe.',
})
} else {
// redirect to app_password_reset path with email
window.location.href = "{{ path('app_password_reset') }}?email=" + encodeURIComponent(email);
}
}
</script>
{% endblock %}