Browse Source

Ajout de la recherche. Modif des redirections de login

master
Dark-Storm 8 months ago
parent
commit
a51f2265b1
Signed by: Dark-Storm <l.gatin@neuf.fr> GPG Key ID: F61F10FA138E797C

+ 10
- 0
app/forms.py View File

@@ -60,3 +60,13 @@ class UpdateAccountForm(FlaskForm):
newsletter = BooleanField('Inscription à la newsletter', description='Un mail par trimestre environ, pour être prévenu des concours, évènements et nouveautés.')
old_password = PasswordField('Ancien mot de passe :', validators=[DataRequired(), verify_authentication])
submit = SubmitField('Mettre à jour')

# TODO: compléter le formulaire de recherche avancée
class AdvancedSearchForm(FlaskForm):
q = StringField('Rechercher :', validators=[DataRequired()])
date = DateField('Date', validators=[Optional()])
submit = SubmitField('Affiner la recherche')

class SearchForm(FlaskForm):
q = StringField('Rechercher', validators=[DataRequired()])

+ 26
- 11
app/routes.py View File

@@ -2,7 +2,7 @@ from flask import render_template, flash, redirect, url_for, request
from flask_login import login_user, logout_user, current_user, login_required
from werkzeug.urls import url_parse
from app import app, db
from app.forms import LoginForm, RegistrationForm, UpdateAccountForm
from app.forms import LoginForm, RegistrationForm, UpdateAccountForm, SearchForm, AdvancedSearchForm
from app.models.users import Member

# Ce truc c'est la vie !
@@ -13,7 +13,9 @@ def _render_template(*args, **kwargs):
# return render_template(*args, **kwargs, login_form=login_form)
# return render_template(*args, **kwargs)
login_form = LoginForm()
return render_template(*args, **kwargs, login_form=login_form)
search_form = SearchForm()
return render_template(*args, **kwargs,
login_form=login_form, search_form=search_form)


@app.route('/')
@@ -23,17 +25,24 @@ def index():

@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'GET':
return redirect(url_for('index'))
login_form = LoginForm()
if login_form.validate_on_submit():
member = Member.query.filter_by(name=login_form.username.data).first()
if member is None or not member.check_password(login_form.password.data):
form = LoginForm()
if form.validate_on_submit():
member = Member.query.filter_by(name=form.username.data).first()
if member is None or not member.check_password(form.password.data):
flash('Pseudo ou mot de passe invalide', 'error')
return redirect(request.referrer)
login_user(member, remember=login_form.remember_me.data)
login_user(member, remember=form.remember_me.data)
flash('Connexion réussie', 'info')
return redirect(request.referrer)
r = request.args.get('next')
if r:
# TODO : prevent OpenRedirect security issues
return redirect(r)
else:
try:
return redirect(request.referer)
except:
return redirect(url_for('index'))
return _render_template('login.html', form=form)

@app.route('/logout')
def logout():
@@ -44,9 +53,10 @@ def logout():

@app.route('/account', methods=['GET', 'POST'])
def account():
# TODO: utiliser le décorateur @login_required
if not current_user.is_authenticated:
flash('Veuillez vous authentifier', 'warning')
return redirect(url_for('index'))
return redirect(url_for('login', next=url_for('account')))
form = UpdateAccountForm()
if request.method == "POST":
if form.validate_on_submit():
@@ -83,3 +93,8 @@ def validation():
if current_user.is_authenticated :
return redirect(url_for('index'))
return _render_template('validation.html')

@app.route('/search')
def search():
form = AdvancedSearchForm()
return _render_template('search.html', form=form)

+ 0
- 49
app/static/css/register.css View File

@@ -1,49 +0,0 @@
#register {
width: 30%; min-width: 350px;
margin: auto;
}

#register form > div {
margin-bottom: 15px;
}

#register form > div > label {
display: inline-block;
margin-bottom: 5px;
}

#register form > div > input[type='text'],
#register form > div > input[type='email'],
#register form > div > input[type='date'],
#register form > div > input[type='password'],
#register form > div > textarea {
display: block;
width: 100%; padding: 6px 2.5%;
border: 1px solid #abcdef;
}
#register form > div > input[type='text']:focus,
#register form > div > input[type='email']:focus,
#register form > div > input[type='date']:focus,
#register form > div > input[type='password']:focus,
#register form > div > textarea:focus {
box-shadow: 0 0 4px rgba(0, 102, 255, .9);
}

#register input[type="submit"] {
width: 100%;
background-color: #149641;
border-color: #0e692d;
color: #ffffff;
}
#register input[type="submit"]:hover,
#register input[type="submit"]:focus,
#register input[type="submit"]:active {
background-color: #0f7331;
border-color: #073617;
}

#register form .msgerror {
color: red;
font-weight: 400;
margin-top: 5px;
}

+ 0
- 2
app/templates/base/head.html View File

@@ -13,6 +13,4 @@
<link rel="stylesheet" media="all and (min-width: 700px)" type="text/css" href={{url_for('static', filename = 'css/flash.css')}}>
<link rel="stylesheet" media="all and (min-width: 700px)" type="text/css" href={{url_for('static', filename = 'css/responsive.css')}}>
<link rel="stylesheet" media="all and (max-width: 699px)" type="text/css" href={{url_for('static', filename = 'css/light.css')}}>

<link rel="stylesheet" media="all and (min-width: 700px)" type="text/css" href={{url_for('static', filename = 'css/register.css')}}>
</head>

+ 2
- 2
app/templates/base/header.html View File

@@ -1,6 +1,6 @@
<header>
<form>
<input type="search" placeholder="Recherche" />
<form action={{url_for('search')}} method="get">
<input type="search" name="q" id="q" placeholder="{{search_form.label}}" />
<a role="button" onclick="this.parentNode.submit();" href="#" class="light-hidden">
<svg viewBox="0 0 24 24">
<path fill="#adb0b4"d="M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z"></path>

+ 1
- 1
app/templates/base/navbar/account.html View File

@@ -49,7 +49,7 @@
<h2>
Invité
</h2>
<form method="post" action="/login" class="login">
<form method="post" action="{{url_for('login')}}" class="login">
{{ login_form.hidden_tag() }}
{{ login_form.username(size=32, placeholder="Identifiant") }}
{{ login_form.password(size=32, placeholder="Mot de passe") }}

+ 23
- 21
app/templates/login.html View File

@@ -1,25 +1,27 @@
{% extends "container.html" %}
{% extends "base/container.html" %}

{% block content %}
<h1>Sign In</h1>
<form action="" method="post">
{{ login_form.hidden_tag() }}
<p>
{{ login_form.username.label }}<br>
{{ login_form.username(size=32) }}<br>
{% for error in login_form.username.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</p>
<p>
{{ login_form.password.label }}<br>
{{ login_form.password(size=32) }}<br>
{% for error in login_form.password.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</p>
<p>{{ login_form.remember_me() }} {{ login_form.remember_me.label }}</p>
<p>{{ login_form.submit() }}</p>
<section class="form" style="width:40%;">
<h1>Sign In</h1>
<form action="" method="post">
{{ form.hidden_tag() }}
<p>
{{ form.username.label }}<br>
{{ form.username(size=32) }}<br>
{% for error in form.username.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</p>
<p>
{{ form.password.label }}<br>
{{ form.password(size=32) }}<br>
{% for error in form.password.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</p>
<p>{{ form.remember_me() }} {{ form.remember_me.label }}</p>
<p>{{ form.submit() }}</p>
</form>
<p>New User? <a href="{{ url_for('register') }}">Click to Register!</a></p>
</form>
<p>New User? <a href="{{ url_for('register') }}">Click to Register!</a></p>
{% endblock %}

+ 19
- 0
app/templates/search.html View File

@@ -0,0 +1,19 @@
{% extends "base/container.html" %}

{% block content %}
<section class="form" style="width:80%;">
<h1>Recherche avancée :</h1>

<form action="" method="post">
<div>
{{ form.q.label }}
{{ form.q(value=request.args.get('q')) }}
</div>
<div>
{{ form.date.label }}
{{ form.date }}
</div>
<div>{{ form.submit(class_="bg-green") }}</div>
</form>
</section>
{% endblock %}

Loading…
Cancel
Save