Exemple #1
0
def update_editor_contents():
    """Update the contents of an editor."""
    edit_data = request.form.get('edit_data')
    editor_name = request.form.get('editor_name')
    editor_contents = EditableHTML.query.filter_by(
        editor_name=editor_name).first()
    if editor_contents is None:
        editor_contents = EditableHTML(editor_name=editor_name)
    editor_contents.value = edit_data
    db.session.add(editor_contents)
    db.session.commit()
    return 'OK', 200
Exemple #2
0
def index():
    if current_user.is_authenticated:
        return redirect('/daily')
    else:
        editable_html_obj = EditableHTML.get_editable_html('index')
        return render_template('main/index.html',
                               editable_html_obj=editable_html_obj)
Exemple #3
0
def test_get_update_editor_contents(client, admin):
    login(client, admin)
    data = {'edit_data': 'test', 'editor_name': 'admin'}

    client.post(url_for('admin.update_editor_contents'), data=data)
    editor_contents = EditableHTML.objects(editor_name='admin').first()
    assert editor_contents.value == 'test'
Exemple #4
0
def text(text_type):
    website_settings = MSettings.query.first()
    editable_html_obj = EditableHTML.get_editable_html(text_type)
    return jsonify({
        'status': 1,
        'editable_html_obj': editable_html_obj.serialize
    })
Exemple #5
0
def texts():
    editable_html_obj = EditableHTML.get_editable_html('contact')
    if request.method == 'POST':
        edit_data = request.form.get('edit_data')
        editor_name = request.form.get('editor_name')

        editor_contents = EditableHTML.query.filter_by(
            editor_name=editor_name).first()
        if editor_contents is None:
            editor_contents = EditableHTML(editor_name=editor_name)
        editor_contents.value = edit_data

        db.session.add(editor_contents)
        db.session.commit()
        flash('Successfully updated text.', 'success')
        return redirect(url_for('admin.texts'))
    return render_template('admin/texts/index.html', editable_html_obj=editable_html_obj)
Exemple #6
0
def daily():
    editable_html_obj = EditableHTML.get_editable_html('daily')

    if request.method == 'POST':
        data = request.get_json()
        id = int(data['id'])
        habit = Habit.query.get(id)
        habit.complete = data['complete']
        db.session.commit()
    habits = current_user.habits
    return render_template('main/daily.html',
                           editable_html_obj=editable_html_obj,
                           habits=habits)
Exemple #7
0
def contact():
    if current_user.is_authenticated:
        form = ContactForm()
    else:
        form = PublicContactForm()
    editable_html_obj = EditableHTML.get_editable_html('contact')
    if request.method == 'POST':
        if form.validate_on_submit():
            if not recaptcha.verify():
                flash("Wrong Captcha, pls try again", 'error')
                return redirect(url_for("public.contact"))
            spam_detect = SpamDetector()

            if current_user.is_authenticated:
                spam_detect.setMessage(form.text.data)
                text_spam = spam_detect.predict()
                spam = False
                if 1 in text_spam:
                    spam = True
                contact_message = ContactMessage(
                    user_id=current_user.id,
                    text=form.text.data,
                    spam=spam
                )
            else:
                spam_detect.setMessage(form.name.data)
                name_spam = spam_detect.predict()
                spam_detect.setMessage(form.text.data)
                text_spam = spam_detect.predict()
                spam = False
                if 1 in name_spam or 1 in text_spam:
                    spam = True
                email = form.email.data
                is_valid = validate_email(email, check_mx=False)
                if not is_valid:
                    flash("The email you entered doesn't exist, pls insert a valid email", 'error')
                    return redirect(url_for("public.contact"))
                contact_message = ContactMessage(
                    name=form.name.data,
                    email=email,
                    text=form.text.data,
                    spam=spam
                )
            db.session.add(contact_message)
            db.session.commit()
            flash('Successfully sent contact message.', 'success')
            return redirect(url_for('public.contact'))
    return render_template('public/contact.html', editable_html_obj=editable_html_obj, form=form)
Exemple #8
0
def update_editor_contents():
    """Update the contents of an editor."""

    edit_data = request.form.get('edit_data')
    editor_name = request.form.get('editor_name')

    editor_contents = EditableHTML.objects(editor_name=editor_name).first()
    if editor_contents is None:
        editor_contents = EditableHTML(editor_name=editor_name)
    editor_contents.value = edit_data

    editor_contents.save()

    return 'OK', 200
Exemple #9
0
def contact():
    if current_user.is_authenticated:
        form = ContactForm()
    else:
        form = PublicContactForm()
    editable_html_obj = EditableHTML.get_editable_html('contact')
    if request.method == 'POST':
        if form.validate_on_submit():
            if current_user.is_authenticated:
                contact_message = ContactMessage(user_id=current_user.id,
                                                 text=form.text.data)
            else:
                contact_message = ContactMessage(name=form.name.data,
                                                 email=form.email.data,
                                                 text=form.text.data)
            db.session.add(contact_message)
            db.session.commit()
            flash('Successfully sent contact message.', 'success')
            return redirect(url_for('public.contact'))
    return render_template('public/contact.html',
                           editable_html_obj=editable_html_obj,
                           form=form)
Exemple #10
0
def faq():
    editable_html_obj = EditableHTML.get_editable_html('faq')
    return render_template('main/faq.html',
                           editable_html_obj=editable_html_obj)
def setup_general():
    """Runs the set-up needed for both local development and production."""
    Role.insert_roles()
    Agency.insert_agencies()
    EditableHTML.add_default_faq()
Exemple #12
0
def donate():
    editable_html_obj = EditableHTML.get_editable_html('donate')
    return render_template(
        'main/privacy.html', editable_html_obj=editable_html_obj)
Exemple #13
0
def update_form_instructions():
    """Update the email confirmation upon room request submission."""
    editable_html_obj = EditableHTML.get_editable_html("form_instructions")
    return render_template('room_request/edit_text.html',
                           editable_html_obj=editable_html_obj,
                           title="Form Instructions")
Exemple #14
0
def monthly():
    editable_html_obj = EditableHTML.get_editable_html('monthly')
    return render_template('main/monthly.html',
                           editable_html_obj=editable_html_obj)
Exemple #15
0
def faq():
    editable_html_obj = EditableHTML.get_editable_html('faq')
    return render_template('public/faq.html', editable_html_obj=editable_html_obj)
Exemple #16
0
def setup_general():
    """Runs the set-up needed for both local development and production."""
    Role.insert_roles()
    EditableHTML.add_default_faq()
def create_all():
    if not EditableHTML.exists():
        EditableHTML.create_table(wait=True)
def setup_general(session=None):
    """Runs the set-up needed for both local development and production.
       Also sets up first administrator user."""
    if not session:
        session = boto3.Session()
    client = session.client('cognito-idp')

    # create a pool and print the id
    response = client.create_user_pool(
        PoolName='serverless-flask-test',
        Policies={
            'PasswordPolicy': {
                'MinimumLength': 8,
                'RequireUppercase': True,
                'RequireLowercase': True,
                'RequireNumbers': True,
                'RequireSymbols': True
            }
        },
        AliasAttributes=[
            'email',
        ],
        EmailVerificationMessage=
        'Please use this code to verify your account with Serverless Flask: {####} ',
        EmailVerificationSubject='Email Verification Code for Serverless Flask',
        MfaConfiguration='OFF',
        DeviceConfiguration={
            'ChallengeRequiredOnNewDevice': False,
            'DeviceOnlyRememberedOnUserPrompt': False
        },
        AdminCreateUserConfig={
            'AllowAdminCreateUserOnly': False,
            'UnusedAccountValidityDays': 1,
            'InviteMessageTemplate': {
                'EmailMessage': 'Welcome to this Serverless Flask example.',
                'EmailSubject': 'Serverless Flask Welcomes You.'
            }
        },
        Schema=[
            {
                'Name': 'email',
                'AttributeDataType': 'String',
                'DeveloperOnlyAttribute': False,
                'Mutable': True,
                'Required': True,
            },
            {
                'Name': 'family_name',
                'AttributeDataType': 'String',
                'DeveloperOnlyAttribute': False,
                'Mutable': True,
                'Required': True,
            },
            {
                'Name': 'given_name',
                'AttributeDataType': 'String',
                'DeveloperOnlyAttribute': False,
                'Mutable': True,
                'Required': True,
            },
        ])

    pool_name = response.get('UserPool')['Name']
    print('The cognito user pool {0!s} has been created.'.format(pool_name))
    pool_id = response.get('UserPool')['Id']
    print(
        'The cognito user pool id is {0!s}. Please save this and set it to your environment variable '
        'COGNITO_POOL_ID'.format(pool_id))

    # create an app and print the id
    response = client.create_user_pool_client(
        UserPoolId=pool_id,
        ClientName='Serverless Flask Web App',
        GenerateSecret=False,  # Boto3 doesn't support token auth yet.
        RefreshTokenValidity=30,
        ExplicitAuthFlows=[
            'ADMIN_NO_SRP_AUTH',
        ])

    app_name = response.get('UserPoolClient')['ClientName']
    print('The cognito app {0!s} has been created for your user pool'.format(
        app_name))
    app_id = response.get('UserPoolClient')['ClientId']
    print(
        'The cognito app id is {0!s}. Please save this and set it to your environment variable '
        'COGNITO_APP_CLIENT_ID'.format(app_id))

    # Create groups in cognito
    client.create_group(GroupName='admin',
                        UserPoolId=pool_id,
                        Description='Administrators',
                        Precedence=1)

    print('The admin group has been created for the cognito user pool')

    client.create_group(GroupName='general',
                        UserPoolId=pool_id,
                        Description='All Users',
                        Precedence=255)

    print('The general group has been created for the cognito user pool')

    print('Completed creating Cognito resources')

    # create the dynamo table
    if not EditableHTML.exists():
        EditableHTML.create(read_capacity_units=1,
                            write_capacity_units=1,
                            wait=True)
        print("DynamoDB table for editors created")

    if not appSession.exists():
        appSession.create(read_capacity_units=1,
                          write_capacity_units=1,
                          wait=True)
        print("DynamoDB table for sessions created")
Exemple #19
0
def text(text_type):
    editable_html_obj = EditableHTML.get_editable_html(text_type)
    return jsonify({
        'status': 1,
        'editable_html_obj': editable_html_obj.serialize
    })
Exemple #20
0
def about():
    editable_html_obj = EditableHTML.get_editable_html('about')
    return render_template('main/about.html',
                           editable_html_obj=editable_html_obj)
Exemple #21
0
def faq():
    website_settings = MSettings.query.first()
    editable_html_obj = EditableHTML.get_editable_html('faq')
    return render_template('public/faq.html',
                           website_settings=website_settings,
                           editable_html_obj=editable_html_obj)
Exemple #22
0
def privacy():
    website_settings = MSettings.query.first()
    editable_html_obj = EditableHTML.get_editable_html('privacy')
    return render_template('public/privacy.html',
                           website_settings=website_settings,
                           editable_html_obj=editable_html_obj)
Exemple #23
0
def habits():
    editable_html_obj = EditableHTML.get_editable_html('habits')
    habits = current_user.habits
    return render_template('main/habits.html',
                           editable_html_obj=editable_html_obj,
                           habits=habits)
Exemple #24
0
def privacy():
    editable_html_obj = EditableHTML.get_editable_html('privacy')
    return render_template('public/privacy.html', editable_html_obj=editable_html_obj)
Exemple #25
0
def update_email_confirmation():
    editable_html_obj = EditableHTML.get_editable_html('email_confirmation')
    return render_template('room_request/edit_text.html',
                           editable_html_obj=editable_html_obj,
                           title="Confirmation Email")
Exemple #26
0
def terms():
    editable_html_obj = EditableHTML.get_editable_html('terms')
    return render_template('public/terms.html', editable_html_obj=editable_html_obj)
Exemple #27
0
def update_home():
    editable_html_obj = EditableHTML.get_editable_html('home_page_language')
    return render_template('room_request/edit_text.html',
                           editable_html_obj=editable_html_obj,
                           title="Home Page Language")
def about():
    editable_html_obj = EditableHTML.get_editable_html('about')
    return render_template('main/about.html',
                           editable_html_obj=editable_html_obj)
Exemple #29
0
def about():
    editable_html_obj = EditableHTML.get_editable_html("about")
    return render_template("main/about.html", editable_html_obj=editable_html_obj)
Exemple #30
0
def index():
    editable_html_obj = EditableHTML.get_editable_html("home_page_language")
    return render_template('main/index.html',
                           editable_html_obj=editable_html_obj)
def drop_all():
    if EditableHTML.exists():
        EditableHTML.delete_table()