示例#1
0
def reset_password(token):
    resetPasswordForm = forms.ResetPasswordForm(request.form, csrf_enabled=True)
    s = Serializer(current_app.config['SECRET_KEY'])
    _id = s.loads(token)

    user = models.User.objects.with_id(_id)

    if request.method == 'POST' and resetPasswordForm.validate() is False:
        current_app.logger.info(resetPasswordForm.errors)
        flash('Les mots de passe doivent correspondre')

    elif request.method == 'POST' and resetPasswordForm.validate():
        # generate password hash
        password_hash = flask_bcrypt.generate_password_hash(request.form['password'])

        # update user password
        user.update(password=password_hash)

        send_mail('Avis de réinitialisation de mot de passe', user.email, 'reset_notice', user=user)

        flash('Votre mot de passe a été changé avec succès.')
        return redirect('/login')

    templateData = {

        'form': resetPasswordForm

    }

    return render_template("/accounts/reset_password.html", **templateData)
示例#2
0
def review(resume_id, feedback_id):
    resume = models.Resume.objects().with_id(resume_id)
    feedback = models.Feedback.objects().with_id(feedback_id)

    # If model is old
    if hasattr(feedback, "version") is False:
        flash(utils.get_message_text("sorry_old_model"))
        return redirect('/feedback')

    if request.method == "POST" and feedback.review_lock is False:
        # Takes the Seeker's input to create the entry in the database
        try:
            feedback.first_question = request.form.get('question_1')
            feedback.second_question = request.form.get('question_2')
            feedback.third_question = request.form.get('question_3')

            feedback.first_section.review = request.form.get('section_1')
            feedback.second_section.review = request.form.get('section_2')
            feedback.third_section.review = request.form.get('section_3')
            feedback.fourth_section.review = request.form.get('section_4')
            feedback.fifth_section.review = request.form.get('section_5')

            feedback.validate()

            feedback.update(review_lock=True)
            feedback.save()

            message_to_display = "saved"
            if request.form.get('thank_you') == CONSTANTS.CHOICE_ONE:
                subject = "[RevueCV] Merci !"
                host_url = request.url_root
                user = feedback.volunteer
                send_mail(subject,
                          user.email,
                          'thank_you',
                          user=user,
                          url=host_url,
                          resume=resume)
                message_to_display = "saved_and_sent"
                feedback.update(thank_you_message=True)
                feedback.save()
            return redirect('/review/%s' % message_to_display)

        except ValidationError as e:
            print "Erreur:", e
            flash(
                "Il y a eu une erreur avec votre soumission. Veuillez réessayer."
            )
            return redirect('/feedback/%s/%s/review' %
                            (feedback.resume.id, feedback.id))

    else:
        # Shows the survey page (review)
        templateData = {
            'title': 'Noter votre feedback',
            'resume': resume,
            'feedback': feedback
        }
        return render_template('feedback/review.html', **templateData)
示例#3
0
def notify_volunteers():
    if list_resumes:
        user_objects = User.objects
        for user in user_objects:
            if user.role == 'volunteer':
                send_mail('Volunteers Needed',
                          user.email,
                          'notify_volunteers',
                          user=user)
示例#4
0
def send_account_activation_instructions(user, host_url):
    """Sends the account activation instructions email for the specified user.

    :param user: The user to send the instructions to
    """
    token = generate_token(user)

    send_mail('Réactivation du compte RevueCV', user.email, 'activate_instructions', user=user, reset_link=token,
              url=host_url)
示例#5
0
def send_reset_password_instructions(user, host_url):
    """Sends the reset password instructions email for the specified user.

    :param user: The user to send the instructions to
    """
    token = generate_token(user)

    send_mail('Réinitialisation du mot de passe RevueCV', user.email, 'reset_instructions', user=user, reset_link=token,
              url=host_url)
示例#6
0
def profile():
    user = models.User.objects.with_id(current_user.id)

    if request.method == "POST" and "role" in request.form:
        user.update(role=request.form['role'])

        return redirect('/profile')

    elif request.method == "POST" and "deactivate" in request.form:
        user.update(active=False)

        send_mail('Avis de désactivation de compte', user.email, 'deactivate_notice', user=user)

        flash("Votre compte a été désactivé avec succès.")
        return redirect('/logout')

    elif request.method == "POST" and "editusername" in request.form:
        if request.form['editusername'].strip() == '':
            flash("Veuillez entrer un nom d'utilisateur")
        else:
            user.update(username=request.form['editusername'])
            flash("Votre nom d'utilisateur a été mis à jour avec succès")

        return redirect('/profile')

    if user.role == 'jobseeker':
        _role = "jobseeker"
    else:
        _role = "volunteer"

    updateProfile = forms.updateProfileForm(csrf_enabled=True)

    templateData = {

        'form': updateProfile,
        'user': user,
        'role': _role

    }

    return render_template("/accounts/profile.html", **templateData)
示例#7
0
def entry_page(resume_id, feedback_id, state="view"):
    # get class resume entry with matching slug
    resume = models.Resume.objects().with_id(resume_id)
    feedback = models.Feedback.objects().with_id(feedback_id)

    if resume and feedback:
        # Display this only when the feedback is freshly saved and not when it is just being viewed.
        if state == "saved":
            flash('Feedback has been saved')

            subject = "[RevueCV] Nouveau feedback pour " + resume.title + " disponible"
            host_url = request.url_root
            user = resume.user

            if user.active:
                send_mail(subject,
                          user.email,
                          'new_feedback',
                          user=user,
                          url=host_url,
                          resume=resume)

        else:
            feedback.viewed = True
            feedback.save()

        templateData = {
            'title': 'Votre Feedback',
            'resume': resume,
            'feedback': feedback
        }

        return render_template('feedback/view.html', **templateData)

    else:
        return render_template('404.html')
示例#8
0
def register():
    registerForm = forms.SignupForm(request.form, csrf_enabled=True)
    current_app.logger.info(request.form)
    host_url = request.url_root

    templateData = {

        'form': registerForm

    }

    if request.method == 'POST' and registerForm.validate() is False:
        current_app.logger.info(registerForm.errors)
        flash_errors(registerForm)

        return render_template("/accounts/register.html", **templateData)
    elif request.method == 'POST' and registerForm.validate():
        email = request.form['email']
        username = request.form['username']
        role_initial = request.form['role']
        role = request.form['role']
        location = request.form['location']
        source = request.form['source']
        sourceoptional = request.form['sourceoptional']

        # generate password hash
        password_hash = flask_bcrypt.generate_password_hash(request.form['password'])

        # prepare User
        user = User(email, username, password_hash, role_initial, role, location, source,
                    sourceoptional)

        userObj = User()
        email_check = userObj.get_by_email(email)
        username_check = userObj.get_by_username(username)

        if email_check:
            if email_check.active:
                do_flash(REGISTRATION_EMAIL_EXISTS, "danger")
            else:
                do_flash(REGISTRATION_INACTIVE, "danger")

                return redirect('/activate')
        elif username_check:
            do_flash(REGISTRATION_UNAME_EXISTS, "danger")
        else:
            try:
                user.save()
                if login_user(user, remember="no"):
                    send_mail('Votre inscription a réussi', email, 'welcome', user=user, url=host_url)

                    if user.role == 'jobseeker':
                        return redirect('/resume/create')
                    else:
                        return redirect('/feedback')
                else:
                    do_flash(REGISTRATION_NOLOGIN, "danger")

                    return redirect('/register')
            except:
                do_flash(REGISTRATION_ERROR, "danger")

    return render_template("/accounts/register.html", **templateData)