(first_name, last_name, email, password, role=None)
return user
Find existing user or create new user
Find existing user or create new user
Find existing user or create new user
def find_or_create_user(first_name, last_name, email, password, role=None):
    """ Find existing user or create new user """
    user = User.query.filter(User.email == email).first()
    if not user:
        user = User(email=email,
                    first_name=first_name,
                    last_name=last_name,
                    password=current_app.user_manager.password_manager.hash_password(password),
                    active=True,
                    email_confirmed_at=datetime.datetime.utcnow())
        if role:
            user.roles.append(role)
        db.session.add(user)
    return user
def find_or_create_user ( first_name , last_name , email , password , role = None ) : user = User . query . filter ( User . email == email ) . first ( ) if not user : user = User ( email = email , first_name = first_name , last_name = last_name , password = current_app . user_manager . password_manager . hash_password ( password ) , active = True , email_confirmed_at = datetime . datetime . utcnow ( ) ) if role : user . roles . append ( role ) db . session . add ( user ) return user