diff --git a/app/routes.py b/app/routes.py index bd7aa16..86070ac 100644 --- a/app/routes.py +++ b/app/routes.py @@ -6,7 +6,7 @@ import subprocess import threading import urllib.parse -from flask import Blueprint, render_template, request, make_response, session, redirect, jsonify, Response +from flask import Blueprint, render_template, request, make_response, session, redirect, jsonify, Response, current_app from wtforms import Form, SelectField, StringField, TextAreaField, validators from email_validator import validate_email, EmailNotValidError @@ -155,6 +155,9 @@ def logout() -> Response: return redirect('/') +FREE_TIER_TEMPLATES = 2 + + @writing_blueprint.route('/add_letter') def add_letter() -> Response: email_address = session.get('username') @@ -163,6 +166,8 @@ def add_letter() -> Response: user = db.get_user(email_address) existing_letter_count = len(db.get_user_letters(user.id)) + if user.in_free_tier() and existing_letter_count >= FREE_TIER_TEMPLATES: + return render_index(error=f'A maximum of {FREE_TIER_TEMPLATES} templates are available to each user.') new_letter_name = f'Letter{existing_letter_count + 1}' default_form_json = jsonify(CLForm().to_cl_data()).get_data(True) db.add_letter(user.id, new_letter_name, default_form_json)