コード例 #1
0
def send_mail(sender, recipients, theme, body, html):
    message_to_send = Message(theme, sender=sender, recipients=[recipients])
    message_to_send.body = body
    message_to_send.html = html

    with app.app_context():
        mail.send(message_to_send)
コード例 #2
0
def forgot_password():
    """Show forgot password screen"""
    if request.method == "POST":

        email = request.form.get("email")
        confirmation_token = generate_confirmation_token(email)

        user = mongo.db.users.find_one({"email": email})

        if not user["confirmed_email"]:
            flash("Cannot Reset Password With Unverified Email Address")
            return render_template("forgot-password.html")

        if user is not None:

            resetLink = url_for("auth.reset_password",
                                token=confirmation_token,
                                _external=True)

            msg = Message(subject="Reset Your Password for Doughversity.",
                          html=f"""<a href='{resetLink}'>
                                    Click Here To Reset Your Password
                                </a>""",
                          sender="*****@*****.**",
                          recipients=[email])
            mail.send(msg)

        flash("Reset Password Email Sent")
        return render_template("forgot-password.html")

    else:
        return render_template("forgot-password.html")
コード例 #3
0
def send_email(to, subject, template):

    msg = Message(subject,
                  recipients=[to],
                  html=template,
                  sender=app.config['MAIL_DEFAULT_SENDER'])
    mail.send(msg)
コード例 #4
0
def contact():
    form = ContactForm()

    if request.method == 'POST' and form.validate_on_submit():
        name = request.form.get('user_name')
        email = request.form.get('user_email')
        message = request.form.get('message')

        msg_body = "%s %s <br><br> %s" % (name, email, message)
        msg = MailMessage(body=msg_body,
                          html=msg_body,
                          subject=u"İletişime geçmek isteyen var",
                          sender=(u"Eşya Kütüphanesi",
                                  "*****@*****.**"),
                          recipients=[
                              "*****@*****.**",
                              "*****@*****.**"
                          ])

        mail.send(msg)

        flash(u"E-postan gönderildi!")
        return redirect(url_for('contact'))

    return render_template("contact.html", form=form, user=current_user)
コード例 #5
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('features.index'))

    form = RegistrationForm()
    if form.validate_on_submit():

        msg = Message('Thanks for Registering!',
                      sender='*****@*****.**',
                      recipients=[str(form.email.data)])
        msg.body = "Hi there! Thanks for registering to Cat Wiki!\n\nYour username is: " + str(
            form.username.data
        ) + "\n\nThank you for using our website, we hope you have an excellent day!"
        mail.send(msg)
        session['new_username'] = form.username.data

        hashed = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")

        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed)
        user.save()
        return redirect(url_for('users.tfa'))

    return render_template('register.html', title='Register', form=form)
コード例 #6
0
ファイル: admin.py プロジェクト: EsyaKutuphanesi/things-demo
    def request_detail_view(self, id):
        unapproved_user = User.query.filter(User.approved == False,
                                            User.id == id).first()
        if not unapproved_user:
            flash(u"Kullanıcı zaten onaylı!")
            return redirect(url_for('.index_view'))

        msg_body = render_template('email/request_detail.txt',
                                   user=unapproved_user)
        html_msg = render_template('email/request_detail.html',
                                   user=unapproved_user)

        msg_subject = u"Ufak bir rica!"
        msg = MailMessage(body=msg_body,
                          html=html_msg,
                          subject=msg_subject,
                          sender=(u"Eşya Kütüphanesi",
                                  "*****@*****.**"),
                          recipients=[unapproved_user.email])

        mail.send(msg)
        flash(
            u"Kullanıcıya e-posta gönderilerek daha fazla bilgi vermesi talep edildi!"
        )
        return redirect(url_for('.index_view'))
コード例 #7
0
def account():
    username_form = UpdateUsernameForm()
    password_form = UpdatePasswordForm()
    profile_pic_form = UpdateProfilePicForm()

    if password_form.validate_on_submit():
        hashed = bcrypt.generate_password_hash(
            password_form.new_password.data).decode("utf-8")

        msg = Message('Password Change',
                      sender='*****@*****.**',
                      recipients=[str(temp.email)])
        msg.body = "Your password has been updated! Please reply to this e-mail if you did not request this change."
        mail.send(msg)

        current_user.modify(password=hashed)
        current_user.save()

        return redirect(url_for('users.account'))

    if username_form.validate_on_submit():
        temp = User.objects(username=current_user.username).first()
        current_user.username = username_form.username.data

        msg = Message('Username Change',
                      sender='*****@*****.**',
                      recipients=[str(temp.email)])
        msg.body = "Your username has been updated!\nYour new username is: " + str(
            username_form.username.data)
        mail.send(msg)

        current_user.modify(username=username_form.username.data)
        current_user.save()

        return redirect(url_for('users.account'))

    if profile_pic_form.validate_on_submit():
        img = profile_pic_form.propic.data
        filename = secure_filename(img.filename)

        if current_user.profile_pic.get() is None:
            current_user.profile_pic.put(img.stream, content_type='images/png')
        else:
            current_user.profile_pic.replace(img.stream,
                                             content_type='images/png')
        current_user.save()

        return redirect(url_for('users.account'))

    image = images(current_user.username)

    return render_template("account.html",
                           title="Account",
                           username_form=username_form,
                           password_form=password_form,
                           profile_pic_form=profile_pic_form,
                           image=image)
コード例 #8
0
def send_reset_email(user):
    token = user.get_reset_token()
    msg = Message('Password Reset Request',
                  sender='*****@*****.**',
                  recipients=[user.email])
    msg.body = f'''To Reset Your Password, visit the following link:
{url_for('reset_token', token=token, _external=True)}    
    
'''
    mail.send(msg)
コード例 #9
0
def send_reset_email(user):
    token = user.get_reset_token()
    print(token)
    msg = Message('Password Reset Request',
                  sender='*****@*****.**',
                  recipients=[user.email])
    msg.body = f'''To reset your password, visit the following link:
{url_for('reset_token', token=token, _external=True)}

If you did not make this request then simply ignore this email and no changes will be made.
'''
    mail.send(msg)
コード例 #10
0
def sendConfirmationEmail(email):
    confirmation_token = generate_confirmation_token(email)

    confirm_email_link = url_for("auth.confirm_email",
                                 token=confirmation_token,
                                 _external=True)

    msg = Message(subject="Confirm your email for Doughversity!",
                  html=f"""<a href='{confirm_email_link}'>
                                    Click Here To Authenticate Your Email!
                                </a>""",
                  sender="*****@*****.**",
                  recipients=[email])
    mail.send(msg)
コード例 #11
0
ファイル: views.py プロジェクト: driftbee/DBdev
def contact():
    form = ContactForm()

    if request.method == 'POST':
        msg = Message(form.subject.data, sender='*****@*****.**', recipients=['*****@*****.**'])
        msg.body = """
             From: %s <%s>
             %s
             """ % (form.name.data, form.email.data, form.message.data)
        mail.send(msg)
        return 'Form posted.'

    elif request.method == 'GET':
        return render_template('contact.html', form=form)
コード例 #12
0
def Mail():
    emai = request.form.get('email')
    auth_code = random.randint(11111, 99999)
    msg = Message(subject='hello',
                  recipients=['%s' % (emai)],
                  body="这是您的验证码:%s" % (auth_code))
    try:
        mail.send(msg)
        session["auth_code"] = auth_code
        session.permanent = True
        app.permanent_session_lifetime = timedelta(minutes=5)
        db.session.commit()
        return (jsonify({'static': 1}))
    except Exception as e:
        print(e)
        return (jsonify({'static': 0}))
コード例 #13
0
ファイル: admin.py プロジェクト: EsyaKutuphanesi/things-demo
    def request_detail_view(self, id):
        unapproved_user = User.query.filter(User.approved == False, User.id == id).first()
        if not unapproved_user:
            flash(u"Kullanıcı zaten onaylı!")
            return redirect(url_for('.index_view'))

        msg_body = render_template('email/request_detail.txt', user=unapproved_user)
        html_msg = render_template('email/request_detail.html', user=unapproved_user)

        msg_subject = u"Ufak bir rica!"
        msg = MailMessage(
            body=msg_body,
            html=html_msg,
            subject=msg_subject,
            sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
            recipients=[unapproved_user.email]
        )

        mail.send(msg)
        flash(u"Kullanıcıya e-posta gönderilerek daha fazla bilgi vermesi talep edildi!")
        return redirect(url_for('.index_view'))
コード例 #14
0
ファイル: views.py プロジェクト: espegj/rappsys
def recovery_password():
    email = request.form['email']
    pas = password_generator()
    enc_pas = hashlib.sha224(pas).hexdigest()
    user = db.session.query(User).filter(User.email == email).first()

    if user != None:
        user.recovery_password = enc_pas
        db.session.commit()
        msg = Message("Reset password",
                  sender="*****@*****.**",
                  recipients=[email])
        msg.body = "Bruk dette passordet faar aa opprette et nytt: " + pas
        try:
            mail.send(msg)
            return render_template('set_new_pass.html', email=email)
        except:
            return render_template("error.html", error=323, message="Det har oppstatt en feil ved utsending av mail..")
    else:
        db.session.close()
        flash("Brukeren eksisterer ikke")
        return render_template("recovery.html")
コード例 #15
0
ファイル: views.py プロジェクト: baa-archieve/esyakutuphanesi
def check_approved(source=None):
    if current_user.approved:
        return redirect(url_for('home'))
    else:
        if source == 'register':

            flash(u'Üyeliğin onay bekliyor. Onaylandığı zaman e-posta ile sana haber vereceğiz.')
            msg_body = "%s %s <br><br> %s" % (current_user.name, current_user.email, current_user.why)
            msg = MailMessage(
                body=msg_body,
                html=msg_body,
                subject=u"Yeni Üye",
                sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
                recipients=["*****@*****.**"]
            )

            mail.send(msg)

        elif source == 'login':
            flash(u'Üyeliğin onay bekliyor.')
        logout_user()
        return redirect(url_for('home'))
コード例 #16
0
ファイル: views.py プロジェクト: baa-archieve/esyakutuphanesi
def invite():
    form = InvitationForm()

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

        emails = request.form.get('emails')
        message = request.form.get('message')

        invite_info = Invitations(
            user_id=current_user.id,
            emails=emails,
            message=message
        )

        db.session.add(invite_info)
        db.session.commit()

        email_list = emails.split()

        for email in email_list:
            msg_body = '%s <br><br> %s <br><br> esyakutuphanesi.com'\
                       % (current_user.name, message)
            html_msg = '%s <br><br> %s <br><br> <a href="http://esyakutuphanesi.com/">esyakutuphanesi.com</a>' \
                       % (current_user.name, message)
            msg_subject = u"%s seni Eşya Kütüphanesi'ne davet ediyor!" % current_user.name
            msg = MailMessage(
                body=msg_body,
                html=html_msg,
                subject=msg_subject,
                sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
                recipients=[email]
            )

            mail.send(msg)

        flash(u"Davetini ilettik!")
        return redirect(url_for('invite'))

    return render_template("invite.html", form=form, user=current_user)
コード例 #17
0
ファイル: views.py プロジェクト: baa-archieve/esyakutuphanesi
def contact():
    form = ContactForm()

    if request.method == 'POST' and form.validate_on_submit():
        name = request.form.get('user_name')
        email = request.form.get('user_email')
        message = request.form.get('message')

        msg_body = "%s %s <br><br> %s" % (name, email, message)
        msg = MailMessage(
            body=msg_body,
            html=msg_body,
            subject=u"İletişime geçmek isteyen var",
            sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
            recipients=["*****@*****.**", "*****@*****.**"]
        )

        mail.send(msg)

        flash(u"E-postan gönderildi!")
        return redirect(url_for('contact'))

    return render_template("contact.html", form=form, user=current_user)
コード例 #18
0
ファイル: admin.py プロジェクト: EsyaKutuphanesi/things-demo
    def approval_view(self, id):
        unapproved_user = User.query.filter(User.approved == False, User.id == id).first()
        if not unapproved_user:
            flash(u"Kullanıcı zaten onaylı!")
            return redirect(url_for('.index_view'))

        unapproved_user.approved = True
        db.session.commit()

        msg_body = render_template('email/welcome.txt', user=unapproved_user)
        html_msg = render_template('email/welcome.html', user=unapproved_user)

        msg_subject = u"Hoşgeldin!"
        msg = MailMessage(
            body=msg_body,
            html=html_msg,
            subject=msg_subject,
            sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
            recipients=[unapproved_user.email]
        )

        mail.send(msg)
        flash(u"Kullanıcı onaylandı ve e-posta gönderildi!")
        return redirect(url_for('.index_view'))
コード例 #19
0
ファイル: admin.py プロジェクト: EsyaKutuphanesi/things-demo
    def approval_view(self, id):
        unapproved_user = User.query.filter(User.approved == False,
                                            User.id == id).first()
        if not unapproved_user:
            flash(u"Kullanıcı zaten onaylı!")
            return redirect(url_for('.index_view'))

        unapproved_user.approved = True
        db.session.commit()

        msg_body = render_template('email/welcome.txt', user=unapproved_user)
        html_msg = render_template('email/welcome.html', user=unapproved_user)

        msg_subject = u"Hoşgeldin!"
        msg = MailMessage(body=msg_body,
                          html=html_msg,
                          subject=msg_subject,
                          sender=(u"Eşya Kütüphanesi",
                                  "*****@*****.**"),
                          recipients=[unapproved_user.email])

        mail.send(msg)
        flash(u"Kullanıcı onaylandı ve e-posta gönderildi!")
        return redirect(url_for('.index_view'))
コード例 #20
0
ファイル: views.py プロジェクト: baa-archieve/esyakutuphanesi
def moderation():
    action = request.args.get("action")
    id = request.args.get("id")

    user_action = request.args.get("user_action")
    user_id = request.args.get("user_id")

    new_user = User.query.filter(User.id > 0).order_by(User.id.desc()).limit(40)

    if action == 'approve' and id > 0:
        if 'admin' in current_user.roles:
            stuff = Stuff.query.filter(Stuff.approved == 0,
                                       Stuff.id == id). \
                order_by(Stuff.id.desc()).first()
        else:
            stuff = Stuff.query.join(Group).join(GroupMembership) \
                .filter(GroupMembership.user_id == current_user.id,
                        GroupMembership.is_moderator,
                        Stuff.id == id,
                        Stuff.approved == 0). \
                order_by(Stuff.id.desc()).first()
        if stuff:
            stuff.approved = 1
            db.session.commit()

            msg_body = render_template('email/approved.txt', user=stuff.owner, stuff=stuff)

            html_msg = render_template('email/approved.html', user=stuff.owner, stuff=stuff)

            msg_subject = u"Eşyan artık sitede!"

            msg = MailMessage(
                body=msg_body,
                html=html_msg,
                subject=msg_subject,
                sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
                recipients=[stuff.owner.email]
            )

            mail.send(msg)

            flash(u"Eşya onaylandı ve e-posta gönderildi!")

    if user_action == 'approve_user' and user_id > 0:
        unapproved_user = User.query.filter(User.approved == False, User.id == user_id). \
            order_by(User.id.desc()).first()

        if unapproved_user:
            unapproved_user.approved = True
            db.session.commit()

            msg_body = render_template('email/welcome.txt', user=unapproved_user)
            html_msg = render_template('email/welcome.html', user=unapproved_user)

            msg_subject = u"Hoşgeldin!"
            msg = MailMessage(
                body=msg_body,
                html=html_msg,
                subject=msg_subject,
                sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
                recipients=[unapproved_user.email]
            )

            mail.send(msg)

            flash(u"Kullanıcı onaylandı ve e-posta gönderildi!")

    if 'admin' in current_user.roles:
        last_objects = Stuff.query.filter(Stuff.id > 0).\
            order_by(Stuff.id.desc()).limit(40)

    else:
        last_objects = Stuff.query.join(Group).join(GroupMembership)\
            .filter(GroupMembership.user_id == current_user.id,
                    GroupMembership.is_moderator).order_by(Stuff.id.desc()).limit(40)

    return render_template(
        "moderation.html",
        user=current_user,
        new_user=new_user,
        last_objects=last_objects
    )
コード例 #21
0
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)
コード例 #22
0
ファイル: emails.py プロジェクト: kshitijjain91/workplate
def send_email(subject, sender, recipients, text_body, html_body):
    msg = Message(subject, sender=sender, recipients=recipients)
    msg.body = text_body
    msg.html = html_body
    mail.send(msg)
コード例 #23
0
ファイル: views.py プロジェクト: baa-archieve/esyakutuphanesi
def make_request(stuff_id=None):
    form = RequestForm()
    message = None
    return_url = request.form['return_url']
    if form.validate_on_submit():
        message = form.message.data
        stuff_id = form.stuff_id.data
        duration = int(form.duration.data)
        unit = int(form.unit.data)

        address = Address.query.filter(Address.user_id == current_user.id).first()

        if address:
            if stuff_id is None or not (stuff_id > ''):
                flash(u'İstek gönderilemedi.')
                return redirect(return_url)
            stuff = Stuff.query.filter(Stuff.id == stuff_id).first()

            if stuff.is_wanted == True:
                user = stuff.owner
                from_user = current_user
            else:
                user = current_user
                from_user = stuff.owner

            new_request = Request(
                stuff_id=stuff_id,
                user_id=user.id,
                from_user_id=from_user.id,
                duration=(duration * unit)
            )

            db.session.add(new_request)
            new_conversation = Conversation(
                title='%s' % stuff.title,
                users=[current_user, stuff.owner],
                request=new_request
            )

            db.session.add(new_conversation)

            new_message = Message(
                from_user=current_user,
                to_user=stuff.owner,
                conversation=new_conversation,
                txt=message
            )

            db.session.add(new_message)

            db.session.commit()

            msg_body = render_template('email/request.txt', to_user=user, from_user=from_user,
                                       stuff=stuff, conversation_url=new_conversation.url)

            html_msg = render_template('email/request.html', to_user=user, from_user=from_user,
                                       stuff=stuff, conversation_url=new_conversation.url)
            if stuff.is_wanted:
                msg_subject = u"%s sana %s ödünç vermek istiyor" % (from_user.name, stuff.title)

            else:
                msg_subject = u"%s için bir talip var!" % stuff.title

            msg = MailMessage(
                body=msg_body,
                html=html_msg,
                subject=msg_subject,
                sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
                recipients=[stuff.owner.email]
            )

            mail.send(msg)

            return redirect(url_for('my_messages'))

        else:
            flash(u'Ödünç istemek için adres girmelisin.')
            return redirect(url_for('new_address'))
    else:
        flash(u'İstek gönderilemedi. Kaç gün için ödünç istediğini girmelisin.')
        return redirect(return_url)
コード例 #24
0
ファイル: views.py プロジェクト: baa-archieve/esyakutuphanesi
def edit_stuff(stuff_id=None):
    stuff = Stuff.query.filter(Stuff.id == stuff_id).first()
    form = EditStuffForm()
    is_new = True
    is_wanted = bool(request.args.get('is_wanted'))
    # if is_wanted == 'true':
    #     form.is_wanted.data = 'True'

    address_choices = []
    if current_user.addresses:
        address_choices = [(address.id, address.detail)
                           for address in current_user.addresses]
    address_choices += [(-1, u'Yeni adres: Haritadan sağ tıklayarak seçebilirsiniz.')]
    #else:
    #    flash('Adres girmeniz gerekiyor')
    #    return redirect(url_for("new_address",
    #                            next=request.script_root+request.path))

    form.address.choices = address_choices

    if current_user.groups:
        group_choices = [(membership.group.id, membership.group.name)
                         for membership in current_user.groups]
        group_choices = [(-1, u'Herkese açık')] + group_choices
    else:
        group_choices = [(-1, u'Herkese açık')]

    form.group.choices = group_choices

    categories = Category.query.order_by(Category.name)
    category_choices = [(category.id, category.name)
                        for category in categories]
    form.category.choices = category_choices
    if stuff:
        category = Category.query. \
            filter(Category.id == stuff.category_id).first()
    else:
        category = categories[0]
    stuff_types = category.type_list
    stuff_type_choices = [(stuff_type.id, stuff_type.name)
                          for stuff_type in stuff_types]
    form.stuff_type.choices = stuff_type_choices

    if request.args.get('status'):
        status = int(request.args.get('status'))

        if status:
            Stuff.query.filter(Stuff.id == stuff_id).\
                update({Stuff.approved: status})
            db.session.commit()
            flash(u"Eşya kaldırıldı.")
            return redirect(url_for("my_stuff"))

    if request.method == 'POST':
        category = Category.query.\
            filter(Category.id == form.category.data).first()

        stuff_types = category.type_list
        stuff_type_choices = [(stuff_type.id, stuff_type.name)
                              for stuff_type in stuff_types]
        form.stuff_type.choices = stuff_type_choices

        if form.validate_on_submit():
            if form.address.data == -1:
                address = Address(
                    user=current_user,
                    lat=request.form.get('lat'),
                    lng=request.form.get('lng'),
                    detail=unicode(request.form.get('address_str')),
                    name="addr"
                )
                db.session.add(address)
            else:
                address = Address.query.\
                    filter(Address.id == form.address.data).\
                    first()

            if stuff:
                stuff.title = form.title.data
                stuff.detail = form.detail.data
                stuff.stuff_address = address
                stuff.category_id = form.category.data
                stuff.type_id = form.stuff_type.data
                #stuff.is_wanted = form.is_wanted.data == 'True'
                flash(u"Eşya güncellendi.")

            else:
                group_id = None if form.group.data == -1 else form.group.data
                stuff = Stuff(
                    title=form.title.data,
                    detail=form.detail.data,
                    stuff_address=address,
                    owner=current_user,
                    category_id=form.category.data,
                    type_id=form.stuff_type.data,
                    group_id=group_id,
                    is_wanted=form.is_wanted.data == 'True'
                )
                db.session.add(stuff)
                db.session.commit()

                photo_file = form.photo.data

                stuff_id = str(stuff.id)

                if photo_file:
                    file_ext = get_file_extension(photo_file.filename)
                    generated_name = str(uuid.uuid1()) + '.' + file_ext

                    folder_path = app.config['UPLOADS_FOLDER'] + '/stuff/' + stuff_id + '/'

                    new_folder = os.path.dirname(folder_path)
                    if not os.path.exists(new_folder):
                        os.makedirs(new_folder)

                    filepath = os.path.join(folder_path, generated_name)
                    photo_file.save(filepath)

                    file_new_name = 'stuff/' + stuff_id + '/' + generated_name

                # else:
                #     generated_name = str(form.category.data)+'.jpg'
                #     file_new_name = generated_name

                    new_photo = StuffPhoto(
                        owner=current_user,
                        filename=file_new_name,
                        stuff=stuff
                    )
                    db.session.add(new_photo)
                    db.session.commit()

                flash(u"Eşya kaydedildi.")

                msg_body = u"Eşya ekleyen: %s %s <br><br>Eşya başlık: %s<br> Eşya detay : %s" \
                           % (current_user.name, current_user.email, stuff.title, stuff.detail)
                msg = MailMessage(
                    body=msg_body,
                    html=msg_body,
                    subject=u"Yeni Eşya",
                    sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
                    recipients=["*****@*****.**"]
                )

                mail.send(msg)

            tags = form.tags.data.split(',')
            for t in tags:
                if t > '':
                    new_tag = Tag(stuff=stuff, name=t)
                    db.session.add(new_tag)

            db.session.commit()

            if stuff_id is None:
                return redirect(url_for('edit_stuff', stuff_id=stuff.id))

    if stuff:
        is_new = False

        if stuff.group_id > 0:
            group_choices = [(stuff.group_id, stuff.group.name)]
        else:
            group_choices = [(-1, u'Herkese açık')]

        form.group.choices = group_choices
        form.fill_form(stuff)

    return render_template(
        "edit_stuff.html",
        user=current_user,
        is_wanted=is_wanted,
        form=form,
        action='Edit',
        stuff=stuff,
        is_new=is_new
    )
コード例 #25
0
ファイル: views.py プロジェクト: baa-archieve/esyakutuphanesi
def show_conversation(conversation_id):
    conversation = Conversation.query.\
        filter(Conversation.id == conversation_id).first()

    if current_user not in conversation.users:
        redirect('/my_messages')

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

        if current_user.id == conversation.request.user.id:
            to_user = conversation.request.from_user
        else:
            to_user = conversation.request.user

        print to_user.id
        new_message = Message(
            from_user=current_user,
            to_user=to_user,
            conversation=conversation,
            txt=form.message.data
        )
        db.session.add(new_message)
        db.session.commit()

        msg_body = render_template('email/conversation.txt', user=to_user, from_user=current_user.name,
                                   stuff_title=conversation.title, conversation=new_message)

        html_msg = render_template('email/conversation.html', user=to_user, from_user=current_user.name,
                                   stuff_title=conversation.title, conversation=new_message)

        # msg_body = u'%s sana mesaj gönderdi. <br><br> esyakutuphanesi.com'\
        #            % current_user.name
        # html_msg = u'%s sana mesaj gönderdi. <br><br> Mesajı okumak için' \
        #            u' <a href="http://esyakutuphanesi.com/conversation/{{conversation_id}}">tıkla!</a>' \
        #            % current_user.name

        msg_subject = u"Mesajın var"

        msg = MailMessage(
            body=msg_body,
            html=html_msg,
            subject=msg_subject,
            sender=(u"Eşya Kütüphanesi", "*****@*****.**"),
            recipients=[to_user.email]
        )

        mail.send(msg)

    Message.query.filter(
        Message.conversation_id == conversation_id,
        Message.status == 0,
        Message.to_user == current_user
    ).update({Message.status: 1})
    db.session.commit()

    form.message.data = None

    review_form = ReviewForm()

    if request.args.get('status'):
        status = int(request.args.get('status'))
    else:
        status = 0
    if status > 0 and \
            (conversation.request.stuff.owner == current_user or conversation.request.from_user_id == current_user.id):
        if conversation.request.stuff.status == 1:
            if status == 1 and conversation.request.status == 0:
                flash(u'Eşyayı vermeyi kabul ettiniz.')
                conversation.request.stuff.status = 0
                conversation.request.status = 1
                conversation.request.given_at = datetime.utcnow()
                db.session.commit()
        elif status == 2 and conversation.request.status == 1:
            flash(u'Eşyayı geri aldınız.')
            conversation.request.stuff.status = 1
            conversation.request.status = 2
            conversation.request.returned_at = datetime.utcnow()
            db.session.commit()
        else:
            flash(u'Eşya zaten başkasına verilmiş.')

    wanted_stuff = StuffPhoto.query.filter(StuffPhoto.stuff_id == conversation.request.stuff_id).first()
    review_form.request_id.data = conversation.request_id
    return render_template(
        "conversation.html",
        user=current_user,
        wanted_stuff=wanted_stuff,
        form=form,
        action='Edit',
        conversation=conversation,
        review_form=review_form
    )
コード例 #26
0
ファイル: e_mail.py プロジェクト: dkirel/fresh_lane
def send_async_email(app, msg):
    with app.app_context():
        mail.send(msg)
コード例 #27
0
ファイル: 1.py プロジェクト: Red82/Blog-by-Flask
from flask.ext.mail import Message
from __init__ import app, mail
from config import ADMINS
msg = Message('test subject', sender = ADMINS[0], recipients = ADMINS)
msg.body = 'text body'
msg.html = '<b>HTML</b> body'
with app.app_context():
    mail.send(msg)
コード例 #28
0
ファイル: routes.py プロジェクト: jessqin/Cats
def cat_detail(cat_name):
    client = CatClient()
    attributes_to_keep = [
        'affection_level', 'child_friendly', 'dog_friendly', 'energy_level',
        'grooming', 'hypoalergenic'
    ]

    image_result, breed_result = client.retrieve_cat_by_id(cat_name)
    ratings = dict()
    for key in breed_result[0].keys():
        value = str(breed_result[0][key])
        if value.isdigit() and key in attributes_to_keep:
            new_key = key.replace('_', ' ').capitalize()
            ratings[new_key] = (range(int(value)), range(5 - int(value)))

    #if type(image_result) == dict:
    #    return render_template('movie_detail.html', error_msg=result['Error'])

    if len(image_result) == 0 or len(breed_result) == 0:
        return render_template('cat_detail.html', error_msg="error")

    picform = ProposePicForm()
    if picform.validate_on_submit():
        temp = User.objects(username=current_user.username).first()
        msg = Message('Upload Request',
                      sender='*****@*****.**',
                      recipients=[str(temp.email)])
        msg.body = "Thanks for requesting to upload an image to breed:" + str(
            cat_name) + "!\nYour image is attached to this email"
        msg.attach(picform.new_pic.data.filename, 'images/png',
                   picform.new_pic.data.read())
        mail.send(msg)

        msg = Message('Upload Request',
                      sender='*****@*****.**',
                      recipients=['*****@*****.**'])
        msg.body = "Someone is requesting to upload image to breed: " + str(
            cat_name)
        msg.attach(picform.new_pic.data.filename, 'images/png',
                   picform.new_pic.data.read())
        mail.send(msg)

        img = picform.new_pic.data
        filename = secure_filename(img.filename)

        pim = CatImage(
            commenter=load_user(current_user.username),
            date=current_time(),
            im=None,
            cat_name=cat_name,
        )
        pim.save()
        pim.im.put(img.stream, content_type='images/png')
        pim.save()

        return redirect(url_for('features.cat_detail', cat_name=cat_name))

    form = CatReviewForm()
    if form.validate_on_submit():
        review = Review(
            commenter=load_user(current_user.username),
            content=form.text.data,
            date=current_time(),
            cat_name=cat_name,
        )

        review.save()
        return redirect(request.path)

    reviews_m = Review.objects(cat_name=cat_name)
    reviews = []
    for r in reviews_m:
        reviews.append({
            'date': r.date,
            'username': r.commenter.username,
            'content': r.content,
            'image': images(r.commenter.username)
        })

    return render_template('cat_detail.html',
                           form=form,
                           image=image_result[0],
                           cat=breed_result[0],
                           ratings=ratings,
                           reviews=reviews,
                           picform=picform)
コード例 #29
0
ファイル: emails.py プロジェクト: Red82/Blog-by-Flask
def send_async_email(msg):
    mail.send(msg)
コード例 #30
0
ファイル: views.py プロジェクト: qinms/BlogApp
def send_mail(to,subject,template,**kwargs):
    msg = Message(subject,sender=MAIL_SENDER,recipients=[to])
    msg.html = render_template(template,**kwargs)
    mail.send(msg)