This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from flask_mail import Message | |
from utils.common import TokenGenerator | |
from server import mail | |
def send_forgot_password_email(request, user): | |
""" | |
It sends an email to the user with a link to reset their password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask_restful import Api | |
from users.views import LoginApi, ForgotPassword, SignUpApi, ResetPassword | |
def create_authentication_routes(api: Api): | |
"""Adds resources to the api. | |
:param api: Flask-RESTful Api Object | |
""" | |
api.add_resource(SignUpApi, "/api/auth/register/") | |
api.add_resource(LoginApi, "/api/auth/login/") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import jwt | |
import datetime | |
from server import db | |
from os import environ | |
from users.helper import send_forgot_password_email | |
from users.models import User | |
from flask_bcrypt import generate_password_hash | |
from utils.common import generate_response, TokenGenerator | |
from users.validation import ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from marshmallow import Schema, fields, validate | |
# "This class defines the input schema for the CreateSignup mutation. It requires a username, email, | |
# and password. The username must be at least 4 characters long, and the password must be at least 6 | |
# characters long." | |
# | |
# The input schema is used to validate the input data before it is passed to the mutation | |
class CreateSignupInputSchema(Schema): | |
# the 'required' argument ensures the field exists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import jwt | |
from datetime import datetime, timedelta, timezone | |
from utils.http_code import HTTP_200_OK, HTTP_201_CREATED | |
def generate_response(data=None, message=None, status=400): | |
""" | |
It takes in a data, message, and status, and returns a dictionary with the data, message, and status | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Descriptive HTTP status codes, for code readability. | |
""" | |
def is_informational(code): | |
return 100 <= code <= 199 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Response | |
from flask_restful import Resource | |
from flask import request, make_response | |
from users.service import create_user, reset_password_email_send, login_user, reset_password | |
class SignUpApi(Resource): | |
@staticmethod | |
def post() -> Response: | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""App entry point.""" | |
"""Initialize Flask app.""" | |
import os | |
from flask import Flask | |
from flask_restful import Api | |
from flask_sqlalchemy import SQLAlchemy | |
from flask_mail import Mail | |
db = SQLAlchemy() | |
mail = Mail() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Data models.""" | |
import datetime | |
from flask_bcrypt import generate_password_hash, check_password_hash | |
from flask_sqlalchemy import SQLAlchemy | |
from server import db | |
# The User class is a data model for user accounts | |
class User(db.Model): | |
"""Data model for user accounts.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Initialize Flask app.""" | |
from flask import Flask | |
from flask_sqlalchemy import SQLAlchemy | |
db = SQLAlchemy() | |
def create_app(): | |
"""Construct the core application.""" | |
app = Flask(__name__, instance_relative_config=False) |
NewerOlder