def edit_job(job_id: int) -> "render_template('job/add_job.html')":

    edit = True

    job = Job.find_job_by_id(job_id)
    form = JobForm(obj=job)

    if request.method == "POST" and form.validate_on_submit():
        job_id = str(job_id)
        form.populate_obj(job)
        job.last_edited = get_date_now()

        cache.delete(job_id)
        cache.set(key=job_id, value=job)
        job.save()

        log = f"You successful edited a job with ID {job_id} on the {format_date(job.applied_date)}"
        log_account_activity(session["username"], log)

        flash("You have successfully edited your job", "success")
        return secure_redirect_or_403(
            url_for('job_app.get_job_with_id', job_id=job_id))

    return render_template("job/add_job.html",
                           form=form,
                           login_form=LoginForm(),
                           edit=edit,
                           job_id=job_id)
def view_history() -> "render_template":

    ROWS_PER_PAGE = 15
    page = request.args.get('page', 1, type=int)

    histories = Account.get_account_activity_history_by_username(session["username"]).paginate(page=page, per_page=ROWS_PER_PAGE)
    return render_template("history/history.html", login_form=LoginForm(), histories=histories)
def queried_job_search() -> "render_template('search/job_searches.html')":

    form = SearchForm()
    page = request.args.get('page', 1, type=int)

    if form.validate_on_submit():

        jobs = User.get_user_jobs(session["username"])

        if form.job_title.data and not form.company.data:
            jobs = jobs.filter(Job.title == form.job_title.data.title)

        elif not form.job_title.data and form.company.data:
            jobs = jobs.filter(Job.company == form.company.data.company)

        elif form.job_title.data and form.company.data:
            jobs = jobs.filter(
                and_(Job.title == form.job_title.data.title,
                     Job.company == form.company.data.company))

        jobs = filter_jobs_query_based_on_search_form_parameter(
            jobs, form).paginate(page=page, per_page=_ROWS_PER_PAGE)

        return render_template("search/job_searches.html",
                               login_form=LoginForm(),
                               form=form,
                               jobs=jobs)
    return abort(404)
def login() -> "render_template('index.html')":
    login_form = LoginForm()
    email = login_form.email.data

    if request.method == "POST" and login_form.validate_on_submit():
        user = User.find_by_email(email=email)

        if not user:
            flash("Incorrect Username and password", "danger")
            logger.warning(
                f"An unregistered user with the email <{email}> attempted to login"
            )

        elif user and user.account and not user.account[0].live:

            flash("Your account is no longer active.", "danger")
            flash("Contact the administrator using the contact us form below",
                  "info")

        elif user and not user.email_confirmed:
            flash(
                "You need to confirm your email before you can use the website",
                "danger")

        elif user and PasswordImplementer.is_password_valid(
                user.password, login_form.password.data):

            session["username"] = user.username.lower()
            session["admin"] = user.account[0].admin
            session["email"] = user.email.lower()

            return secure_redirect_or_403(url_for("home_app.dashboard"))

        else:
            flash("Incorrect Username and password", "danger")
            logger.warning(
                f"The user <{user.username.title()}> failed to login with the correct username and password"
            )

    return render_template("index.html",
                           contact_form=ContactForm(),
                           login_form=login_form,
                           register_form=RegisterForm())
def logout() -> "secure_redirect_or_403(url_for('home_app.home'))":

    user = User.find_by_username(session["username"])
    user.last_login = datetime.utcnow()
    user.save()
    session.clear()

    flash("You have successfully logged out", "success")
    return render_template("index.html",
                           contact_form=ContactForm(),
                           login_form=LoginForm(),
                           register_form=RegisterForm())
def add_phone_number() -> "render_template":

    form = AddPhoneNumberForm()

    if request.method == "POST" and form.validate_on_submit():
        user = User.find_by_username(session["username"])
        user.phone_number = form.phone_number.data
        user.save()

        log = f"You added your phone number to your account on {format_date(get_date_now())}"
        log_account_activity(log=log, username=user.username)

        flash("You have successfully added your phone number", "success")
        return secure_redirect_or_403(url_for("account_app.view_account"))

    return render_template("add_details/add_phone.html", form=form, login_form=LoginForm())
def contact_us() -> "render_template('index.html')":

    form = ContactForm()

    if request.method == "POST" and form.validate_on_submit():
        send_user_contact_message(
            email=form.email.data.strip(),
            first_name=form.first_name.data,
            message=form.message.data,
            surname=form.surname.data,
        )
        flash("Your message has been send to the administrator", "success")
        return secure_redirect_or_403(url_for("home_app.landing_page"))

    return render_template("index.html",
                           contact_form=form,
                           login_form=LoginForm(),
                           register_form=RegisterForm())
def home() -> "render_template('index.html')":

    form = RegisterForm()

    if request.method == "POST":

        if form.validate_on_submit():

            email, username = form.email.data.lower().strip(
            ), form.username.data.strip().lower()
            token = gen_confirmation_string_token_from_email(email)
            try:
                email_user_confirmation_email_link(username=username,
                                                   email=email,
                                                   token=token)
            except FailedToSendEmail:
                logger.critical(
                    f"Failed to send a confirmation email to the user with the email <{email}> address"
                )
            else:
                user = User(
                    email=email,
                    email_confirmation_sent_on=datetime.utcnow(),
                    username=username,
                    password=PasswordImplementer.hash_password(
                        form.new_password.data),
                    token=token,
                ).save()

                email_notification_to_owner_about_new_user_registration(user)
                flash("You have successfully registered.", "success")
                flash(
                    "Check your email for a confirmation link or your junk or spam box if it is not in your inbox.",
                    "info")

            return secure_redirect_or_403(url_for("home_app.home"))
        else:
            flash(
                "Your registration form could not be submitted because it contains errors",
                "danger")
    return render_template("index.html",
                           contact_form=ContactForm(),
                           login_form=LoginForm(),
                           register_form=form)
def reset_password() -> "render_template":
    form = ForgottenPasswordForm()

    if request.method == "POST" and form.validate_on_submit():

        user = User.find_by_email(form.email.data)
        if user:
            token = gen_confirmation_string_token_from_email(user.email)
            email_user_forgotten_password_link(email=user.email, username=user.username, token=token)
            user.token = token
            user.save()

            logger.info(f"The user <{user.username.title()}> has requested a password reset link")
            log = f"You requested a forgotten password link on {format_date(get_date_now())}"
            log_account_activity(log=log, username=user.username)

        flash("If you email address is found we will send you a reset link", "info")

    return render_template('password/forgotten_password.html', form=form, login_form=LoginForm())
示例#10
0
def add_job() -> "render_template('job/add_job.html')":

    form = JobForm()
    edit = False

    if request.method == "POST" and form.validate_on_submit():
        user = User.find_by_username(session["username"])

        if user:
            job = Job(
                applied_job_from=form.applied_job_from.data,
                company=form.company.data,
                description=form.description.data,
                employment_type=form.employment_type.data,
                job_availability=form.job_availability.data,
                job_url=form.job_url.data,
                journal=form.journal.data,
                live=True,
                location=form.location.data,
                salary=form.salary.data,
                status=form.status.data,
                title=form.title.data,
            )

            job.save()
            user.jobs.append(job)
            user.save()

            log = f"You added the job with ID {job.id} on the {format_date(job.applied_date)} to the database"
            log_account_activity(username=session["username"], log=log)

            flash("Successfully added job to the database", "success")

            return secure_redirect_or_403(url_for('job_app.add_job'))

    return render_template("job/add_job.html",
                           edit=edit,
                           form=form,
                           login_form=LoginForm())
示例#11
0
def change_old_password() -> "render_template":
    form = ChangePasswordForm()

    if request.method == "POST" and form.validate_on_submit():
        user = User.find_by_username(session["username"])

        if PasswordImplementer.is_password_valid(user.password, form.password.data):
            user.password = PasswordImplementer.hash_password(form.new_password.data)
            user.save()

            email_user_about_password_change(username=user.username, email=user.email)

            log = f"You successful changed your password on {format_date(get_date_now())}"
            logger.info(f"The user <{session['username'].title()}> has changed their password")
            log_account_activity(log=log, username=user.username)

            flash("You have successfully changed your password.", "success")
            flash("The change will be implemented once you logout", "success")

        else:
            flash("Your current password does not match what we have in our records", "danger")

    return render_template("password/change_password.html", form=form, login_form=LoginForm())
示例#12
0
def search() -> "render_template('search/search.html')":
    return render_template("search/search.html",
                           login_form=LoginForm(),
                           form=SearchForm())
示例#13
0
def change_email() -> "render_template":
    form = ChangeEmailForm()

    if request.method == "POST" and form.validate_on_submit():

        user = User.find_by_email(form.email.data.strip().lower())

        if not user:
            flash("The email address used is not the same one you used to register", "danger")

        elif User.find_by_email(form.new_email.data.strip().lower()):
            flash("The new email you entered already exists", "primary")

        else:

            email = form.new_email.data.lower().strip().lower()
            token = gen_confirmation_string_token_from_email(email)

            try:
                email_user_to_re_verifying_email(email=email, username=user.username, token=token)
            except FailedToSendEmail:
                logger.critical(f"Failed to send a confirmation email to the user with the email <{email}> address")
            else:
                user.email, user.email_confirmed, user.token = email, False, token
                user.email_confirmation_sent_on = get_date_now()
                user.save()

                log = f"You successful changed your email address on {format_date(get_date_now())}"
                log_account_activity(log=log, username=user.username)

                return secure_redirect_or_403(url_for('account_app.re_verify_changed_email'))

    return render_template("add_details/change_email.html", form=ChangeEmailForm(), login_form=LoginForm())
示例#14
0
def view_account() -> "render_template":

    user = User.find_by_username(session["username"])
    return render_template("account/account.html", login_form=LoginForm(), user=user)
示例#15
0
def landing_page() -> "render_template('index.html')":
    return render_template("index.html",
                           contact_form=ContactForm(),
                           login_form=LoginForm(),
                           register_form=RegisterForm())
示例#16
0
def successfully_changed_password():
    session.clear()
    return render_template("success/password.html", login_form=LoginForm())
示例#17
0
def successful_de_activated_account():
    return render_template("account/account_deactivated.html", login_form=LoginForm())
示例#18
0
def re_verify_changed_email():
    session.clear()
    return render_template("success/changed_email.html", login_form=LoginForm())
示例#19
0
def dashboard() -> "render_template('dashboard/dashboard.html')":
    """The browse page enables the user to access all the features of the application"""
    return render_template("dashboard/dashboard.html",
                           ADMIN_EMAIL=environ.get("ADMIN_EMAIL"),
                           login_form=LoginForm())
示例#20
0
def reset_forgotten_password(username: str, token: str) -> "render_template":

    form = NewPasswordForm()

    user = User.find_by_username(username)

    if user and user.token != token:
        flash("The token is no longer valid", "info")
        return secure_redirect_or_403(url_for('home_app.landing_page'))

    try:
        is_user_confirmation_token_valid(user)
    except SignatureExpired:

        flash("Your token has expired a new token has been re-sent to your email", "danger")
        resend_user_expired_token_link(user)
        return secure_redirect_or_403(url_for('home_app.landing_page'))

    if request.method == "POST" and form.validate_on_submit():

        user.password = PasswordImplementer.hash_password(form.new_password.data)
        user.token = None
        user.save()

        email_user_about_password_change(username=user.username, email=user.email)

        log = f"On {format_date(get_date_now())} you successfully performed a reset on your forgotten password"
        log_account_activity(log=log, username=user.username)

        return secure_redirect_or_403(url_for("account_app.successfully_changed_password"))

    return render_template("password/new_password.html", token=token, form=form, login_form=LoginForm(), username=username)
示例#21
0
def jobs() -> "render_template('job/jobs.html')":

    page = request.args.get('page', 1, type=int)
    jobs = User.get_user_jobs(session["username"]).order_by(
        Job.id.desc()).paginate(page=page, per_page=_ROWS_PER_PAGE)
    return render_template("job/jobs.html", jobs=jobs, login_form=LoginForm())
示例#22
0
def admin():
    return render_template("admin/under_construction.html",
                           login_form=LoginForm())
示例#23
0
def activate_account() -> "render_template":

    # Account.activate_user_account(username.lower())
    # flash(f"You re-activated the account for user {username.title()}")
    return render_template("admin/under_construction.html",
                           login_form=LoginForm())
示例#24
0
def get_job_with_id(job_id: str) -> "render_template('job/job.html')":
    return render_template("job/job.html",
                           job=Job.find_job_by_id(job_id),
                           login_form=LoginForm())