From 734cd8e6e51ab563a3b15e2b7dfd5c86836deff0 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 28 Dec 2021 12:45:33 +0100 Subject: [PATCH 1/8] export SECRET_KEY required by Flask-WTF (CSRF) --- .github/workflows/flask.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml index bb192c94..ccc4a798 100644 --- a/.github/workflows/flask.yml +++ b/.github/workflows/flask.yml @@ -66,6 +66,7 @@ jobs: - name: Run Tests run: | + export SECRET_KEY=`python3 -c 'import secrets; print(secrets.token_hex())'` source env/bin/activate coverage run --source='ereuse_devicehub' env/bin/pytest -m mvp --maxfail=5 tests/ coverage report --include='ereuse_devicehub/*' From 43b5a67caba17aebd54c08ec75842795761be530 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 28 Dec 2021 13:05:41 +0100 Subject: [PATCH 2/8] Create logout view --- .../templates/ereuse_devicehub/base_site.html | 14 ++------------ ereuse_devicehub/views.py | 9 ++++++++- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html index b68d5635..d1c50e43 100644 --- a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html +++ b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html @@ -185,7 +185,7 @@
  • - + My Profile @@ -194,16 +194,6 @@
  • -
  • - - - Account Settings - -
  • -
  • - -
  • -
  • @@ -215,7 +205,7 @@
  • - + Sign Out diff --git a/ereuse_devicehub/views.py b/ereuse_devicehub/views.py index 3c5b28d0..84397ce7 100644 --- a/ereuse_devicehub/views.py +++ b/ereuse_devicehub/views.py @@ -1,7 +1,7 @@ import flask from flask import Blueprint from flask.views import View -from flask_login import login_required, login_user +from flask_login import login_required, login_user, logout_user from ereuse_devicehub.forms import LoginForm from ereuse_devicehub.resources.user.models import User @@ -32,6 +32,12 @@ class LoginView(View): return flask.render_template('ereuse_devicehub/user_login.html', form=form) +class LogoutView(View): + def dispatch_request(self): + logout_user() + return flask.redirect(flask.url_for('core.login')) + + class UserProfileView(View): decorators = [login_required] template_name = 'ereuse_devicehub/user_profile.html' @@ -42,4 +48,5 @@ class UserProfileView(View): core.add_url_rule('/login/', view_func=LoginView.as_view('login')) +core.add_url_rule('/logout/', view_func=LogoutView.as_view('logout')) core.add_url_rule('/profile/', view_func=UserProfileView.as_view('user-profile')) From a9515dce139b8915a13874e863ecd9243f5c2c35 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 28 Dec 2021 13:26:56 +0100 Subject: [PATCH 3/8] Print current_user info & drop topbar unused elements --- ereuse_devicehub/resources/user/models.py | 6 + ereuse_devicehub/static/img/profile-img.jpg | Bin 4957 -> 0 bytes .../templates/ereuse_devicehub/base_site.html | 148 +----------------- .../ereuse_devicehub/user_profile.html | 12 +- ereuse_devicehub/views.py | 6 +- 5 files changed, 15 insertions(+), 157 deletions(-) delete mode 100644 ereuse_devicehub/static/img/profile-img.jpg diff --git a/ereuse_devicehub/resources/user/models.py b/ereuse_devicehub/resources/user/models.py index c9d3fef7..70f14e00 100644 --- a/ereuse_devicehub/resources/user/models.py +++ b/ereuse_devicehub/resources/user/models.py @@ -71,6 +71,12 @@ class User(UserMixin, Thing): """Alias because flask-login expects `is_active` attribute""" return self.active + @property + def get_full_name(self): + # TODO(@slamora) create first_name & last_name fields and use + # them to generate user full name + return self.email + def check_password(self, password): # take advantage of SQL Alchemy PasswordType to verify password return self.password == password diff --git a/ereuse_devicehub/static/img/profile-img.jpg b/ereuse_devicehub/static/img/profile-img.jpg deleted file mode 100644 index 16ac22904218c0ab01136463638b24715503874e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4957 zcmb7IWmMGP*8UAMbPg~y(hUko2n;dQ&<%=&2nsTUG)OlxbcjewcS=YoDIq0|l%ya- zr}X82?|s*L*Zb|=XMcOvK5L)#JnK1UpWB(+C4fv#Syd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