Skip to content

Commit e9d6bfb

Browse files
authored
Merge pull request #228 from Seluj78/feature/openapi-doc
2 parents a188b9e + 2b6eb56 commit e9d6bfb

File tree

7 files changed

+1707
-16
lines changed

7 files changed

+1707
-16
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## API Docs:
2+
3+
```
4+
docker run -p 80:8080 -e SWAGGER_JSON=/foo/swagger.yaml -v app:/foo swaggerapi/swagger-ui
5+
```

backend/PyMatcha/routes/api/auth/password.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def forgot_password():
5555
pass
5656
else:
5757
token = generate_confirmation_token(email=data["email"], token_type="reset")
58-
link = os.getenv("APP_URL") + "/auth/password/forgot/" + token
58+
# link = os.getenv("APP_URL") + "/auth/password/forgot/" + token
59+
link = f"{os.getenv('FRONT_URL')}/accounts/password/reset?token={token}"
5960
rendered_html = render_template("password_reset.html", link=link)
6061
current_app.logger.debug("/auth/password/forgot -> Sending worker request to send email")
6162
send_mail_html.delay(dest=data["email"], subject="Reset your password on PyMatcha", html=rendered_html)
@@ -96,3 +97,20 @@ def reset_password():
9697
u.save()
9798
current_app.logger.debug("/auth/password/reset -> Password reset successfully")
9899
return Success("Password reset successful.")
100+
101+
102+
@auth_password_bp.route("/auth/password/check_token", methods=["POST"])
103+
@validate_params({"token": str})
104+
def check_token_validity():
105+
data = request.get_json()
106+
try:
107+
confirm_token(data["token"], expiration=7200)
108+
except (SignatureExpired, BadSignature) as e:
109+
if e == SignatureExpired:
110+
current_app.logger.debug("/auth/password/reset -> Signature Expired")
111+
raise BadRequestError("Signature Expired.", "Request another password reset and try again.")
112+
else:
113+
current_app.logger.debug("/auth/password/reset -> Bad Signature")
114+
raise BadRequestError("Bad Signature.", "Request another password reset and try again.")
115+
else:
116+
return Success("Reset token is correct")

backend/PyMatcha/routes/api/messages.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def unlike_message(message_id):
148148
def get_new_messages():
149149
message_list = Message.get_multis(to_id=current_user.id, is_seen=False)
150150
if not message_list:
151-
return Success("No new messages.")
152-
new_messages = [m.to_dict() for m in message_list]
151+
new_messages = []
152+
else:
153+
new_messages = [m.to_dict() for m in message_list]
153154
return SuccessOutput("new_messages", new_messages)

backend/PyMatcha/routes/api/recommendations.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
You should have received a copy of the GNU General Public License
1717
along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
"""
19+
import json
20+
1921
from flask import Blueprint
2022
from flask_jwt_extended import current_user
2123
from flask_jwt_extended import jwt_required
@@ -32,4 +34,4 @@ def get_recommendations():
3234
recommendations = redis.get(f"user_recommendations:{str(current_user.id)}")
3335
if not recommendations:
3436
raise NotFoundError("Recommendations not calculated yet", "Please come back later")
35-
return SuccessOutput("recommendations", recommendations)
37+
return SuccessOutput("recommendations", json.loads(recommendations))

backend/PyMatcha/utils/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def update_user_recommendations():
107107
for user_to_update in User.select_all():
108108
count += 1
109109
user_to_update_recommendations = []
110-
110+
# TODO: Find a way to bypass that
111111
if not user_to_update.birthdate:
112112
continue
113113
if not user_to_update.geohash:

0 commit comments

Comments
 (0)