Beispiel #1
0
def register():
    error_list = []
    form = RegistrationForm()
    if request.method == 'POST':
        #print(request.form['user_name'])
        try:
            user_name = form.user_name.data
            password = form.password.data
            if len(user_name) < 3:
                #print("a")
                if len(user_name) == 0:
                    error_list.append('Your username is required.')
                else:
                    error_list.append('Your username is too short.')
            schema = PasswordValidator()
            schema.min(8) \
                .has().uppercase() \
                .has().lowercase() \
                .has().digits()
            if not schema.validate(password):
                #print("b")
                if len(password) == 0:
                    error_list.append("Your password is required.")
                error_list.append('Your password is invalid, please refer to Account notes.')
            #print(error_list)
            if len(error_list) == 0:
                services.add_user(user_name, password, repo.repo_instance)
                # All is well, redirect the user to the login page.
                return redirect(url_for('authen_bp.login'))
            else:
                return render_template(
                    'authen/credentials.html',
                    title='Register',
                    form=form,
                    error_list=error_list,
                    handler_url=url_for('authen_bp.register'),
                )
        except services.NameNotUniqueException:
            error_list.append("Your username is already taken - please supply another.")
    # For a GET or a failed POST request, return the Registration Web page.
    return render_template(
        'authen/credentials.html',
        title='Register',
        form=form,
        error_list=error_list,
        handler_url=url_for('authen_bp.register'),
    )
Beispiel #2
0
 def __call__(self, form, field):
     schema = PasswordValidator()
     schema.min(8).has().uppercase().has().lowercase().has().digits()
     if not schema.validate(field.data):
         raise ValidationError(self.message)
Beispiel #3
0
import re
from typing import Tuple

from flask import request, jsonify, Blueprint
from password_validator import PasswordValidator

from authserver.rabbitmq import RabbitMQ
from common import email_utils
from common.error import ValidationException

password_schema = PasswordValidator()

(password_schema.min(12).max(
    100).has().uppercase().has().lowercase().has().digits().has().symbols())

user_api = Blueprint("user_api", __name__)


@user_api.route('/api/user', methods=["POST"])
def create() -> Tuple[str, int]:
    from authserver.model.user import User

    body = request.json
    validate_create(body)
    user = User.create(body["email"], body["password"])
    create_rmq_user(body["email"], body["password"], user.hashed_id)
    return jsonify(dict(topic=f"user.{user.hashed_id}.message"))


def create_rmq_user(email: str, password: str, hashed_id: str) -> None:
    rmq = RabbitMQ()