コード例 #1
0
ファイル: web.py プロジェクト: ernsyn/ihatemoney
def invite():
    """Send invitations for this particular project"""

    form = InviteForm()

    if request.method == "POST":
        if form.validate():
            # send the email
            message_body = render_localized_template("invitation_mail")
            message_title = _(
                "You have been invited to share your "
                "expenses for %(project)s",
                project=g.project.name,
            )
            msg = Message(
                message_title,
                body=message_body,
                recipients=[
                    email.strip() for email in form.emails.data.split(",")
                ],
            )
            current_app.mail.send(msg)
            flash(_("Your invitations have been sent"))
            return redirect(url_for(".list_bills"))

    return render_template("send_invites.html", form=form)
コード例 #2
0
ファイル: web.py プロジェクト: Pmtague/ihatemoney
def invite():
    """Send invitations for this particular project"""

    form = InviteForm()

    if request.method == "POST":
        if form.validate():
            # send the email
            message_body = render_localized_template("invitation_mail")
            message_title = _(
                "You have been invited to share your "
                "expenses for %(project)s",
                project=g.project.name,
            )
            msg = Message(
                message_title,
                body=message_body,
                recipients=[
                    email.strip() for email in form.emails.data.split(",")
                ],
            )
            success = send_email(msg)
            if success:
                flash(_("Your invitations have been sent"), category="success")
                return redirect(url_for(".list_bills"))
            else:
                flash(
                    _("Sorry, there was an error while trying to send the invitation emails. "
                      "Please check the email configuration of the server "
                      "or contact the administrator."),
                    category="danger",
                )
                # Fall-through: we stay on the same page and display the form again
    return render_template("send_invites.html", form=form)
コード例 #3
0
ファイル: web.py プロジェクト: Pmtague/ihatemoney
def remind_password():
    form = PasswordReminder()
    if request.method == "POST":
        if form.validate():
            # get the project
            project = Project.query.get(form.id.data)
            # send a link to reset the password
            remind_message = Message(
                "password recovery",
                body=render_localized_template("password_reminder",
                                               project=project),
                recipients=[project.contact_email],
            )
            success = send_email(remind_message)
            if success:
                return redirect(url_for(".password_reminder_sent"))
            else:
                flash(
                    _("Sorry, there was an error while sending you an email "
                      "with password reset instructions. "
                      "Please check the email configuration of the server "
                      "or contact the administrator."),
                    category="danger",
                )
                # Fall-through: we stay on the same page and display the form again
    return render_template("password_reminder.html", form=form)
コード例 #4
0
ファイル: web.py プロジェクト: Pmtague/ihatemoney
def create_project():
    form = ProjectForm()
    if request.method == "GET" and "project_id" in request.values:
        form.name.data = request.values["project_id"]

    if request.method == "POST":
        # At first, we don't want the user to bother with the identifier
        # so it will automatically be missing because not displayed into
        # the form
        # Thus we fill it with the same value as the filled name,
        # the validation will take care of the slug
        if not form.id.data:
            form.id.data = form.name.data
        if form.validate():
            # save the object in the db
            project = form.save()
            db.session.add(project)
            db.session.commit()

            # create the session object (authenticate)
            session[project.id] = True
            session.update()

            # send reminder email
            g.project = project

            message_title = _(
                "You have just created '%(project)s' "
                "to share your expenses",
                project=g.project.name,
            )

            message_body = render_localized_template("reminder_mail")

            msg = Message(message_title,
                          body=message_body,
                          recipients=[project.contact_email])
            success = send_email(msg)
            if success:
                flash(_("A reminder email has just been sent to you"),
                      category="success")
            else:
                # Display the error as a simple "info" alert, because it's
                # not critical and doesn't prevent using the project.
                flash(
                    _("We tried to send you an reminder email, but there was an error. "
                      "You can still use the project normally."),
                    category="info",
                )
            # redirect the user to the next step (invite)
            flash(
                _("The project identifier is %(project)s", project=project.id))
            return redirect(url_for(".list_bills", project_id=project.id))

    return render_template("create_project.html", form=form)
コード例 #5
0
ファイル: web.py プロジェクト: ernsyn/ihatemoney
def create_project():
    form = ProjectForm()
    if request.method == "GET" and "project_id" in request.values:
        form.name.data = request.values["project_id"]

    if request.method == "POST":
        # At first, we don't want the user to bother with the identifier
        # so it will automatically be missing because not displayed into
        # the form
        # Thus we fill it with the same value as the filled name,
        # the validation will take care of the slug
        if not form.id.data:
            form.id.data = form.name.data
        if form.validate():
            # save the object in the db
            project = form.save()
            db.session.add(project)
            db.session.commit()

            # create the session object (authenticate)
            session[project.id] = True
            session.update()

            # send reminder email
            g.project = project

            message_title = _(
                "You have just created '%(project)s' "
                "to share your expenses",
                project=g.project.name,
            )

            message_body = render_localized_template("reminder_mail")

            msg = Message(message_title,
                          body=message_body,
                          recipients=[project.contact_email])
            try:
                current_app.mail.send(msg)
            except SMTPRecipientsRefused:
                flash(_("Error while sending reminder email"),
                      category="danger")

            # redirect the user to the next step (invite)
            flash(
                _("The project identifier is %(project)s", project=project.id))
            return redirect(url_for(".list_bills", project_id=project.id))

    return render_template("create_project.html", form=form)
コード例 #6
0
ファイル: web.py プロジェクト: ernsyn/ihatemoney
def remind_password():
    form = PasswordReminder()
    if request.method == "POST":
        if form.validate():
            # get the project
            project = Project.query.get(form.id.data)
            # send a link to reset the password
            current_app.mail.send(
                Message(
                    "password recovery",
                    body=render_localized_template("password_reminder",
                                                   project=project),
                    recipients=[project.contact_email],
                ))
            return redirect(url_for(".password_reminder_sent"))

    return render_template("password_reminder.html", form=form)