diff --git a/README.md b/README.md index 22c8e222..3f4552d8 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,12 @@ A lemmy/kbin clone written in Python with Flask. - Clean, simple code. - Easy setup, easy to manage - few dependencies and extra software required. - GPL. + +## Contributing + +Join our Maxtrix channel. + +Report bugs in our issue queue. + +If submitting a substantial PR, communicate your intentions to the maintainer(s) before investing your effort into coding. +This is to ensure your contribution will fit well with the rest of the code base. \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py index 8a4a0340..0909cd47 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -50,6 +50,9 @@ def create_app(config_class=Config): from app.activitypub import bp as activitypub_bp app.register_blueprint(activitypub_bp) + from app.auth import bp as auth_bp + app.register_blueprint(auth_bp, url_prefix='/auth') + def get_resource_as_string(name, charset='utf-8'): with app.open_resource(name) as f: return f.read().decode(charset) diff --git a/app/auth/email.py b/app/auth/email.py index ea1fadfe..3c24f91b 100644 --- a/app/auth/email.py +++ b/app/auth/email.py @@ -20,3 +20,11 @@ def send_welcome_email(user): recipients=[user.email], text_body=render_template('email/welcome.txt', user=user), html_body=render_template('email/welcome.html', user=user)) + + +def send_verification_email(user): + send_email(_('Please verify your email address'), + sender='PyFedi ', + recipients=[user.email], + text_body=render_template('email/verification.txt', user=user), + html_body=render_template('email/verification.html', user=user)) \ No newline at end of file diff --git a/app/auth/forms.py b/app/auth/forms.py index 6e2e3437..2d9ec1d2 100644 --- a/app/auth/forms.py +++ b/app/auth/forms.py @@ -2,7 +2,7 @@ from flask_wtf import FlaskForm from wtforms import StringField, PasswordField, SubmitField, HiddenField from wtforms.validators import ValidationError, DataRequired, Email, EqualTo, Length from flask_babel import _, lazy_gettext as _l -from app.models import User +from app.models import User, Community from app.auth.recaptcha3 import Recaptcha3Field @@ -22,13 +22,21 @@ class RegistrationForm(FlaskForm): EqualTo('password')]) recaptcha = Recaptcha3Field(action="TestAction", execute_on_load=True) - submit = SubmitField(_l('Sign up')) + submit = SubmitField(_l('Register')) def validate_real_email(self, email): user = User.query.filter_by(email=email.data).first() if user is not None: raise ValidationError(_('An account with this email address already exists.')) + def validate_user_name(self, user_name): + user = User.query.filter_by(user_name=user_name.data).first() + if user is not None: + raise ValidationError(_('An account with this user name already exists.')) + community = Community.query.filter_by(name=user_name.data).first() + if community is not None: + raise ValidationError(_('A community with this name exists so it cannot be used for a user.')) + class ResetPasswordRequestForm(FlaskForm): email = StringField(_l('Email'), validators=[DataRequired(), Email()]) diff --git a/app/auth/recaptcha3.py b/app/auth/recaptcha3.py index fbd5cd02..6a7ea5bd 100644 --- a/app/auth/recaptcha3.py +++ b/app/auth/recaptcha3.py @@ -1,14 +1,12 @@ import logging import requests -from flask import Markup, current_app, json, request +from flask import Markup, current_app, request from wtforms import ValidationError from wtforms.fields import HiddenField from wtforms.widgets import HiddenInput logger = logging.getLogger(__name__) -JSONEncoder = json.JSONEncoder - RECAPTCHA_TEMPLATE = '''