Esempio n. 1
0
def contact_us():
    form = contactForm()
    if request.method == 'POST' and form.validate_on_submit():
        name = form.first_name.data + " " + form.last_name.data
        inquiry_selection = dict(form.inquiry_selection.choices).get(
            form.inquiry_selection.data)
        email = form.email.data
        tel = formatPhoneNumber(form.mobile.data)
        msg = form.message.data
        mail_msg = Message(f'Contact Message Recieved',
                           recipients=[
                               "*****@*****.**",
                               "*****@*****.**"
                           ])
        mail_msg.html = formatContact(name=name,
                                      inquiry_selection=inquiryselection,
                                      email=email,
                                      tel=tel,
                                      msg=msg)
        mail.send(mail_msg)
        alert.setAlert(
            'info',
            'Contact Message has been Sent. Please wait for a responce from support team.'
        )
        return redirect(url_for('.homePage'))
    else:
        return render_template('public/contactpage.html', form=form)
Esempio n. 2
0
def articleCreation():
    form = articleForm()
    if request.method == "POST" and form.validate_on_submit():
        img_file = form.front_image.data
        if isinstance(img_file, type(None)):
            del img_file
            img = "None"
        else:
            filename = secure_filename(img_file.filename)
            img_set.save(img_file, name=f"{filename}")
            with iopen(f'{PATH}\\static\\assets\\uploads\\images\\{filename}',
                       'rb') as image:
                img = str(base64.b64encode(image.read()), 'utf-8')
        current_date = datetime.now()
        date_util = DateUtil(current_date)
        creation_date = date_util.datetimeSubDate(date_re)
        del current_date
        body = request.form["editordata"]
        new_article = Article(title=form.title.data,
                              author=form.author.data,
                              create_date=creation_date,
                              short_desc=form.short_desc.data,
                              title_img=img,
                              body=body)
        db.session.add(new_article)
        db.session.commit()
        alert.setAlert('success', 'Article has been Created.')
        return redirect(url_for(".homePage"))
    else:
        return render_template("public/articles/articleform.html", form=form)
Esempio n. 3
0
def signOut():
    """
    Signs out of the site
    """
    logout_user()
    alert.setAlert('success', 'Successfully signed out')
    return redirect(url_for(".homePage"))
Esempio n. 4
0
def initialForgotPage():
    """
    forgot password page.
    """
    form = forgotRequestForm()
    if request.method == "POST":
        recipient_email = form.email.data
        user = User.lookup(form.email.data)
        if isinstance(user, type(None)):
            if recipient_email != '' and form.submit.data == True:
                alert.setAlert('warning',
                               f"No Account found under {recipient_email}.")
                return redirect(url_for(".loginPage"))
            elif recipient_email == '' and form.back_button.data:
                return redirect(url_for('.loginPage'))
        if not form.submit.data and form.back_button.data:
            return redirect(url_for('loginPage'))
        reset_token = urlSerializer.dumps(recipient_email, salt="forgot-pass")
        reset_url = 'http://127.0.0.1:5000' + url_for(
            "resetRequestRecieved", token=reset_token, email=recipient_email)
        reset_msg = Message('Reset Password', recipients=[recipient_email])
        reset_msg.html = automatedMail(
            user.name,
            f'''You have requested to reset your password. Follow the link below to reset your password.
                                    <br> Reset Password: {reset_url}''')
        mail.send(reset_msg)
        alert.setAlert('success', 'Reset Password Email has been sent.')
        return redirect(url_for('.homePage'))
    else:
        return render_template("public/forgot.html", field=form)
Esempio n. 5
0
def confirmation_recieved(token):
    """
    Confirmation and account creation page
    :param token: Email token
    """
    global email
    email = "".join(email)
    try:
        urlSerializer.loads(token, salt="email-confirm", max_age=3600 / 2)
        user_datastore.remove_role_from_user(User.lookup(email), 'unverified')
        user_datastore.add_role_to_user(User.lookup(email), "verified")
        user_datastore.commit()
        unverlog.removeContent(email, 'r+')
        alert.setAlert('success', 'Email Verified')
        return redirect(url_for(".homePage"))
    except SignatureExpired:
        notice_user = User.lookup(email)
        notice_msg = Message('Account Validation Warning',
                             recipients=[notice_user.email])
        notice_msg.html = automatedMail(
            notice_user.name, f'''
                                        We regret to inform you that your account may expire at around 0 to 1 hour due to confirmation token have expired. <br>
                                        Contact support if you want to make sure that your account won't automatically be deleted at: {url_for('.contact_us')} (<i>Notice:</i>
                                        <b>Support may be offline at any given time and may not reply fast enough. If this is the case and the 0 to 1 hour period is up then create an account again at:</b><a href="{url_for(".registerPage")}">Register</a>").
                                        ''')
        mail.send(notice_msg)
        return redirect(url_for(".homePage"))
Esempio n. 6
0
def registerPage():
    """
    Registration Page
    """
    global email
    form = registerForm()
    if request.method == 'POST':
        with sql_sess.no_autoflush:
            user_datastore.find_or_create_role('admin')
            user_datastore.find_or_create_role('member')
            user_datastore.find_or_create_role('unverified')
            user_datastore.find_or_create_role('verified')
        current_date = datetime.now()
        new_user = user_datastore.create_user(
            name=form.name.data.capitalize(),
            username=form.email.data.lower(),
            email=form.email.data.lower(),
            hashed_password=guard.hash_password(form.password.data),
            created_at=
            f'{current_date.month}/{current_date.day}/{current_date.year}',
            blacklisted=False,
            roles=['member', 'unverified'])
        user_datastore.commit()

        def yield_email(email):
            yield email

        email = yield_email(form.email.data.lower())
        token = urlSerializer.dumps(form.email.data, salt='email-confirm')
        verify_msg = Message('Confirm Account', recipients=[form.email.data])
        confirm_link = 'http://127.0.0.1:5000' + url_for(
            ".confirmation_recieved", token=token, external=True)
        verify_msg.html = automatedMail(
            form.name.data, f'''
                                        Thank you for registering! In order to complete the registration you must click on the link below. <br>
                                        Link will expire in <b>30</b> minutes after this email has been sent. <br>
                                        Link: <a href="{confirm_link}">Confirm Account</a>'''
        )
        mail.send(verify_msg)
        alert.setAlert(
            'success',
            'Registration Succesful. Check your email for confirmation link.')
        unverlog.addContent(form.email.data.lower(), token, mode="r+")
        return redirect(url_for(".homePage"))
    else:
        return render_template("public/registerpage.html", form=form)
Esempio n. 7
0
def resetRequestRecieved(token, email):
    """
    Redirects to Reset Form link after validating token
    """
    try:
        urlSerializer.loads(token, salt="forgot-pass", max_age=300)

        form = forgotForm()
        if request.method == 'POST':
            email = str(email).replace("%40", '@')
            replacementPassword = guard.hash_password(
                form.confirm_new_password.data)
            user = User.lookup(email)
            if not guard.authenticate(user, form.confirm_new_password.data):
                user.password = replacementPassword
                db.session.commit()
                alert.setAlert('success',
                               'Password has been Successfully reset.')
            else:
                alert.setAlert(
                    'warning',
                    'The Requested Password matches your current password.')
            return redirect(url_for('loginPage'))
        else:
            return render_template("public/forgotrecieved.html",
                                   form=form,
                                   token=token,
                                   email=email)

    except SignatureExpired:
        alert.setAlert('error', 1)
        return redirect(url_for(".loginPage"))
Esempio n. 8
0
def inauthorized_auth_error(e):
    """
    handles 401 status code and redirects to HomePage
    """
    alert.setAlert('error', "4")
    return redirect(url_for('main_app.homePage'))
Esempio n. 9
0
def server_error(e):
    """
    handles 500 status code and redirects to HomePage
    """
    alert.setAlert('error', "2")
    return redirect(url_for('main_app.homePage'))