Commit a49732b54352c411881769940013e4aa89713c92
1 parent
0d4479a4
Exists in
master
and in
4 other branches
Add current user to base page
Showing
5 changed files
with
34 additions
and
30 deletions
Show diff stats
app/auth/routes.py
... | ... | @@ -16,6 +16,7 @@ def login_post(): |
16 | 16 | user_password = request.form.get('password') |
17 | 17 | user_remember = request.form.get('remember') |
18 | 18 | user = User.query.filter_by(login=user_login).one_or_none() |
19 | + print("user login: {}, user password: {}".format(user.login, user.password)) | |
19 | 20 | if user and user.password == user_password: |
20 | 21 | # login code goes here |
21 | 22 | login_user(user) | ... | ... |
app/auth/templates/login.html
... | ... | @@ -5,18 +5,19 @@ |
5 | 5 | <link href="{{ url_for('auth.static', filename='signin.css') }}" rel="stylesheet" type="text/css"/> |
6 | 6 | </head> |
7 | 7 | <body class="text-center"> |
8 | - <form class="form-signin" method="POST" action="{{ url_for('auth.login')}}"> | |
8 | + <form action="{{ url_for('auth.login')}}" class="form-signin" method="POST"> | |
9 | + {% include 'flash-messages.html' %} | |
9 | 10 | |
10 | 11 | <img class="mb-4" height="72" src="{{ url_for('static', filename='img/pdc.png') }}" width="72"> |
11 | 12 | <h1 class="h3 font-weight-normal mb-3">Connectez vous</h1> |
12 | 13 | <label class="sr-only" for="login">Email Adress</label> |
13 | - <input autofocus class="form-control" name="login" id="login" placeholder="identifiant" required > | |
14 | + <input autofocus class="form-control" id="login" name="login" placeholder="identifiant" required> | |
14 | 15 | <label class="sr-only" for="password">Password</label> |
15 | - <input class="form-control" name="password" id="password" placeholder="mot de passe" required type="password"> | |
16 | + <input class="form-control" id="password" name="password" placeholder="mot de passe" required type="password"> | |
16 | 17 | |
17 | 18 | <div class="checkbox my-3"> |
18 | - <label class="text-muted" data-toggle="tooltip" data-placement="top" title="désactivé"> | |
19 | - <input type="checkbox" id="remember" name="remember" value="true" disabled > Se souvenir de moi | |
19 | + <label class="text-muted" data-placement="top" data-toggle="tooltip" title="désactivé"> | |
20 | + <input disabled id="remember" name="remember" type="checkbox" value="true"> Se souvenir de moi | |
20 | 21 | </label> |
21 | 22 | </div> |
22 | 23 | |
... | ... | @@ -26,6 +27,6 @@ |
26 | 27 | {% include 'copy.html' %} |
27 | 28 | </div> |
28 | 29 | </form> |
29 | -{% include 'bs4-scripts.html' %} | |
30 | + {% include 'bs4-scripts.html' %} | |
30 | 31 | </body> |
31 | 32 | </html> | ... | ... |
app/cli/__init__.py
... | ... | @@ -16,7 +16,7 @@ def delete(user_id): |
16 | 16 | @bp.cli.command('create_db') |
17 | 17 | def create(): |
18 | 18 | db.create_all() |
19 | - admin = User(email='groz@free.fr', name='richard', password='1champ1') | |
19 | + admin = User(email='groz@free.fr', name='richard', login='richard', password='1champ1') | |
20 | 20 | db.session.add(admin) |
21 | 21 | db.session.commit() |
22 | 22 | |
... | ... | @@ -34,20 +34,15 @@ def add(email, name, password): |
34 | 34 | |
35 | 35 | @bp.cli.command('show_all') |
36 | 36 | def show_all(): |
37 | - print("{:<5} {:<15} {:<15} {:<15}".format('id', 'name', 'passwd', 'email')) | |
38 | - print("{:<5} {:<15} {:<15} {:<15}".format('-' * 5, '-' * 15, '-' * 15, '-' * 15)) | |
37 | + print("{:<5} {:<15} {:<15} {:<15} {:<15}".format('id', 'name', 'login', 'passwd', 'email')) | |
38 | + print("{:<5} {:<15} {:<15} {:<15} {:<15}".format('-' * 5, '-' * 15, '-' * 15, '-' * 15, '-' * 15)) | |
39 | 39 | for user in User.query.all(): |
40 | - print("{:<5} {:<15} {:<15} {:<15}".format( | |
40 | + print(user.login) | |
41 | + print("{:<5} {:<15} {:<15} {:<15} {:<15}".format( | |
41 | 42 | user.id, |
42 | 43 | user.name, |
44 | + user.login, | |
43 | 45 | user.password, |
44 | 46 | user.email |
45 | 47 | )) |
46 | 48 | |
47 | - | |
48 | -@bp.cli.command('create') | |
49 | -def create(): | |
50 | - db.create_all() | |
51 | - admin = User(email='groz@free.fr', name='richard', password='1champ1') | |
52 | - db.session.add(admin) | |
53 | - db.session.commit() | ... | ... |
app/templates/base_page.html
... | ... | @@ -8,9 +8,16 @@ |
8 | 8 | |
9 | 9 | <nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0"> |
10 | 10 | <a class="navbar-brand col-sm-3 col-md-2 mr-0" href="#">Plan de Charges</a> |
11 | + {% if not current_user.is_anonymous %} | |
11 | 12 | <ul class="navbar-nav px-3"> |
12 | 13 | <li class="nav-item text-nowrap"> |
13 | - <a class="nav-link" href="{{ url_for('auth.login') }}">Sign out</a> | |
14 | + <a class="nav-link" >Bienvenue {{current_user.name}}</a> | |
15 | + </li> | |
16 | + </ul> | |
17 | + {% endif %} | |
18 | + <ul class="navbar-nav px-3"> | |
19 | + <li class="nav-item text-nowrap"> | |
20 | + <a class="nav-link" href="{{ url_for('auth.login') }}">Déconnecter</a> | |
14 | 21 | </li> |
15 | 22 | </ul> |
16 | 23 | </nav> |
... | ... | @@ -105,18 +112,9 @@ |
105 | 112 | </nav> |
106 | 113 | |
107 | 114 | <main class="container" role="main"> |
108 | - {% with messages = get_flashed_messages(with_categories=true) %} | |
109 | - {% if messages %} | |
110 | - <div id="messages"> | |
111 | - {% for level, message in messages %} | |
112 | - <div class="alert alert-{{level}}" role="alert">{{ message }}</div> | |
113 | - {% endfor %} | |
114 | - </div> | |
115 | - {% endif %} | |
116 | - {% endwith %} | |
117 | - | |
118 | - {%block content%} | |
119 | - {%endblock%} | |
115 | + {% include 'flash-messages.html' %} | |
116 | + {% block content %} | |
117 | + {% endblock %} | |
120 | 118 | </main> |
121 | 119 | |
122 | 120 | </div> | ... | ... |
... | ... | @@ -0,0 +1,9 @@ |
1 | + {% with messages = get_flashed_messages(with_categories=true) %} | |
2 | + {% if messages %} | |
3 | + <div id="messages"> | |
4 | + {% for level, message in messages %} | |
5 | + <div class="alert alert-{{level}}" role="alert">{{ message }}</div> | |
6 | + {% endfor %} | |
7 | + </div> | |
8 | + {% endif %} | |
9 | + {% endwith %} | ... | ... |