Example #1
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)
Example #2
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)
Example #3
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"))
Example #4
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)
Example #5
0
def checkExpireRegistrationCodes():
    rprint(
        "[black][Scheduler Thread][/black][bold green]Commencing token check[/bold green]"
    )
    from ProjectsWebsite.views import urlSerializer
    from ProjectsWebsite.database.models import user_datastore, User
    with open(f"{current_app.static_folder}\\unverified\\unverified-log.txt",
              'r+',
              encoding="utf-8") as f:
        lines = f.readlines()
        f.close()
        if lines == []:
            return None
        for line in lines:
            user = line[line.find("(") + 1:line.rfind(")")]
            parenthesis_length = len(user) + 3
            token = line[parenthesis_length:]
        try:
            urlSerializer.loads(token, salt="email-confirm", max_age=3600 / 2)
        except SignatureExpired:
            lines.remove(line)
            expired_user = User.lookup(user)
            expired_msg = Message("Account Deleted", recipients=[user])
            expired_msg.html = automatedMail(
                expired_user.name, f'''
                                             Your current account in MyProjects has not been verified and your verification link has expired. 
                                            You must <a href="{url_for("main_app.registerPage")}">register</a> again if you want to have an account in MyProject.'''
            )
            mail.send(expired_msg)
            user_datastore.delete_user(user)
            user_datastore.commit()
            f.writelines(lines)
            f.close()
        except Exception as e:
            raise OperationError(
                "urlSerializer args or kwargs caused the current operation to fail.",
                "itsdangerous.URLSafeTimedSerializer") from e
        else:
            for line in lines:
                f.writelines(line)
            f.close()