From bedac53e29fc2101d50aeb938855fafb299b0555 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Mon, 30 May 2022 14:19:16 -0700 Subject: [PATCH] Fix missing PGP keys when early login. Fix avatar not found when make/book is clicked. --- api/logics.py | 8 ++++---- api/views.py | 7 +++---- frontend/src/components/BottomBar.js | 6 +++--- frontend/src/components/UserGenPage.js | 8 ++++---- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/api/logics.py b/api/logics.py index f1d92e66..978898c4 100644 --- a/api/logics.py +++ b/api/logics.py @@ -102,12 +102,12 @@ class Logics: try: import_pub_result = gpg.import_keys(pub_key) pub_key = gpg.export_keys(import_pub_result.fingerprints[0]) - except: + except Exception as e: return ( False, { "bad_request": - "Your PGP public key does not seem valid" + f"Your PGP public key does not seem valid. Exception: {str(e)}" }, None, None) @@ -115,12 +115,12 @@ class Logics: # Try to import the encrypted private key (without passphrase) try: import_priv_result = gpg.import_keys(enc_priv_key) - except: + except Exception as e: return ( False, { "bad_request": - "Your PGP private key does not seem valid" + f"Your PGP private key does not seem valid. Exception: {str(e)}" }, None, None) diff --git a/api/views.py b/api/views.py index dcb51bd0..446389b0 100644 --- a/api/views.py +++ b/api/views.py @@ -718,12 +718,11 @@ class UserView(APIView): user = authenticate(request, username=nickname, password=token_sha256) if user is not None: login(request, user) + context["public_key"] = user.profile.public_key + context["encrypted_private_key"] = user.profile.encrypted_private_key # Sends the welcome back message, only if created +3 mins ago - if request.user.date_joined < (timezone.now() - - timedelta(minutes=3)): + if request.user.date_joined < (timezone.now() - timedelta(minutes=3)): context["found"] = "We found your Robot avatar. Welcome back!" - context["public_key"] = user.profile.public_key - context["encrypted_private_key"] = user.profile.encrypted_private_key return Response(context, status=status.HTTP_202_ACCEPTED) else: # It is unlikely, but maybe the nickname is taken (1 in 20 Billion chance) diff --git a/frontend/src/components/BottomBar.js b/frontend/src/components/BottomBar.js index 36ea15bb..c6cb8388 100644 --- a/frontend/src/components/BottomBar.js +++ b/frontend/src/components/BottomBar.js @@ -61,7 +61,7 @@ class BottomBar extends Component { this.setState(null) fetch('/api/info/') .then((response) => response.json()) - .then((data) => this.setState(data) + .then((data) => this.setState(data) & console.log(data) & this.setState({active_order_id: data.active_order_id ? data.active_order_id : null, last_order_id: data.last_order_id ? data.last_order_id : null}) & this.props.setAppState({nickname:data.nickname, loading:false})); @@ -130,7 +130,7 @@ bottomBarDesktop =()=>{ -
+
{ -
+
diff --git a/frontend/src/components/UserGenPage.js b/frontend/src/components/UserGenPage.js index a2434938..4dae0e63 100644 --- a/frontend/src/components/UserGenPage.js +++ b/frontend/src/components/UserGenPage.js @@ -227,7 +227,7 @@ class UserGenPage extends Component { saveAsJson(this.state.nickname+'.json', this.createJsonFile())} > @@ -238,7 +238,7 @@ class UserGenPage extends Component { (navigator.clipboard.writeText(getCookie('robot_token')) & this.props.setAppState({copiedToken:true}))} > @@ -275,10 +275,10 @@ class UserGenPage extends Component { - + - +